/** * Sends a command to the serial device. This actually streams the bits to * the comm port. * @param command Command to be sent to serial device. */ @Override public void sendStringToComm(String command) throws Exception { this.serialPort.writeString(command); }
@Override public boolean sendCommand(String string) { try { return serialPort.writeString(string); } catch (SerialPortException e) { e.printStackTrace(); } return false; }
public void forwardMessage(int[]message) { String messageString = ""; for (int i = 0; i < message.length-1; i++) messageString+=Integer.toHexString(Math.max(0,Math.min(message[i],255))) + " "; messageString+=Integer.toHexString(Math.max(0,Math.min(message[message.length-1],255))) + "\n"; try { System.out.println("messageString:" + messageString); serialPort.purgePort(SerialPort.PURGE_TXCLEAR | SerialPort.PURGE_RXCLEAR); serialPort.writeString(messageString); } catch (SerialPortException e) { e.printStackTrace(); } }
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); } }