大侠,救命啊,我真的不知道怎么办了1!
import javax.comm.*;
import java.io.*;
import java.util.*; class IMU
{ static CommPortIdentifier portId;
static SerialPort serialPort;
static OutputStream out;
static InputStream in; public static void main(String[] args)
{
try
{
//Declare the serial port, and open it.
portId = CommPortIdentifier.getPortIdentifier("COM1");
{ //System.out.println(e.getMessage());
System.out.println(portId.getName());
}
} }
好了,这回代码少了,可以看清楚了吧,就是那句话
portId = CommPortIdentifier.getPortIdentifier("COM1");
得不到com1啊,为什么啊?
portId是空的(null),这是为什么
import javax.comm.*;
import java.io.*;
import java.util.*; class IMU
{ static CommPortIdentifier portId;
static SerialPort serialPort;
static OutputStream out;
static InputStream in; public static void main(String[] args)
{
try
{
//Declare the serial port, and open it.
portId = CommPortIdentifier.getPortIdentifier("COM1");
{ //System.out.println(e.getMessage());
System.out.println(portId.getName());
}
} }
好了,这回代码少了,可以看清楚了吧,就是那句话
portId = CommPortIdentifier.getPortIdentifier("COM1");
得不到com1啊,为什么啊?
portId是空的(null),这是为什么
谢谢先!
问题是,我现在不能取得CommPortIdentifier类的一个实例啊
我通过下面的语句来取
static CommPortIdentifier portId;
portId = CommPortIdentifier.getPortIdentifier("COM1");
但是取得的是null
就是说portId是null
到底是哪里出了问题呢
import javax.comm.*;public class Test2 {
public static void main(String args[]) { //列出你的计算机上的所有的串口的名称
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println(portId.getName());
}
} //如果"COM1"不存在的话就会抛出NoSuchPortException
try {
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM1");
System.out.println(portId.getName());
} catch (NoSuchPortException nspe) {
System.out.println(nspe);
}
}
}
非常感谢你的帮助!
我现在的问题是,在这一步
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
portList 返回的是空直,进不去while循环
这是怎么回事?
我到别人的机器上也式过,结果一样
是不是机器断口需要配置啊
谢谢
win32包里面个配置说明文档JDK1.2.html