我對Windows 7的64位。我寫了一個小應用程序,它使用RXTX
通過串口進行通信。我在Windows 64位上使用了rxtxSerial.dll
,在Eclispe和NetBeans上都能很好地工作。爪哇 - 部署RXTX
在項目的根,我把RXTXComm.jar
和rxtxSerial.dll.
,當我要部署的應用程序出現問題。我在Eclipse上使用了Export函數,或者我從NetBeans訪問了bin /文件夾。我再次RXTXComm.jar
和rxtxSerial.dll
放置在文件夾的根目錄,但是當我執行Application.jar,RXTX
似乎並不工作。掃描似乎一直停留,而不應該持續一秒以上。
[對不起,我「至少需要10聲譽發表圖片。」]
我嘗試了所有我發現在互聯網上的建議:
- 安裝在該DLL和RXTXComm.jar JRE文件夾
- 放置在DLL文件夾WINDOWS32
- 試圖從Eclipse的
我必須缺少一些東西。有沒有人已經成功地爲Windows 32/64bit和MAC部署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";
}
}
}
謝謝您的幫助。