@Override public void sendByteImmediately(byte b) throws Exception { serialPort.writeBytes(new byte[]{b}, 1); }
@Override public void sendStringToComm(String command) throws Exception { serialPort.writeBytes(command.getBytes(), command.length()); }
@Override public int writeBytes(byte[] buffer, long bytesToWrite) { return serialPort.writeBytes(buffer, bytesToWrite); }
@Override public void sendData(byte[] data) { this.serialPort.writeBytes(data, data.length); }
@Override public void sendData(byte[] data) { this.serialPort.writeBytes(data, data.length); }
@Override public int writeBytes(byte[] buffer, long bytesToWrite) { return serialPort.writeBytes(buffer, bytesToWrite); }
/** * Writes up to <i>bytesToWrite</i> raw data bytes from the buffer parameter to the serial port. * <p> * The length of the byte buffer must be greater than or equal to the value passed in for <i>bytesToWrite</i> * <p> * In blocking-write mode, this call will block until <i>bytesToWrite</i> bytes of data have been successfully written to the serial port. Otherwise, this method will return * after <i>bytesToWrite</i> bytes of data have been written to the device driver's internal data buffer, which, in most cases, should be almost instantaneous unless the data * buffer is full. * * @param buffer The buffer containing the raw data to write to the serial port. * @param bytesToWrite The number of bytes to write to the serial port. * @return The number of bytes successfully written, or -1 if there was an error writing to the port. */ public final int writeBytes(byte[] buffer, long bytesToWrite) { return writeBytes(portHandle, buffer, bytesToWrite, 0); }
/** * Writes up to <i>bytesToWrite</i> raw data bytes from the buffer parameter to the serial port 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>bytesToWrite</i> * <p> * In blocking-write mode, this call will block until <i>bytesToWrite</i> bytes of data have been successfully written to the serial port. Otherwise, this method will return * after <i>bytesToWrite</i> bytes of data have been written to the device driver's internal data buffer, which, in most cases, should be almost instantaneous unless the data * buffer is full. * * @param buffer The buffer containing the raw data to write to the serial port. * @param bytesToWrite The number of bytes to write to the serial port. * @param offset The buffer index from which to begin writing to the serial port. * @return The number of bytes successfully written, or -1 if there was an error writing to the port. */ public final int writeBytes(byte[] buffer, long bytesToWrite, long offset) { return writeBytes(portHandle, buffer, bytesToWrite, offset); }
public void write(int d) throws IOException { byte[] b = new byte[] { (byte) d }; int l = serialPort.writeBytes(b, 1); if (l == -1) { throw new IOException("Write error."); } }
public void writeLine(String data) throws IOException { byte[] b = data.getBytes(); int l = serialPort.writeBytes(b, b.length); if (l == -1) { throw new IOException("Write error."); } b = getLineEndingType().getLineEnding().getBytes(); l = serialPort.writeBytes(b, b.length); if (l == -1) { throw new IOException("Write error."); } }
@Override public void write(IMessage message) { try { byte[] data = _parser.getGatewayData(message); // add raw message to a debug file if (_RAW_MSG_LOGGER.isDebugEnabled()) { MDC.put(GatewayUtils.RAW_MESSAGE_REFERENCE, gatewayReference); _RAW_MSG_LOGGER.debug("Tx: {}", new String(data)); } _serialPort.writeBytes(data, data.length); } catch (Exception ex) { _config.setStatus(STATE.DOWN, "ERROR: " + ex.getMessage()); _logger.error("Exception while writing data, ", ex); } }
@Override public void write(IMessage message) { try { byte[] data = _parser.getGatewayData(message); _serialPort.writeBytes(data, data.length); } catch (Exception ex) { _config.setStatus(STATE.DOWN, "ERROR: " + ex.getMessage()); _logger.error("Exception while writing data, ", ex); } }