Java host computer to the microcontroller to write serial instructions, the simple code is as follows:
Import java.io.inputstream;import java.io.outputstream;import javax.comm.*;p ublic class Test {public static void Main (String args[]) throws Exception { Commportidentifier Serialportid = Commportidentifier.getportidentifier ("COM3"); SerialPort port = (SerialPort) serialportid.open ("Read", +); Open the COM3 serial port, where 30 is the timeout time to open the serial port port.setserialportparams (9600, 8, 1, 0);//Set COM2 baud rate, data bit, stop bit, check mode // Get input output stream from the string byte[] buffer = {0x0f,0x01,0x00};//controlling command outputstream out = Port.getoutputstream ( ); Out. write (buffer); Out. Flush (); InputStream in = Port.getinputstream (); In.read (data); Data is a byte[] }}
Reference
[1].http://blog.csdn.net/pigteacher/article/details/5619955
Java Write serial port