Java – rxtx cannot list or find ports under Windows 7 64 bit

good morning,

I'm having trouble using and / or installing rxtx on Windows 7 64 bit I used to have no problem using it on X86 Win XP system For some reason, rxtx could not find any ports to reinstall into this new system I have tried to install rxtx, cloud Hopper's 64 bit native library, delete all rxtx files and start from scratch Rxtxcomm Jar, I can browse the software package in NetBeans, but the implementation seems to have been damaged or can't be found

This line fails each time:

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

And throw nosuchportexception

Using it to list serial ports does not produce any results

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

I have checked whether the serial port is available, so at this time, I want to know whether the local library is damaged only for Windows 7 64 bit

Has anyone successfully used rxtx 2.2pre2 under Windows 7 64 bit?

Illegal code part 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;
    }
}

Solution

I have the same problem I use eclipse as the IDE for programming. I found this alternative configuration in the official Wiki:

>Set rxtxcomm Jar to the Lib directory of the project > navigate package explorer to the Lib folder and right-click rxtxcomm Jar | build path | add to build path > rxtxserial DLL and rxtxparallel Copy the DLL file to the root directory of the project > running | running configuration | classpath tab | user entry | advanced | add folder, select the root folder of the project > this should be enough to run it under eclipse. When deploying a runnable jar, just ensure that the DLL is in the same folder as the jar (the JVM assumes that it is a classpath)

(this is my first answer. I don't know if I can publish external links, but from http://rxtx.qbang.org/wiki/index.php/Using_RXTX_In_Eclipse First five steps)

I hope it helps!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>