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 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); } } }
int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR _serialPort.setEventsMask(mask);//Set mask
int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR _serialPort.setEventsMask(mask);//Set mask