@Override public String getDescriptivePortName() { return this.serialPort.getDescriptivePortName(); }
@Override public String getDescriptivePortName() { return serialPort == null ? "" : serialPort.getDescriptivePortName(); }
@Override public String getDescriptivePortName() { return serialPort == null ? "" : serialPort.getDescriptivePortName(); }
@Override public String getDescriptivePortName() { return this.serialPort.getDescriptivePortName(); }
@Override public void disconnect() { try { if (_serialPort.closePort()) { _logger.debug("_serialPort{} closed", _serialPort.getDescriptivePortName()); } else { _logger.warn("Failed to close _serialPort{}", _serialPort.getDescriptivePortName()); } _config.setStatus(STATE.DOWN, "Stopped."); } catch (Exception ex) { _config.setStatus(STATE.DOWN, "ERROR:" + ex.getMessage()); } }
@Override public void disconnect() { try { if (_serialPort.closePort()) { _logger.debug("_serialPort{} closed", _serialPort.getDescriptivePortName()); } else { _logger.warn("Failed to close _serialPort{}", _serialPort.getDescriptivePortName()); } _config.setStatus(STATE.DOWN, "Stopped."); } catch (Exception ex) { _config.setStatus(STATE.DOWN, "ERROR:" + ex.getMessage()); } }
if (serialPort == null) { serialPort = SerialPort.getCommPort(parameters.getPortName()); if (serialPort.getDescriptivePortName().contains("Bad Port")) { serialPort = null; throw new IOException(String.format("Port %s is not a valid name for a port on this platform", parameters.getPortName()));
if (serialPort == null) { serialPort = SerialPort.getCommPort(parameters.getPortName()); if (serialPort.getDescriptivePortName().contains("Bad Port")) { serialPort = null; throw new IOException(String.format("Port %s is not a valid name for a port on this platform", parameters.getPortName()));
@Override public void connect() { SerialPort[] serialPorts = SerialPort.getCommPorts(); _logger.debug("Number of serial port available:{}", serialPorts.length); for (int portNo = 0; portNo < serialPorts.length; portNo++) { _logger.debug("SerialPort[{}]:[{},{}]", portNo + 1, serialPorts[portNo].getSystemPortName(), serialPorts[portNo].getDescriptivePortName()); } // create an instance of the serial communications class _serialPort = SerialPort.getCommPort(_config.getPortName()); _serialPort.openPort();//Open port if (!_serialPort.isOpen()) { _logger.error("Unable to open serial port:[{}]", _config.getPortName()); _config.setStatus(STATE.DOWN, "ERROR: Unable to open!"); return; } _serialPort.setComPortParameters( _config.getBaudRate(), 8, // data bits SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY); // create and register the serial data listener _serialPort.addDataListener(new SerialDataListenerjSerialComm(_serialPort, _config, _parser, _queue)); _logger.debug("Serial port initialized with {}", _config); _config.setStatus(STATE.UP, "Connected Successfully"); }
@Override public void connect() { SerialPort[] serialPorts = SerialPort.getCommPorts(); _logger.debug("Number of serial port available:{}", serialPorts.length); for (int portNo = 0; portNo < serialPorts.length; portNo++) { _logger.debug("SerialPort[{}]:[{},{}]", portNo + 1, serialPorts[portNo].getSystemPortName(), serialPorts[portNo].getDescriptivePortName()); } // create an instance of the serial communications class _serialPort = SerialPort.getCommPort(_config.getPortName()); _serialPort.openPort();//Open port if (!_serialPort.isOpen()) { _logger.error("Unable to open serial port:[{}]", _config.getPortName()); _config.setStatus(STATE.DOWN, "ERROR: Unable to open!"); return; } _serialPort.setComPortParameters( _config.getBaudRate(), 8, // data bits SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY); // create and register the serial data listener _serialPort.addDataListener(new SerialDataListenerjSerialComm(_serialPort, _config, _parser, _queue)); _logger.debug("Serial port initialized with {}", _config); _config.setStatus(STATE.UP, "Connected Successfully"); }