为什么找不到串口?
我是按着网上面的说明这样安装的:我用的是JDK1.6
1.把javax.comm.properties文件拷贝到Java运行时环境的lib目录中,即:
C:\Program Files\Java\jdk1.5.0_12\lib\javax.comm.properties
C:\Program Files\Java\jdk1.5.0_12\jre\lib\javax.comm.properties
2.把win32com.dll拷贝到C:\windows\system32\ 和 C:\Program Files\Java\jdk1.5.0_12\jre\bin\下
3.把comm.jar放到Java运行时环境的lib目录中,即C:\Program Files\Java\jdk1.5.0_12\lib\comm.jar
4.在"环境变量"的CLASSPATH中添加comm.jar,如:%JAVA_HOME%\lib\comm.jar;
程序:
import javax.comm.*;
import javax.comm.SerialPort;
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Enumeration en = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId;
try
{
while (en.hasMoreElements())
{
portId = (CommPortIdentifier) en.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
{
System.out.println(portId.getName());
}
}
}catch(NoSuchElementException e)
{
}
try
{
portId = CommPortIdentifier.getPortIdentifier("COM1");
}catch(NoSuchPortException e)
{
e.printStackTrace();
}
}
}
可是Enumeration en = CommPortIdentifier.getPortIdentifiers()中的en总是空的,portId = CommPortIdentifier.getPortIdentifier("COM1");出现javax.comm.NoSuchPortException
搞不明白什么地方弄错了