Java-部署RXTX
我使用的是64位Windows 7。我编写了一个小应用程序,它使用Java-部署RXTX,java,deployment,rxtx,Java,Deployment,Rxtx,我使用的是64位Windows 7。我编写了一个小应用程序,它使用RXTX通过串口进行通信。我使用了适用于64位Windows的rxtxSerial.dll,它在Eclispe和NetBeans上都运行良好 在项目的根目录下,我放置了RXTXComm.jar和rxtxSerial.dll。 当我想要部署应用程序时,问题出现了。我在Eclipse上使用了导出功能,或者从NetBeans访问了bin/文件夹。我再次将RXTXComm.jar和rxtxSerial.dll放在文件夹的根目录下,但当我执
RXTX
通过串口进行通信。我使用了适用于64位Windows的rxtxSerial.dll
,它在Eclispe和NetBeans上都运行良好
在项目的根目录下,我放置了RXTXComm.jar
和rxtxSerial.dll。
当我想要部署应用程序时,问题出现了。我在Eclipse上使用了导出功能,或者从NetBeans访问了bin/文件夹。我再次将RXTXComm.jar
和rxtxSerial.dll
放在文件夹的根目录下,但当我执行Application.jar时,RXTX
似乎不起作用。扫描似乎停留不动,但不会持续超过一秒钟
[抱歉,我“需要至少10个声誉才能发布图片。”]
我尝试了在互联网上找到的所有建议:
- 在JRE文件夹中安装DLL和RXTXComm.jar
- 将DLL放置在Windows32文件夹中
- 尝试了从Eclipse导出的所有不同导出选项
RXTX
?你能描述一下你做了什么,需要做什么吗
请在下面找到扫描端口时执行的代码:
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";
}
}
}
private void扫描按钮操作()
{
如果(扫描状态==ST_自由)
{
扫描状态=ST_扫描;
重绘组件();
扫描=新线程(新扫描端口());
scan.start();
}
}
//运行线程扫描端口
私有类ScanPorts实现可运行{
公开募捐
{
尝试
{
UARTConnection连接=新的UARTConnection();
//listPort()是一个长阻塞调用
String[][]list=connection.listPorts();
//在组合框中显示端口
comboBoxModel.removeAllElements();
if(list.length==0)comboBoxModel.addElement(新项(-1,“未扫描端口”);
其他的
{
for(int i=0;i
谢谢你的帮助。我找到了解决方案,对那些可能有帮助的人来说 从Eclipse或NetBean运行应用程序时,应用程序以64位运行。因此,我使用了64位的
rxtxSerial.dll
。它工作正常
但我意识到,在IDE之外运行编译后的.jar时,Windows进程列表显示应用程序的javaw.exe*32
。出于某种原因,我忽略了编译后的.jar是32位的。因此,Windows 32位所需的驱动程序,而不是64位。从现在起,它运行良好
注意:为了能够在我的MAC上工作,我必须用Java1.6(不是1.7)编译应用程序,当然还要提供MAC驱动程序