1
votes

I have followed the instructions to setup rxtx on windows from http://www.jcontrol.org/download/readme_rxtx_en.html.

What I did exactly was copy rxtxSerial.dll to "C:\Program Files\Java\jdk1.6.0_07\jre\bin" and copied RXTXcomm.jar to "C:\Program Files\Java\jdk1.6.0_07\jre\lib\ext" (my JAVA_HOME variable is set to C:\Program Files\Java\jdk1.6.0_07\jre)

I also added RXTXcomm.jar to my eclipse project.

But when I run it, it still says "NoSuchPortException"

Devel Library
=========================================
Native lib Version = RXTX-2.0-7pre1
Java lib Version   = RXTX-2.0-7pre1
java.lang.ClassCastException: gnu.io.RXTXCommDriver cannot be cast to gnu.io.CommDriver thrown while loading gnu.io.RXTXCommDriver
gnu.io.NoSuchPortException
    at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:218)
    at TwoWaySerialComm.connect(TwoWaySerialComm.java:20)
    at TwoWaySerialComm.main(TwoWaySerialComm.java:107)

In my java file, I tell it:

        try
        {
            (new TwoWaySerialComm()).connect("COM4");
        }

and I've also tried the Java Comm API. Both cannot recognize my serial port but I am sure I followed the instruction correctly. There files are there.

Does anybody have any idea what it could be?

10

10 Answers

1
votes

Try putting rxtxSerial.dll in

C:\Program Files\Java\jdk1.6.0_07\jre\lib\bin
                                      ^^^
1
votes

you can use CommPortIdentifier.getPortIdentifiers()

to identify all possible ports your system finds.

1
votes

I am not too familiar with RXTX, but is this normal?

java.lang.ClassCastException: gnu.io.RXTXCommDriver cannot be cast to gnu.io.CommDriver thrown while loading gnu.io.RXTXCommDriver

Otherwise maybe the problem is not with the port itself after all, but something with the classes themselves? Just a guess.

1
votes

You can also try an alternative solution that was specifically implemented for Windows. There should be plenty available, one of them you can get from http://www.caerustech.com/JCommWin32.php

Shultz

0
votes

It may be that your system does not have a COM4 defined or it's not accessible. It's hard to guess what may be wrong, because you haven't posted you port init code - what you posted looks like wrapper code.

Here is my working init code using the javax.comm API (but using SerialPort from serialio.com):

// name comes from config and is "COM1", "COM2", ...
SerialPort port=(SerialPort)CommPortIdentifier.getPortIdentifier(name).open("YourPortOwnerIdHere",5000);      // owner and ms timeout
port.setSerialPortParams(bau,dtb,stb,par);
port.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN|SerialPort.FLOWCONTROL_RTSCTS_OUT);
port.enableReceiveTimeout(1000);

Hopefully this points you in the right direction.

0
votes

I agree that you're problem looks like a ClassCastException and not the other.

For windows, I'm using "Windows Java Serial Com Port Driver" at http://www.engidea.com/blog/informatica/winjcom/winjcom.html and it is much easier for me to set up.

In either case, you want the DLL in the BIN directory, not LIB\BIN as was suggested. At least that's what's working for me. I'm using NetBeans and I've also found it helpful to put the jar and dll into various bin and lib\ext folders in the JDK.

Note that if you have multiple versions of the JRE on your machine, you might not be using the one that you think you are using. Also, as a practical matter I've found it more helpful to just copy both the jar and dll into the various bin and lib\ext folders. Makes it just a paste, paste, paste operation.

For windows, I recommend "Windows Java Serial Com Port Driver" because it solved my problems with USB serial ports. I had fits with RXTX because it would crash when the USB was unplugged. winjcom solved that problem and others as well. It has very helpful error exceptions.

Also, make sure your serial drivers are up-to-date. Downloading an update fixed my other bug. -Stosh

0
votes

I also had a problem when closing the serialPort within the serialEvent function. Maybe it's a deadlock problem, where the close method waits forever for serialEvent's lock to be released. Starting a new thread to close the port worked for me.

0
votes

For your question, my code is the following:

if (idPuerto == null)
{
            formulario = form;
            boolean encontrado = false;


            listaPuertos = CommPortIdentifier.getPortIdentifiers();

            while( listaPuertos.hasMoreElements() && encontrado == false )
            {
              idPuerto = (CommPortIdentifier)listaPuertos.nextElement();
              //System.out.println(idPuerto.getName());

              if( idPuerto.getPortType() == CommPortIdentifier.PORT_SERIAL )
              {
                if( idPuerto.getName().equals(RFIDBascApp.ComBasc) )
                {        
                    encontrado = true;
                    logger.AddInfoUser("Puerto serie encontrado");

                  }
                }
              }
0
votes

You had NoSuchPortException, so first of all iterate on all available ports!

import gnu.io.CommPortIdentifier;        
import java.util.Enumeration;  

public class ListAvailablePorts {  

    public void list() {  
        Enumeration ports = CommPortIdentifier.getPortIdentifiers();  

        while(ports.hasMoreElements()){  
            CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
            System.out.println(port.getName());
        }
    }  

    public static void main(String[] args) {  
        new ListAvailablePorts().list();  
    }  
} 
-1
votes

@Pinheiro you might want to take a look at this