java操作并串口

code即正义 发布于 2017/06/23 14:10
阅读 186
收藏 0
 CommPortIdentifier portID = CommPortIdentifier.getPortIdentifier("LPT1");
             ParallelPort port = (ParallelPort) portID.open("Read", 30);
             port.addEventListener(new ParallelPortEventListener() {
                @Override
                public void parallelEvent(ParallelPortEvent arg0) {
                }
            });
                OutputStream out = port.getOutputStream();

这是我写的获得LPT端口的代码,下面的截图是设备管理器里面的所有端口

下面是控制台报错

gnu.io.NoSuchPortException
	at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:269)
	at com.jayp.print.Test.service(Test.java:43)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)

为什么一直显示没有这个端口,我初始化端口的配置哪里有问题吗?我是从网上找的一个demo写的

加载中
0
c
code即正义

我用getPortIdentifiers()方法获取设备上的所有端口,但是得到的枚举类是空的,意思是这个设备上没有端口?但是这不可能啊。我是在本机上跑的servlet,然后做的端口映射远程在客户那里访问测试的,但是我在本地访问的这个枚举也是空,这到底是为什么?

返回顶部
顶部