public boolean disconnect() { try { serialPort.closePort(); connected = false; } catch (SerialPortException e) { e.printStackTrace(); } return !connected; }
@Override public void closePort() throws Exception { if (this.serialPort != null) { try { this.serialPort.removeEventListener(); if (this.serialPort.isOpened()) { this.serialPort.closePort(); } } finally { this.serialPort = null; } } }
@Override public int shutDown() { if (serialPort.isOpened()) { try { serialPort.removeEventListener(); serialPort.closePort(); return 1; } catch (SerialPortException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } return -1; }
@Override public void closeConnection() { if (portOpened) { if (serialPort != null) { try { serialPort.removeEventListener(); serialPort.closePort(); } catch (SerialPortException e) { } } portOpened = false; } }
@Override public void stop() throws IOException { try { if (port.isOpened()) { port.purgePort(SerialPort.PURGE_RXCLEAR | SerialPort.PURGE_TXCLEAR); port.closePort(); } } catch (SerialPortException ex) { throw new IOException("Cannot properly stop firmata device", ex); } }
@Override public void stop() throws IOException { try { if (port.isOpened()) { port.purgePort(SerialPort.PURGE_RXCLEAR | SerialPort.PURGE_TXCLEAR); port.closePort(); } } catch (SerialPortException ex) { throw new IOException("Cannot properly stop firmata device", ex); } }
/** * Close the connection to the serial port. * * @throws IOException */ public void close() throws IOException { try { serialReader.close(); serialPort.removeEventListener(); serialPort.closePort(); } catch (final SerialPortException e) { throw new IOException(e); } }
/** * Close the connection to the serial port. * * @throws IOException */ public void close() throws IOException { try { serialReader.close(); serialPort.removeEventListener(); serialPort.closePort(); } catch (final SerialPortException e) { throw new IOException(e); } }
/** * Closes the jSSC connection and stops the serialPortWriter Thread */ public void closeConnection() throws SerialPortException { if (serialPort.isOpened()) serialPort.closePort(); stop(); }
/** * {@inheritDoc} * * @see java.lang.Object#finalize() */ @Override protected void finalize() throws Throwable { if (serialPort.isOpened()) { serialReader.close(); serialPort.removeEventListener(); serialPort.closePort(); } super.finalize(); }
/** * {@inheritDoc} * * @see java.lang.Object#finalize() */ @Override protected void finalize() throws Throwable { if (serialPort.isOpened()) { serialReader.close(); serialPort.removeEventListener(); serialPort.closePort(); } super.finalize(); }
@Override protected void closeImpl() throws SerialPortException { Throwable ex = null; try { this.is.close(); } catch (IOException e) { LOG.error(e); ex = e; } try { this.os.close(); } catch (IOException e) { LOG.error(e); ex = e; } try { this.port.closePort(); } catch (jssc.SerialPortException e) { LOG.error(e); ex = e; } if (ex != null) throw new SerialPortException(ex); //May miss some errors if > 1, but hey we get something back. }
SerialPort serialPort = new SerialPort("/dev/ttyUSB0");// For windows "COMX" (e.g : "COM1") should works if (serialPort.openPort()) { serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_ODD); byte[] buffer = serialPort.readBytes(1);// Read one byte String str = new String(buffer); serialPort.closePort(); }
public class Main { public static void main(String[] args) { SerialPort serialPort = new SerialPort("COM1"); try { serialPort.openPort();//Open serial port serialPort.setParams(9600, 8, 1, 0);//Set params. byte[] buffer = serialPort.readBytes(10);//Read 10 bytes from serial port serialPort.closePort();//Close serial port } catch (SerialPortException ex) { System.out.println(ex); } } }
public class Main { public static void main(String[] args) { SerialPort serialPort = new SerialPort("COM1"); try { serialPort.openPort();//Open serial port serialPort.setParams(9600, 8, 1, 0);//Set params. byte[] buffer = serialPort.readBytes(10);//Read 10 bytes from serial port serialPort.closePort();//Close serial port } catch (SerialPortException ex) { System.out.println(ex); } } }
@Override public void disconnect() { try { _serialPort.closePort(); _config.setStatus(STATE.DOWN, "Stopped."); _logger.debug("_serialPort{} closed", _serialPort.getPortName()); } catch (SerialPortException ex) { if (ex.getMessage().contains("Port not opened")) { _logger.debug("unable to close the port, Error: {}", ex.getMessage()); } else { _logger.error("unable to close the port{}", _serialPort.getPortName(), ex); } _config.setStatus(STATE.DOWN, "ERROR:" + ex.getMessage()); } }
@Override public void disconnect() { try { _serialPort.closePort(); _config.setStatus(STATE.DOWN, "Stopped."); _logger.debug("_serialPort{} closed", _serialPort.getPortName()); } catch (SerialPortException ex) { if (ex.getMessage().contains("Port not opened")) { _logger.debug("unable to close the port, Error: {}", ex.getMessage()); } else { _logger.error("unable to close the port{}", _serialPort.getPortName(), ex); } _config.setStatus(STATE.DOWN, "ERROR:" + ex.getMessage()); } }
public static void main(String[] args) { char ESC = (char) 27; // Ascii character for Escape char LN = (char) 10; String message = "TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:NONE"; String cmd = ESC + message + LN; SerialPort serialPort = new SerialPort("/dev/ttyUSB0"); try { serialPort.openPort(); serialPort.setParams(SerialPort.BAUDRATE_57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.writeString(cmd); serialPort.closePort(); } catch (SerialPortException ex) { System.out.println(ex); } }