Package gnu.io

Examples of gnu.io.CommPortIdentifier


  public RFXComSerialConnector() {
  }

  @Override
  public void connect(String device) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException {
    CommPortIdentifier portIdentifier = CommPortIdentifier
        .getPortIdentifier(device);

    CommPort commPort = portIdentifier
        .open(this.getClass().getName(), 2000);

    serialPort = (SerialPort) commPort;
    serialPort.setSerialPortParams(38400, SerialPort.DATABITS_8,
        SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
View Full Code Here


    @SuppressWarnings("rawtypes")
    public void initialize() throws InitializationException {
      // parse ports and if the default port is found, initialized the reader
      Enumeration portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
        CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
        if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
          if (id.getName().equals(port)) {
            logger.debug("Serial port '{}' has been found.", port);
            portId = id;
          }
        }
      }
      if (portId != null) {
        // initialize serial port
        try {
          serialPort = (SerialPort) portId.open("openHAB", 2000);
        } catch (PortInUseException e) {
          throw new InitializationException(e);
        }

        try {
          inputStream = serialPort.getInputStream();
        } catch (IOException e) {
          throw new InitializationException(e);
        }

        try {
          serialPort.addEventListener(this);
        } catch (TooManyListenersException e) {
          throw new InitializationException(e);
        }

        // activate the DATA_AVAILABLE notifier
        serialPort.notifyOnDataAvailable(true);

        try {
          // set port parameters
          serialPort.setSerialPortParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
              SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {
          throw new InitializationException(e);
        }

        try {
          // get the output stream
          outputStream = serialPort.getOutputStream();
        } catch (IOException e) {
          throw new InitializationException(e);
        }
      } else {
        StringBuilder sb = new StringBuilder();
        portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements()) {
          CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
          if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            sb.append(id.getName() + "\n");
          }
        }
        throw new InitializationException("Serial port '" + port + "' could not be found. Available ports are:\n" + sb.toString());
      }
    }
View Full Code Here

        } catch (RuntimeException e) {
            if (e.getCause() instanceof NoSuchPortException) {
                StringBuilder sb = new StringBuilder("Available ports are:\n");
                Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
                while (portList.hasMoreElements()) {
                    CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
                    if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                        sb.append(id.getName() + "\n");
                    }
                }
                sb.deleteCharAt(sb.length() - 1);
                throw new ConfigurationException(CONFIG_KEY_SERIAL_PORT, "Serial port '" + serialPort + "' could not be opened. "
                        + sb.toString());
View Full Code Here

        /* by default, RXTX searches only devices /dev/ttyS* and
         * /dev/ttyUSB*, and will so not find symlinks. The
         *  setProperty() call below helps
         */
        System.setProperty("gnu.io.rxtx.SerialPorts", m_serialDeviceName);
        CommPortIdentifier ci =  CommPortIdentifier.getPortIdentifier(m_serialDeviceName);
        CommPort cp = ci.open("openhabalarmdecoder", 10000);
        if (cp == null) {
          throw new IllegalStateException("cannot open serial port!");
        }
        if (cp instanceof SerialPort) {
          m_port = (SerialPort)cp;
View Full Code Here

    @SuppressWarnings("rawtypes")
    public void initialize() throws InitializationException {
      // parse ports and if the default port is found, initialized the reader
      Enumeration portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
        CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
        if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
          if (id.getName().equals(port)) {
            logger.debug("Serial port '{}' has been found.", port);
            portId = id;
          }
        }
      }
      if (portId != null) {
        // initialize serial port
        try {
          serialPort = (SerialPort) portId.open("openHAB", 2000);
        } catch (PortInUseException e) {
          throw new InitializationException(e);
        }

        try {
          inputStream = serialPort.getInputStream();
        } catch (IOException e) {
          throw new InitializationException(e);
        }

        try {
          serialPort.addEventListener(this);
        } catch (TooManyListenersException e) {
          throw new InitializationException(e);
        }

        // activate the DATA_AVAILABLE notifier
        serialPort.notifyOnDataAvailable(true);

        try {
          // set port parameters
          serialPort.setSerialPortParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
              SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {
          throw new InitializationException(e);
        }

        try {
          // get the output stream
          outputStream = serialPort.getOutputStream();
        } catch (IOException e) {
          throw new InitializationException(e);
        }
      } else {
        StringBuilder sb = new StringBuilder();
        portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements()) {
          CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
          if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            sb.append(id.getName() + "\n");
          }
        }
        throw new InitializationException("Serial port '" + port + "' could not be found. Available ports are:\n" + sb.toString());
      }
    }
View Full Code Here

      }
    }
  } 
 
  public void openPort(String portName) throws InitializationException {
    CommPortIdentifier portIdentifier;

    port = portName;
    try {
      portIdentifier = CommPortIdentifier.getPortIdentifier(port);

      try {
        serialPort = (SerialPort) portIdentifier.open("openhab", 3000);
        serialPort.setSerialPortParams(19200, SerialPort.DATABITS_8,SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

        inputStream = new DataInputStream(new BufferedInputStream(serialPort.getInputStream()));
        outputStream = serialPort.getOutputStream();

      } catch (PortInUseException e) {
        throw new InitializationException(e);
      } catch (UnsupportedCommOperationException e) {
        throw new InitializationException(e);
      } catch (IOException e) {
        throw new InitializationException(e);
      }

    } catch (NoSuchPortException e) {
      StringBuilder sb = new StringBuilder();
      Enumeration portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
        CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
        if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
          sb.append(id.getName() + "\n");
        }
      }

      throw new InitializationException("Serial port '" + port
          + "' could not be found. Available ports are:\n"
View Full Code Here

  @Override
  public void connect() throws SwegonVentilationException {

    try {
      CommPortIdentifier portIdentifier = CommPortIdentifier
          .getPortIdentifier(portName);
      CommPort commPort = portIdentifier.open(this.getClass().getName(),
          2000);
      serialPort = (SerialPort) commPort;
      serialPort.setSerialPortParams(BAUDRATE, SerialPort.DATABITS_8,
          SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
View Full Code Here

      /* by default, RXTX searches only devices /dev/ttyS* and
       * /dev/ttyUSB*, and will so not find symlinks. The
       *  setProperty() call below helps
       */
      System.setProperty("gnu.io.rxtx.SerialPorts", m_devName);
      CommPortIdentifier ci =
          CommPortIdentifier.getPortIdentifier(m_devName);
      CommPort cp = ci.open(m_appName, 1000);
      if (cp instanceof SerialPort) {
        m_port = (SerialPort)cp;
      } else {
        throw new IllegalStateException("unknown port type");
      }
View Full Code Here

    System.setProperty("gnu.io.rxtx.SerialPorts", iname);
    try {
      Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
       
        CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
        if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
          //System.out.println("found " + portId.getName());
          if (portId.getName().equals(iname)) {
            port = (SerialPort)portId.open("serial madness", 2000);
            input = port.getInputStream();
            output = port.getOutputStream();
            port.setSerialPortParams(rate, databits, stopbits, parity);
            port.addEventListener(this);
            port.notifyOnDataAvailable(true);
View Full Code Here

    try {
      //System.err.println("trying");
      Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
      //System.err.println("got port list");
      while (portList.hasMoreElements()) {
        CommPortIdentifier portId =
          (CommPortIdentifier) portList.nextElement();
        //System.out.println(portId);

        if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
          String name = portId.getName();
          list.addElement(name);
        }
      }

    } catch (UnsatisfiedLinkError e) {
View Full Code Here

TOP

Related Classes of gnu.io.CommPortIdentifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.