uj5u.com熱心網友回復:
進行open操作時報這個錯portId = CommPortIdentifier.getPortIdentifier(portName);
if (portId == null) {
System.out.println("port is null");
}
COMname=portName;
// 打開埠,并給埠名字和一個timeout(打開操作的超時時間)
Thread.sleep(10);
CommPort commPort = portId.open(portName, 10);
// 判斷是不是串口
if (commPort instanceof SerialPort) {
serialPort = (SerialPort) commPort;
// 設定一下串口的波特率等引數
// 資料位:8
// 停止位:1
// 校驗位:None
serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
// 下面是得到用于和COM口通訊的輸入、輸出流。
in = new InputStreamReader(serialPort.getInputStream());
out = new OutputStreamWriter(serialPort.getOutputStream());
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/41321.html
標籤:Java相關
