菜鸟求助,串口通信,又是NoSuchPortException
代码如下
import java.io.*;
import java.util.*;
import javax.comm.*;
public class Communication {
private static SerialPort serialPort;
private static String portName;
private static InputStream in;
private InputStream inputStream;
public static void main (String arg[]){
try{
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portName) ;
try {
serialPort = (SerialPort)portId.open("Serial_Communication",5000);
} catch (PortInUseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
serialPort. setSerialPortParams (4800,SerialPort.DATABITS_8,SerialPort.STOPBITS_1 ,SerialPort.PARITY_NONE);
try {
in = serialPort.getInputStream();
} catch (
IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch (UnsupportedCommOperationException e)
{
System.out.println("UnsupportedCommOperation");
}
catch (NoSuchPortException e)
{
System.out.println("NoSuchPort");
}
System.out.println("done") ;
}
运行结果
NoSuchPort
done
鼠标放在CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portName)上面,会提示
This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.
求高手指教。。
------解决方案--------------------
汗
portName没有进行初始化。那肯定就是空了。
------解决方案--------------------
探讨 引用: 汗 portName没有进行初始化。那肯定就是空了。 请问如何初始化,请指教啊大侠。。