RXTX无法在windows 7 64位下列出或查找端口 [英] RXTX cannot list or find ports under windows 7 64 bits

查看:20
本文介绍了RXTX无法在windows 7 64位下列出或查找端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,

我在 Windows 7 64 位上使用/或安装 rxtx 时遇到问题.我以前在 x86 win XP 系统上使用过它,没有任何问题.由于出于某种原因重新安装到这个新系统,因此 rxtx 无法定位任何端口.我已经尝试过 rxtx 安装、Cloud Hopper 的 64 位本机库并删除所有 rxtx 文件并从头开始.找到了 RXTXcomm.jar,我可以在 NetBeans 中浏览包,但实现似乎已损坏或未找到.

I'm having issues using/or installing rxtx on windows 7 64 bits. I worked with it previously on a x86 win XP system and had no issues. Since reinstalling to this new system for some reason rxtx is unable to locate any ports whatsoever. I've tried the rxtx install, Cloud Hopper's 64 bit native library and deleting all rxtx files and starting from scratch. RXTXcomm.jar is found and I can browse the packages in NetBeans but the implementation seems to be broken or not found.

此行每次执行时都会失败:

This line fails when executing, every time :

comPort = "COM1";
portId = CommPortIdentifier.getPortIdentifier(comPort);

并抛出一个 NoSuchPortException.

and throws a NoSuchPortException.

使用此列出串行端口不会产生任何结果.

Listing the serial ports using this produces nothing.

Enumeration ports = CommPortIdentifier.getPortIdentifiers();
String portArray[] = null;
while (ports.hasMoreElements()) {
    CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
    System.out.println(port.getName());
} 

我已经检查了串行端口是否可用,所以此时我想知道 Windows 7 64 位的本机库是否被简单地破坏了.

I've checked the serial ports are available so at this point I'm wondering if the native libraries are simply broken for windows 7 64 bits.

有人在windows 7 64位下成功使用过RXTX 2.2pre2吗?

Has anyone successfully used RXTX 2.2pre2 under windows 7 64 bits?

构造函数中的违规代码部分:

Offending code section in constructor :

public SerialControl(String name, String comPort, int baudrate, int databits, String     parity, double stopbits) throws Exception {
    int stop = 0;
    int data = 0;
    int par = 0;

    this.name=name;

    // Sanity checks and interpretation
    if (baudrate > 115200 || baudrate < 300) {
        System.err.println(name+": constructor(): Invalid baudrate "+baudrate);
        throw new Exception("Invalid baudrate, " + baudrate);
    }

    if (databits >= 5 && databits <= 8) {
        switch (databits) {
            case 5:
                data = SerialPort.DATABITS_5;
                break;
            case 6:
                data = SerialPort.DATABITS_6;
                break;
            case 7:
                data = SerialPort.DATABITS_7;
                break;
            case 8:
                data = SerialPort.DATABITS_8;
                break;
            default:
                System.err.println(name+": constructor(): Invalid data bits, switched " + databits);
                throw new Exception("Invalid data bits, switched " + databits);
        }
    } else {
        throw new Exception("Invalid data bits=" + databits);
    }

    if (stopbits >= 1.0 && stopbits <= 2.0) {

        if (stopbits == 1.0) {
            stop = SerialPort.STOPBITS_1;
        } else if (stopbits == 1.5) {
            stop = SerialPort.STOPBITS_1_5;
        } else if (stopbits == 2.0) {
            stop = SerialPort.STOPBITS_2;
        } else {
            System.err.println(name+": constructor(): Invalid stop bits, switched " + stopbits);
            throw new Exception("Invalid stop bits, switched " + stopbits);
        }
    } else {
        System.err.println(name+": constructor(): Invalid stop bits, switched " + stopbits);
        throw new Exception("Invalid stop bits " + stopbits);
    }

    switch (parity) {
        case "S":
            par = SerialPort.PARITY_SPACE;
            break;
        case "E":
            par = SerialPort.PARITY_EVEN;
            break;
        case "M":
            par = SerialPort.PARITY_MARK;
            break;
        case "O":
            par = SerialPort.PARITY_ODD;
            break;
        case "N":
            par = SerialPort.PARITY_NONE;
            break;
        default:
            System.err.println(name+": constructor(): Invalid parity, switched " + parity);
            throw new Exception("Invalid parity, switched " + parity);
    }

    // Inits
    // Try to find the port specified
    try {
        portId = CommPortIdentifier.getPortIdentifier(comPort);
    } catch (Exception e) {
        System.err.println(name+": constructor(): No such port "" + comPort+""");
        e.printStackTrace();
        throw e;
    }

    // Open the port
    try {
        serialPort = (SerialPort) portId.open("User Port", 2000);
    } catch (PortInUseException e) {
        System.err.println(name+": constructor(): Could not open port " + comPort);
        throw e;
    }

    // Grab the input stream
    try {
        inputStream = serialPort.getInputStream();
    } catch (IOException e) {
        System.err.println(name+": constructor(): Could not get input stream for " + comPort);
        throw e;
    }

    // Set the serial port parameters, no flow control
    try {
        serialPort.setSerialPortParams(baudrate, data, stop, par);
        serialPort.setDTR(false);
        serialPort.setRTS(false);
    } catch (UnsupportedCommOperationException e) {
        System.err.println(name+": constructor(): Error initializing " + comPort);
        throw e;
    }
}

推荐答案

我遇到了同样的问题.我使用 Eclipse 作为 IDE 进行编程,我在官方 wiki 中找到了这个替代配置:

I got the same problem. I use Eclipse as IDE for programming and i found this alternative configuration in the official wiki:

  1. 将 RXTXcomm.jar 复制到项目的 lib 目录下
  2. 将您的包浏览器导航到 lib 文件夹,右键单击 RXTXcomm.jar |构建路径 |添加到构建路径
  3. 将 rxtxSerial.dll 和 rxtxParallel.dll 文件复制到项目的根目录
  4. 运行中 |运行配置 |类路径选项卡 |用户条目 |高级 |添加文件夹,选择你项目的根文件夹
  5. 这应该足以在 Eclipse 下运行它,在部署可运行的 jar 时,只需确保 dll 与 jar 位于同一文件夹中(JVM 假定它用于类路径)

(这是我的第一个答案,我不知道我是否可以发布外部链接,但是这五个步骤来自 http://rxtx.qbang.org/wiki/index.php/Using_RXTX_In_Eclipse)

(It's my first answer, i don't know if i'm allowed to post an external link, but the five step come's from http://rxtx.qbang.org/wiki/index.php/Using_RXTX_In_Eclipse )

希望能帮到你!

这篇关于RXTX无法在windows 7 64位下列出或查找端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆