1

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 Answers 10

1

Try putting rxtxSerial.dll in

C:\Program Files\Java\jdk1.6.0_07\jre\lib\bin
                                      ^^^
1
  • I don't think that is correct. rxtx.qbang.org/wiki/index.php/Installation_for_Windows says that "Copy rxtxserial.dll to C:\Program Files\Java\jre7\bin"
    – likejudo
    Mar 7, 2013 at 23:09
1

you can use CommPortIdentifier.getPortIdentifiers()

to identify all possible ports your system finds.

3
  • Found this via search as I've got an instance of a new updated app not finding the com port (and the old one still does). Tried the getPortIdentifiers and interestingly enough, it just returns null. Does that mean no ports available, or am I doing something else wrong? Jan 20, 2010 at 15:39
  • Update on mine. Appears to be something horribly broken somewhere. I have to checkout from SVN to a Solaris box, copy the files to Windows, compile there, then drag the build back to Solaris to make it go. For some reason the built version fails if I either SVN checkout on Windows or do the build on Solaris. Sigh. Apparently something's corrupted somewhere. Jan 28, 2010 at 16:12
  • To list all ports = for (Enumeration<CommPortIdentifier> e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements();) System.out.println(e.nextElement().getName()); Aug 15, 2017 at 14:15
1

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

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

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

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

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

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

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

@Pinheiro you might want to take a look at this

1
  • Random links to other places are not a good answer. You should distill the information to answer the question, and provide the link as a reference for more informatin.
    – AllenKll
    Apr 14, 2016 at 13:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.