java - Send a String to serial port as a command for embedded device -


I am working on a project that contains an embedded device. I hope to send commands to this device. This command is a string: "LAMP1_ON \ r \ n";

I am using RXTX with Java and sending data via serial port. But when I send the string command, the device receives "AMP_N" and some other sketching strings.

I do not know why it is so, and how can I fix it.

My code is below:

  Public class SerialWriter executes Runnable {OutputStream out; Letter string; Public serial (output stream out, string str) {this.out = out; This.str = str; } Run Public Zero () {try {byte [] array = this.str.getBytes (); This.out.write (array); This.out.flush (); } Hold (IOException e) {e.printStackTrace (); }}}  

I hope to send the string to the port via the method of writing. It works but does not send the exact string which is included in this.str , instead it sends "AMP_N" and "AMP" and dispersed string

I have seen the problem that I did not set the FLOWCONTROL property properly. This code works fine

  serialPort.setSerialPortParams (9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); SerialPort.setFlowControlMode (SerialPort.FLOWCONTROL_NONE);  

Comments