@Override public void serialEvent(com.fazecast.jSerialComm.SerialPortEvent event) { if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE) { return; } int bytesAvailable = serialPort.bytesAvailable(); if (bytesAvailable <= 0) { return; } int bytesRead = serialPort.readBytes(buffer, Math.min(buffer.length, bytesAvailable)); String response = new String(buffer, 0, bytesRead); responseMessageHandler.handleResponse(response, comm); } }
@Override public int readBytes(byte[] buffer, long bytesToRead) { return serialPort.readBytes(buffer, bytesToRead); }
@Override public int readBytes(byte[] buffer, long bytesToRead) { return serialPort.readBytes(buffer, bytesToRead); }
/** * Reads up to <i>bytesToRead</i> raw data bytes from the serial port and stores them in the buffer. * <p> * The length of the byte buffer must be greater than or equal to the value passed in for <i>bytesToRead</i> * <p> * In blocking-read mode, if no timeouts were specified or the read timeout was set to 0, this call will block until <i>bytesToRead</i> bytes of data have been successfully * read from the serial port. Otherwise, this method will return after <i>bytesToRead</i> bytes of data have been read or the number of milliseconds specified by the read timeout * have elapsed, whichever comes first, regardless of the availability of more data. * * @param buffer The buffer into which the raw data is read. * @param bytesToRead The number of bytes to read from the serial port. * @return The number of bytes successfully read, or -1 if there was an error reading from the port. */ public final int readBytes(byte[] buffer, long bytesToRead) { return readBytes(portHandle, buffer, bytesToRead, 0); }
/** * Reads up to <i>bytesToRead</i> raw data bytes from the serial port and stores them in the buffer starting at the indicated offset. * <p> * The length of the byte buffer minus the offset must be greater than or equal to the value passed in for <i>bytesToRead</i> * <p> * In blocking-read mode, if no timeouts were specified or the read timeout was set to 0, this call will block until <i>bytesToRead</i> bytes of data have been successfully * read from the serial port. Otherwise, this method will return after <i>bytesToRead</i> bytes of data have been read or the number of milliseconds specified by the read timeout * have elapsed, whichever comes first, regardless of the availability of more data. * * @param buffer The buffer into which the raw data is read. * @param bytesToRead The number of bytes to read from the serial port. * @param offset The read buffer index into which to begin storing data. * @return The number of bytes successfully read, or -1 if there was an error reading from the port. */ public final int readBytes(byte[] buffer, long bytesToRead, long offset) { return readBytes(portHandle, buffer, bytesToRead, offset); }
public int read() throws TimeoutException, IOException { byte[] b = new byte[1]; int l = serialPort.readBytes(b, 1); if (l == -1) { throw new IOException("Read error."); } if (l == 0) { throw new TimeoutException("Read timeout."); } return b[0]; }
@Override public byte[] getData() { int bytesAvailable = this.serialPort.bytesAvailable(); byte[] buffer = new byte[bytesAvailable]; this.serialPort.readBytes(buffer, bytesAvailable); return buffer; }
@Override public byte[] getData() { int bytesAvailable = this.serialPort.bytesAvailable(); byte[] buffer = new byte[bytesAvailable]; this.serialPort.readBytes(buffer, bytesAvailable); return buffer; }
_serialPort.readBytes(buffer, buffer.length); for (byte b : buffer) { if ((b == ISerialDriver.MESSAGE_SPLITTER) && rawMessage.length() > 0) {
_serialPort.readBytes(buffer, buffer.length); for (byte b : buffer) { if ((b == ISerialDriver.MESSAGE_SPLITTER) && rawMessage.length() > 0) {