返回信息流问题:
输出的几个结果
portList=javax.comm.CommPortEnumerator@1d62270
portList.nextElement()=null
CommPortIdentifier.PORT_SERIAL=1
portList.hasMoreElements()=false
为什么portList.nextElement()=null,portList.hasMoreElements()=false
使得下面红色字段的判断无法进入
代码段:
portList=CommPortIdentifier.getPortIdentifiers();
//用循环结构找出串口
while(portList.hasMoreElements()) {
//强制转换为通讯端口类型
portId=(CommPortIdentifier)portList.nextElement();
if(portId.getPortType()==CommPortIdentifier.PORT_SERIAL)
{
if(portId.getName().equals("COM1"))
{
//打开串口
try {
outputStream=serialPort.getOutputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}[/face]
这是一条镜像帖。来源:北邮人论坛 / java / #22368同步于 2012/5/8
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
java串口通信问题,求指教,急!!
mm5695
2012/5/8镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
在硬件管理中可以看到系统默认的通信端口COM1,在没有加外设的情况下只有这一个。
你可以用端口虚拟软件多弄几个再试就知道了
【 在 mm5695 的大作中提到: 】
: 问题:
: 输出的几个结果
: portList=javax.comm.CommPortEnumerator@1d62270
: ...................
我弄了几个虚拟端口,但是还是不行,会不会是我的配置有问题呢
【 在 superboy168 的大作中提到: 】
: 在硬件管理中可以看到系统默认的通信端口COM1,在没有加外设的情况下只有这一个。
: 你可以用端口虚拟软件多弄几个再试就知道了
请直接检查你的portList是否为null
【 在 mm5695 的大作中提到: 】
: 问题:
: 输出的几个结果
: portList=javax.comm.CommPortEnumerator@1d62270
: ...................
这是我运行程序的一些变量的值,求指点
portList=javax.comm.CommPortEnumerator@1d62270
portList.nextElement()=null
CommPortIdentifier.PORT_SERIAL=1
portList.hasMoreElements()=false
【 在 superboy168 的大作中提到: 】
: 请直接检查你的portList是否为null