Home > Back-end >  Java open the serial port appear because the thread exits or serial communication application reques
Java open the serial port appear because the thread exits or serial communication application reques

Time:09-17

CodePudding user response:

For the open operation times the wrong

PortId=CommPortIdentifier. GetPortIdentifier (portName);
If (portId==null) {
System. The out. Println (" port is null ");
}
COMname=portName;
//open ports, and port name and a timeout (open operation timeout)
Thread.sleep (10);
CommPort CommPort=portId. Open (portName, 10);
//determine whether serial
If (commPort instanceof SerialPort) {
SerialPort=(serialPort commPort);


//set the baud rate of serial port parameters such as
//data bits: 8
//stop bit: 1
//check digit: None
SerialPort. SetSerialPortParams (115200, serialPort. DATABITS_8, serialPort. STOPBITS_1,
SerialPort. PARITY_NONE);
//below is used for communication and the COM input, the output stream,
In=new InputStreamReader (serialPort getInputStream ());
Out=new OutputStreamWriter (serialPort getOutputStream ());
  • Related