I am on Windows Seven 64-bit. I wrote a little application that uses RXTX
to communication through serial port. I used the rxtxSerial.dll
for Windows 64-bit and it works pretty well on both Eclispe and NetBeans.
At the root of the project, I placed RXTXComm.jar
and rxtxSerial.dll.
The problem appears when I want to deploy the application. I used the Export function on Eclipse or I accessed the bin/ folder from NetBeans. I placed again RXTXComm.jar
and rxtxSerial.dll
at the root of the folders but when I execute the Application.jar, RXTX
doesn't seem working. The scan seems to stay stuck whereas it shouldn't last more than a second.
[Sorry, I "need at least 10 reputation to post images."]
I tried all the suggestions I found on the internet:
I must be missing something. Has anyone already been successful in deploying RXTX
for Windows 32/64bit and MAC? Could you describe what you did and what is necessary to do so?
Please find below the piece of code executing when scanning for ports:
private void scanButtonAction()
{
if(scanState == ST_FREE)
{
scanState = ST_SCANNING;
redrawComponents();
scan = new Thread(new ScanPorts());
scan.start();
}
}
// Thread run to scan the ports
private class ScanPorts implements Runnable {
public void run()
{
try
{
UARTConnection connection = new UARTConnection();
// listPort() is a long blocking call
String[][] list = connection.listPorts();
// Display the ports in the ComboBox
comboBoxModel.removeAllElements();
if(list.length == 0) comboBoxModel.addElement( new Item(-1, "No port scanned", "" ) );
else
{
for(int i = 0; i < list.length; i++)
{
// Id, Description (user's display), PortName (for serial connection)
comboBoxModel.addElement( new Item(i, list[i][1], list[i][0]) );
}
// To select the first item of the list. Necessary with custom Rendered
portNumberBox.setSelectedIndex(0);
}
scanState = ST_FREE;
redrawComponents();
// The connect button is enabled only after a first scan
connectButton.setEnabled(true);
}
catch(Exception ex)
{
scanState = ST_FREE;
redrawComponents();
}
}
}
public class UARTConnection {
public UARTConnection()
{
}
public String[][] listPorts() throws Exception
{
Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
Enumeration<CommPortIdentifier> tmpPortEnum = portEnum;
ArrayList<String[]> list = new ArrayList<String[]>();
int i = 0;
while ( portEnum.hasMoreElements() )
{
String port[] = new String[2];
CommPortIdentifier portIdentifier = portEnum.nextElement();
System.out.println(portIdentifier.getName() + " - " + getPortTypeName(portIdentifier.getPortType()));
port[0] = portIdentifier.getName();
port[1] = portIdentifier.getName() + " - " + getPortTypeName(portIdentifier.getPortType());
list.add(port);
i++;
}
String listOfPort[][] = new String[list.size()][2];
for(i = 0; i < list.size(); i++)
{
String[] port = list.get(i);
listOfPort[i][0] = port[0];
listOfPort[i][1] = port[1];
}
return listOfPort;
}
private String getPortTypeName ( int portType )
{
switch ( portType )
{
case CommPortIdentifier.PORT_I2C:
return "I2C";
case CommPortIdentifier.PORT_PARALLEL:
return "Parallel";
case CommPortIdentifier.PORT_RAW:
return "Raw";
case CommPortIdentifier.PORT_RS485:
return "RS485";
case CommPortIdentifier.PORT_SERIAL:
return "Serial";
default:
return "unknown type";
}
}
}
Thank you for your help.
I found the solution, for those it might help.
When running the application from Eclipse or NetBean, the app is running in 64-bit. Hence, I used the 64bit rxtxSerial.dll
. It was working properly.
But I realized when running the compiled .jar outside of the IDE, the Windows process list was displaying javaw.exe *32
for the application. For some reason I ignore, the compiled .jar was in 32bit. Hence, the driver required was for Windows 32bit, not the 64bit. It works well from now on.
Note: in order to be able to work on my MAC, I had to compile the application in Java 1.6 (not 1.7) and to provide the MAC driver of course.