我想使用jsp + servlet 完成串口通讯,但是我在Servlet端获取服务器上的串口时获取不到,求解决!!!服务器是tomcat,在Servlet端使用如下代码获取端口
public void init() {
try {
portList = CommPortIdentifier.getPortIdentifiers(); // 得到当前连接上的端口
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
System.out.println("已有端口名称:" + portId.getName());
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {//
// 判断如果端口类型是串口
if (portId.getName().equals("COM5")) { // 判断如果COM5端口已经启动就连接
ReadPortService reader = new ReadPortService(); // 实例一个
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
获取不到,但是直接写一个main方法调用init()方法时可以获取到串口,求解决