Package gnu.io

Examples of gnu.io.CommPortIdentifier


   */
  public void open(String portName) throws InitializationException {
    logger.debug("Open ComfoAir connection");

    port = portName;
    CommPortIdentifier portIdentifier;

    try {
      portIdentifier = CommPortIdentifier.getPortIdentifier(port);

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

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

        ComfoAirCommand command = ComfoAirCommandType.getChangeCommand(
            ComfoAirCommandType.ACTIVATE.key, new DecimalType(1));
        sendCommand(command);
      } 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


  @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 connect(final String serialPortName)
      throws SerialInterfaceException {
    logger.info("Connecting to serial port {}", serialPortName);
    try {
      CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
      CommPort commPort = portIdentifier.open("org.openhab.binding.zwave",2000);
      this.serialPort = (SerialPort) commPort;
      this.serialPort.setSerialPortParams(115200,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
      this.serialPort.enableReceiveThreshold(1);
      this.serialPort.enableReceiveTimeout(ZWAVE_RECEIVE_TIMEOUT);
      this.receiveThread = new ZWaveReceiveThread();
View Full Code Here

  private void openCommPort(String portName) throws Exception {

    if (log.isDebugEnabled()) {
      Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
      while (portIdentifiers.hasMoreElements()) {
        CommPortIdentifier id = (CommPortIdentifier) portIdentifiers.nextElement();
        log.debug("Found port: {} x {}", id.getName(), id.getCurrentOwner());
      }
    }

    CommPortIdentifier portIdentifier = null;

    try {
      portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    } catch (NoSuchPortException e) {
      log.debug("Port not found during first attempt : {}", e.getMessage());
    }

    if (portIdentifier == null) {
      try {
        System.setProperty(SERIAL_PORT_PROPERTY_NAME, portName);
        portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
      } catch (Exception e) {
        log.debug("Port not found during second attempt : {}", e.getMessage());
        System.clearProperty(SERIAL_PORT_PROPERTY_NAME);
      }
    }

    if (portIdentifier == null) {
      throw new Exception("Serial port '" + portName + "' not found.");
    }
    if (portIdentifier.isCurrentlyOwned()) {
      throw new Exception("Serial port '" + portName + "' is in use.");
    }

    // open port
    port = (SerialPort) portIdentifier.open(this.getClass().getSimpleName(), CONNECT_TIMEOUT);
    log.info("Connected to serial port '{}'", portIdentifier.getName());

    // configure
    port.setSerialPortParams(9600, SerialPort.DATABITS_8,SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    port.notifyOnDataAvailable(true);
    port.addEventListener(this);
View Full Code Here

   **/
  public void open() {

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

  @Override
  public void connect() throws OpenEnergyMonitorException {

    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

    } catch(KNXException knxe) {
      if(knxe.getMessage().startsWith("can not open serial port")) {
        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);
        knxe = new KNXException("Serial port '" + serialPort + "' could not be opened. " + sb.toString());
      }
View Full Code Here

   * @throws IOException
   *             if any kind of error occurs opening the serial port.
   */
  public void open() throws IOException {

    CommPortIdentifier portIdentifier;
    try {
      portIdentifier = CommPortIdentifier
          .getPortIdentifier(serialPortName);
    } catch (NoSuchPortException e) {
      throw new IOException("Serial port with given name does not exist",
          e);
    }

    if (portIdentifier.isCurrentlyOwned()) {
      throw new IOException("Serial port is currently in use.");
    }

    // fixed issue as rxtx library originally used in j62056 does use
    // different version of rxtx
    // com port in their version is using gnu.io.CommPort
    RXTXPort commPort;
    try {
      commPort = portIdentifier.open(this.getClass().getName(), 2000);
    } catch (PortInUseException e) {
      throw new IOException("Serial port is currently in use.", e);
    }

    if (!(commPort instanceof SerialPort)) {
View Full Code Here

    logger.debug("Goint to open Serial connection on port '{}'", portName);
   
    // 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(portName)) {
          logger.debug("Serial port '{}' has been found.", portName);
          portId = id;
        }
      }
    }
   
    if (portId != null) {
      // initialize serial port
      try {
        serialPort = (SerialPort) portId.open("openHAB", 2000);
       
        inputStream = serialPort.getInputStream();
        outputStream = serialPort.getOutputStream();
       
        bReader = new BufferedReader(new InputStreamReader(inputStream));
        bWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
       
        serialPort.addEventListener(this);
        serialPort.notifyOnDataAvailable(true);
        serialPort.setSerialPortParams(BAUD, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

      } catch (IOException e) {
        throw new EHealthException(e);
      } catch (PortInUseException e) {
        throw new EHealthException(e);
      } catch (UnsupportedCommOperationException e) {
        throw new EHealthException(e);
      } catch (TooManyListenersException e) {
        throw new EHealthException(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 EHealthException("Serial port '" + portName + "' could not be found. Available ports are:\n" + sb.toString());
    }
  }
View Full Code Here

   */
  public void connect() throws EpsonProjectorException {

    try {
      logger.debug("Open connection to serial port '{}'", serialPortName);
      CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);

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

      serialPort = (SerialPort) commPort;
      serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
          SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
      serialPort.enableReceiveThreshold(1);
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.