我在Windows七号64位。我编写了一个小应用程序,它使用RXTX通过串口进行通信。我使用了rxtxSerial.dll for Windows 64位,它在Eclispe和NetBeans上都运行得很好。
在项目的根目录下,我将RXTXComm.jar和rxtxSerial.dll.放在
当我想部署应用程序时会出现问题。我在Eclipse上使用了导出函数,或者从NetBeans访问bin/文件夹。我再次将RXTXComm.jar和rxtxSerial.dll放在文件夹的根部,但是当我执行Application.jar时,RXTX似乎无法工作。扫描似乎被卡住了,而它不能持续超过一秒钟。
对不起,我“至少需要10个声誉来发布图片。”
我尝试了我在网上找到的所有建议:
我一定是漏掉了什么。是否有人已经成功地将RXTX部署到Windows32/64位和MAC?你能描述一下你做了什么,需要做什么吗?
在扫描端口时,请在下面找到正在执行的代码:
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";
}
}
}谢谢你的帮助。
发布于 2013-07-03 07:23:04
我找到了解决办法,对那些可能有帮助的人。
当从Eclipse或NetBean运行应用程序时,应用程序在64位内运行。因此,我使用了64位rxtxSerial.dll。它运转正常。
但是我意识到在IDE外部运行编译的.jar时,Windows列表显示了应用程序的javaw.exe *32。由于某些原因,我忽略了编译后的.jar为32位。因此,所需的驱动程序是Windows 32位,而不是64位。从现在起一切都很顺利。
注意:为了能够在我的MAC上工作,我必须用Java1.6(而不是1.7)编译应用程序,当然还要提供MAC驱动程序。
https://stackoverflow.com/questions/17319254
复制相似问题