7

Good morning,

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);

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());
} 

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.

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;
    }
}
darkhelmet
  • 123
  • 1
  • 2
  • 7
  • both `SerialControl` and CommPortIdentifier#getPortIdentifiers()` work from Eclipse and the command line – GrahamA Aug 30 '12 at 10:47
  • A little followup for people who may encounter this, my projects were imported from a windows XP environment, rebuilding them in Windows 7 seem to have corrected whatever the problem was. – darkhelmet Oct 22 '12 at 17:52

2 Answers2

9

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

  1. Copy RXTXcomm.jar to the lib directory of your project
  2. Navigate your package explorer to the lib folder, right click on RXTXcomm.jar | Build Path | Add to built path
  3. Copy rxtxSerial.dll and rxtxParallel.dll files to the root directory of your project
  4. Under Run | Run configurations | Classpath tab | User entries | Advanced | Add folder, choose the root folder of your project
  5. This should be enough just to run it under Eclipse, when deploying a runnable jar, just make sure the dlls are on the same folder as the jar (JVM assumes it for classpath)

(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 )

Hope it help !

Maffo
  • 91
  • 1
  • 2
  • External links to references are encouraged! Just be careful about self-promotion (see the [FAQ](http://stackoverflow.com/faq#promotion))... but that doesn't seem to be an issue in this case. :) – hopper Nov 20 '12 at 17:12
  • Thanks! I'm a bit late in responding but I was able to use this while I rebuilt my NetBeans projects. – darkhelmet Mar 21 '13 at 17:22
2

It appers to work for me using Windows 7 and 64-bit versions of Java and RXTX (cloudhopper version)

enter image description here

Are you sure you have a COM1?

GrahamA
  • 5,875
  • 29
  • 39
  • Yes I use it all the time with Putty. Your code lists my ports correctly when I run it in a separate application, but when run from my serial class the ports are not found... the mystery thickens but it seems like a library problem. – darkhelmet Aug 29 '12 at 16:56
  • @darkhelmet if you want to post your serial class I'll try running it – GrahamA Aug 29 '12 at 18:50
  • the class has a couple of dependencies to other classes, I can't post it all but here's the relevant part in the constructor where it happens; it's the first thing where I'm initializing the serial port – darkhelmet Aug 29 '12 at 20:59