2013-07-22 34 views
0

使用供應商ID和產品ID顯示所連接USB端口號碼的最佳API是什麼?如何使用java列出使用供應商ID和產品ID的已連接USB端口號碼

+0

'利用廠商ID和產品id' ..對不起? – Freak

+0

通常,每個USB設備都有供應商ID和唯一的產品ID。通過使用我們可以打開設備並開始讀取和寫入操作。 @freak – Sathiya

+0

你需要在Windows或Linux上做到這一點?嘗試[java libusb](http://libusbjava.sourceforge.net/wp/) – Freak

回答

0

您可以通過簡單的API javax.comm

import javax.comm.*; 
import java.util.Enumeration; 

public class ListPorts { 
public static void main(String args[]) { 
Enumeration ports = CommPortIdentifier.getPortIdentifiers(); 
while (ports.hasMoreElements()) { 
CommPortIdentifier port = (CommPortIdentifier)ports.nextElement(); 
String type; 
switch (port.getPortType()) { 
case CommPortIdentifier.PORT_SERIAL: 
type = "Serial"; 
break; 
default: /// Shouldn't happen 
type = "Unknown"; 
break; 
} 
System.out.println(port.getName() + ": " + type); 
} 
} 
} 

列出所有串口輸出會像

COM1: Serial 
COM2: Serial 
COM7: Serial 

編輯: 也看到Creating and using a real-time port monitoring application powered by IBM Lotus一個好博客。
同樣通過使用jusb for windowsfor linux你可以做讀寫操作,你want.you會發現一個a example here

相關問題