public boolean connect(String address, int baudRate) { serialPort = new SerialPort(address); connected = false; try { int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR; serialPort.openPort(); serialPort.setParams(baudRate, 8, 1, 0); serialPort.setEventsMask(mask);// Set mask // serialPort.addEventListener(this); connected = true; } catch (SerialPortException ex) { System.err.println(ex); } return connected; }
public SerialPortInterface(DataReceiver receiver, int numberOfChannels, String address, int baudRate, boolean bit24) { this.receiver = receiver; this.address = address; this.baudRate = baudRate; this.numberOfChannels = numberOfChannels; this.data = new ArrayList<double[]>(); this.bit24 = bit24; SerialPortReader.bit24 = bit24; serialPort = new SerialPort(address); try { int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR; serialPort.openPort(); serialPort.setParams(baudRate, 8, 1, 0); serialPort.setEventsMask(mask);// Set mask serialPort.addEventListener(serialPortReader = new SerialPortReader()); connectionSuccessful = true; recording = false; } catch (SerialPortException ex) { System.err.println(ex); } }
@Override public boolean openPort() throws Exception { if (StringUtils.isEmpty(portName) || baudRate == 0) { throw new ConnectionException("Couldn't open port " + portName + " using baud rate " + baudRate); } this.responseMessageHandler = new ResponseMessageHandler(); this.serialPort = new SerialPort(portName); this.serialPort.openPort(); this.serialPort.setParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE, true, true); this.serialPort.addEventListener(this); if (this.serialPort == null) { throw new ConnectionException("Serial port not found."); } return serialPort.isOpened(); }
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); } } }
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); } }
this.serialPort.openPort(); this.serialPort.setParams(baudrate, databits, stopbits, parity); } catch (SerialPortException e) {
@Override public void start() throws IOException { if (!port.isOpened()) { try { port.openPort(); port.setParams( SerialPort.BAUDRATE_57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); port.setEventsMask(SerialPort.MASK_RXCHAR); port.addEventListener(this); } catch (SerialPortException ex) { throw new IOException("Cannot start firmata device", ex); } } }
@Override public void start() throws IOException { if (!port.isOpened()) { try { port.openPort(); port.setParams( SerialPort.BAUDRATE_57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); port.setEventsMask(SerialPort.MASK_RXCHAR); port.addEventListener(this); } catch (SerialPortException ex) { throw new IOException("Cannot start firmata device", ex); } } }
@Override public void openConnection(String portName) throws Exception { if (portOpened) return; closeConnection(); // open the port serialPort = new SerialPort(portName); serialPort.openPort();// Open serial port serialPort.setParams(BAUD_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.addEventListener(this); connectionName = portName; portOpened = true; waitingForCue = true; }
@Override protected void openImpl() throws SerialPortException { try { if (LOG.isDebugEnabled()) LOG.debug("Opening Serial Port: " + commPortId); this.port = new SerialPort(commPortId.getName()); this.port.openPort(); this.port.setFlowControlMode(flowControlIn | flowControlOut); this.port.setParams(baudRate, dataBits, stopBits,parity); this.is = new JsscSerialPortInputStream(this.port, this.listeners); this.os = new JsscSerialPortOutputStream(this.port); } catch (jssc.SerialPortException e) { throw new SerialPortException(e); } }
serialPort.openPort(); serialPort.setParams(dataRate, dataBits, stopBits, parity);
serialPort.openPort(); serialPort.setParams(dataRate, dataBits, stopBits, parity);
_serialPort.openPort();//Open port _serialPort.setParams( _config.getBaudRate(),
_serialPort.openPort();//Open port _serialPort.setParams( _config.getBaudRate(),