NoSuchPortException using RXTX Java library on Windows?

I followed the instructions for installing rxtx on windows from http://www.jcontrol.org/download/readme_rxtx_en.html .

What I did exactly was copy rxtxSerial.dll file 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 have 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 will say:

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

and I also tried Java Comm API. Both can't recognize my serial port, but I'm pretty sure I followed the instruction correctly. There are files.

Does anyone know what this might be?

+1


source to share


10 replies


Try adding rxtxSerial.dll

to



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

      

+1


source


you can use CommPortIdentifier.getPortIdentifiers ()



to identify all possible ports found by your system.

+1


source


I'm not very familiar with RXTX, but is this ok?

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, but with the classes themselves? Let's just assume.

+1


source


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

Schultz

+1


source


Your system may not have COM4 or it is not available. It's hard to guess what might be wrong because you didn't send you the port initialization code - what you posted looks like shell code.

Here is my working initialization 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 indicates that you are in the right direction.

0


source


I agree that your problem looks like a ClassCastException and not something else.

For windows, I use the "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 any case, you need the DLL in the BIN directory, not the LIB \ BIN as suggested. At least that's what works for me. I am using NetBeans and I also found it useful to put the jar and dll in different bin and lib \ ext folders in the JDK.

Note that if you have multiple versions of the JRE on your computer, you may not be using the one that you think you are using. Also, as a practical matter, I found it more useful to just copy both the jar and the dll to the different bin and lib \ ext folders. Makes it just paste, paste, paste.

For windows, I recommend "Java Serial Com Port Driver" because it solved my problems with USB serial ports. I had seizures with RXTX because it crashed when USB was unplugged. winjcom has solved this problem and others. It has very useful error exceptions.

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

0


source


I also had a problem when closing serialPort in serialEvent function. Maybe it's a deadlock issue where the close method is always waiting for the serialEvent block to complete. Starting a new thread to close the port worked for me.

0


source


As per your question, my code looks like this:

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


source


You had NoSuchPortException

, so first of all go to 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();  
    }  
} 

      

0


source


@Pinheiro you can take a look at this

-1


source







All Articles