我使用sun提供javacomm20-win32包写了一个java串口通信的程序,使用SerialPort.open方法打开com1串口时总是报端口被占用异常,
但使用串口工具测试,端口却并未被占用。按照要求,我已经将javacomm20-win32提供的win32com.dll放置在jdk\jre\bin目录下,
将javax.comm.properties放置在jdk\jre\lib目录下,将comm.jar包放置在jdk\jre\lib\ext目录下。程序代码如下:public void open()throws Exception{
portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {
            portId = (CommPortIdentifier) portList.nextElement();
            
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
             System.out.println("--------------------------> name=" + portId.getName());
            }
            
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL && portId.getName().equals("com1")) {
             break;
            }
        }

/* open方法打开通讯端口,获得一个CommPort对象。它使程序独占端口。
        * 如果端口正被其他应用程序占用,将使用 CommPortOwnershipListener事件机制,
* 传递一个PORT_OWNERSHIP_REQUESTED事件。每个端口都关联一个 InputStream和一个OutputStream。
* 如果端口是用open方法打开的,那么任何的getInputStream都将返回相同的数据流对象,除非有close 被调用。
* 有两个参数,第一个为应用程序名;第二个参数是在端口打开时阻塞等待的毫秒数。*/
        serialPort = (SerialPort) portId.open("Reader", 2000);
     serialPort.addEventListener(this);/*注册一个SerialPortEventListener事件来监听串口事件 */
     serialPort.notifyOnDataAvailable(true);/*数据可用*/
    
     /*设置串口初始化参数,依次是波特率,数据位,停止位和校验*/
     serialPort.setSerialPortParams(115200,
     SerialPort.DATABITS_8,
     SerialPort.STOPBITS_1,
     SerialPort.PARITY_NONE);
}
}有谁知道是什么问题造成总是抛出javax.comm.PortInUseException: Port currently owned by Unknown Windows Application。
初次写串口通信程序,请大家多多帮忙。感激不尽。