@Override public boolean openPort() throws Exception { responseMessageHandler = new ResponseMessageHandler(); if (serialPort == null) { throw new ConnectionException("The connection wasn't initialized"); } return serialPort.openPort(); }
/** * Opens this serial port for reading and writing. * <p> * This method is equivalent to calling {@link #openPort} with a value of 1000. * <p> * All serial port parameters or timeouts can be changed at any time before or after the port has been opened. * <p> * Note that calling this method on an already opened port will simply reconfigure the port parameters. * * @return Whether the port was successfully opened. */ public final boolean openPort() { return openPort(1000); }
private void openPort() { this.serialPort.openPort(); } }
/** * Opens this serial port for reading and writing with an optional delay time. * <p> * All serial port parameters or timeouts can be changed at any time before or after the port has been opened. * <p> * Note that calling this method on an already opened port will simply reconfigure the port parameters. * * @param safetySleepTime The number of milliseconds to sleep before opening the port in case of frequent closing/openings. * @return Whether the port was successfully opened. */ public final boolean openPort(int safetySleepTime) { return openPort(safetySleepTime, sendDeviceQueueSize, receiveDeviceQueueSize); }
private void openPort() { this.serialPort.openPort(); } }
public Serial(SerialPort port) throws IOException { port.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, TIME_OUT, TIME_OUT); port.setComPortParameters(DATA_RATE, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY); port.setFlowControl(SerialPort.FLOW_CONTROL_DISABLED); if (port.openPort()) { this.port = port; output = port.getOutputStream(); input = port.getInputStream(); } else { throw new IOException("Cannot open serial port."); } }
@Override protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { JSerialCommDeviceAddress remote = (JSerialCommDeviceAddress) remoteAddress; SerialPort commPort = SerialPort.getCommPort(remote.value()); if (!commPort.openPort()) { throw new IOException("Could not open port: " + remote.value()); } commPort.setComPortTimeouts( SerialPort.TIMEOUT_READ_BLOCKING, config().getOption(READ_TIMEOUT), 0); deviceAddress = remote; serialPort = commPort; }
if (!serialPort.openPort(parameters.getOpenDelay())) { close(); Set<String> ports = getCommPorts();
if (!serialPort.openPort(parameters.getOpenDelay())) { close(); Set<String> ports = getCommPorts();
@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"); }
public synchronized void connect() throws Exception { disconnect(); serialPort = SerialPort.getCommPort(portName); serialPort.openPort(0); serialPort.setComPortParameters(baud, dataBits.mask, stopBits.mask, parity.mask); serialPort.setFlowControl(flowControl.mask); if (setDtr) { serialPort.setDTR(); } if (setRts) { serialPort.setRTS(); } serialPort.setComPortTimeouts( SerialPort.TIMEOUT_READ_SEMI_BLOCKING | SerialPort.TIMEOUT_WRITE_BLOCKING, 500, 0); }