serial-port - gnu.io.PortInUseException : Unknown Application?

标签 serial-port rxtx

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.");
        }
    }     
}

正在给予
gnu.io.PortInUseException: Unknown Application
    at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)

我在 64 位 Windows 7 家庭版中使用带有 Java 的 RXTX。

最佳答案

检查您的机器上是否存在/var/lock 文件夹。
mkdir /var/lock chmod go+rwx /var/lock

关于serial-port - gnu.io.PortInUseException : Unknown Application?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9044758/

相关文章:

macos - 尝试在MacOS中打开串行端口时,open(2)函数挂起

c - 如何在Linux中使用串口读取字符

c - Ater 增加 sleep() fd 无法正常工作

尝试使用 RXTXcomm jar 加载小程序时出现 java.lang.ExceptionInInitializerError

加载 gnu.io.RXTXCommDriver 时抛出 java.lang.UnsatisfiedLinkError : no rxtxSerial in java. library.path

c - 在 Raspberry PI 3 上的 C++ 中达到超时后如何清除 select() 状态

通过串行接口(interface)用c++连接到cisco路由器

java - 如何使用 Java 点亮 Arduino Mega 二极管?

Mac 上的 Java rxtx lib segv 错误

Windows x64 中使用 JRE x86 的 Java 串行 I/O