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(); }
/** * @param serialPort * @throws SerialPortException */ public JsscSerialPortInputStream(SerialPort serialPort, List<SerialPortProxyEventListener> listeners) throws jssc.SerialPortException { this.listeners = listeners; this.dataStream = new LinkedBlockingQueue<Byte>(); this.port = serialPort; this.port.addEventListener(this, SerialPort.MASK_RXCHAR); //Setup a bounded Pool that will execute the listener tasks in Order this.listenerTasks = new ArrayBlockingQueue<SerialPortProxyEventTask>(this.maxPoolSize); if(LOG.isDebugEnabled()) LOG.debug("Creating Jssc Serial Port Input Stream for: " + serialPort.getPortName()); }
@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; }
serialReader = new SerialReader(inputStream, regexParser); serialReader.addSerialDataListener(this); serialPort.addEventListener(serialReader, SerialPort.MASK_RXCHAR);
serialReader = new SerialReader(inputStream, regexParser); serialReader.addSerialDataListener(this); serialPort.addEventListener(serialReader, SerialPort.MASK_RXCHAR);
_serialPort.addEventListener(new SerialDataListenerJssc(_serialPort, _config, _parser, _queue)); _logger.debug("Serial port gateway initialized, GatewayTable[{}]", _config); _config.setStatus(STATE.UP, "Connected Successfully");
_serialPort.addEventListener(new SerialDataListenerJssc(_serialPort, _config, _parser, _queue)); _logger.debug("Serial port gateway initialized, GatewayTable[{}]", _config); _config.setStatus(STATE.UP, "Connected Successfully");