Serial port gnu.io.PortinUseeException:未知应用程序?

Serial port gnu.io.PortinUseeException:未知应用程序?,serial-port,rxtx,Serial Port,Rxtx,正在给予 void connect ( String portName ) throws Exception { CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); if ( portIdentifier.isCurrentlyOwned() ) { System.out.println("Error: Port is currently i

正在给予

void connect ( String portName ) throws Exception
{
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    if ( portIdentifier.isCurrentlyOwned() )
    {
        System.out.println("Error: Port is currently in use");
    }
    else
    {
        System.out.println(portIdentifier.getCurrentOwner());
        CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);

        if ( commPort instanceof SerialPort )
        {
            SerialPort serialPort = (SerialPort) commPort;
            serialPort.setSerialPortParams(115200,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);

            InputStream in = serialPort.getInputStream();
            OutputStream out = serialPort.getOutputStream();

            (new Thread(new SerialReader(in))).start();
            (new Thread(new SerialWriter(out))).start();

        }
        else
        {
            System.out.println("Error: Only serial ports are handled by this example.");
        }
    }     
}

我正在windows 7 home 64位中使用RXTX和Java。

重新启动系统/禁用端口。
实际问题是当程序运行时,端口被打开,但在程序终止后没有关闭。

它可以工作。

我遇到了这个问题,因为该端口实际上正在使用。以前的javaw.exe实例出现在Windows任务管理器中,它占用了端口


前一个java进程挂起的原因是硬件问题:当我将碰巧使用的USB-2串行转换器插入USB-2端口时,一切正常。当插入USB-3端口时,RXTX CommPortIdentifier代码将挂起,随后Java实例将收到PortinUseeException。

检查您的计算机上是否存在/var/lock文件夹

gnu.io.PortInUseException: Unknown Application
    at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)

我使用Process Explorer查找具有句柄
\Device\PCISerial0
的进程,并关闭了句柄。如果您的com端口不在PCI卡上,则名称可能不同。

适用于Windows 打开任务管理器 在Eclipse(或您的ide)下查找Java应用程序。 右键单击它->结束任务


mkdir /var/lock
chmod go+rwx /var/lock