私の英語は英語ですが、私の主要言語ではありません。Javaを使用してプラグインされた単一のUSBデバイスの詳細を見つける
私は現在学生です - 率直で、私は自分のプロジェクトで仕事をしようとしています。
使用する言語はJAVAで、IDEはEclipseです。
現在私はhttp://usb4java.org/からダウンロードした私のプロジェクトにLIBUSBを使用しました。それはかなり役に立つと私は私のデバイスの詳細のリストを取得することができました。 私の問題は...私はちょうどデバイス004のための識別したいと言ってみましょう。 これに関する提案はありますか? ?私はそれを2回スキャンし、出力を比較しようとしましたが、指定されたデータ型が一致しないために失敗しました。最初は私はデータ型がarraylistかもしれないと思ったが、そうではない。私は比較を行うことができますので、テキストファイルに出力を格納する別の方法はありますか?
私はlibusbの例からオンラインで取得したコードです。
public class UsbBench {
/**
* Main method.
*
* @param args
* Command-line arguments (Ignored)
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
// Create the libusb context
Context context = new Context();
// Initialize the libusb context
int result = LibUsb.init(context);
if (result < 0)
{
throw new LibUsbException("Unable to initialize libusb", result);
}
// Read the USB device list
DeviceList list = new DeviceList();
result = LibUsb.getDeviceList(context, list);
if (result < 0)
{
throw new LibUsbException("Unable to get device list", result);
}
try
{
// Iterate over all devices and list them
for (Device device: list)
{
int address = LibUsb.getDeviceAddress(device);
int busNumber = LibUsb.getBusNumber(device);
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result < 0)
{
throw new LibUsbException(
"Unable to read device descriptor", result);
}
}
}
finally
{
// Ensure the allocated device list is freed
LibUsb.freeDeviceList(list, true);
}
// Deinitialize the libusb context
LibUsb.exit(context);
}
}
そしてそれはまた良い取り組んでいます。 OUTPUT:
Bus 002, Device 003: Vendor 1bcf, Product 2c6e
Bus 001, Device 002: Vendor 06cb, Product 2970
Bus 001, Device 003: Vendor 0461, Product 4ded
Bus 001, Device 001: Vendor 8086, Product 8c31
Bus 002, Device 001: Vendor 8086, Product 8c26
Bus 002, Device 004: Vendor 04ca, Product 300b
Bus 002, Device 005: Vendor 8087, Product 8000
だから、私の問題がある...私は単なる一例デバイス004 に対して識別には、この上の任意の提案がありたいとしましょう。 ?これはまた、私の初めてのstackoverflowです。私はあなたの専門知識を謙虚に求めています。ありがとう。ありがとう。
「デバイス002のデバイスの識別」とはどういう意味ですか?あなたはそのデバイスが物理的に何であるかを理解することを意味しますか?ベンダーと製品コードの解釈方法を尋ねていますか? [USB IDリポジトリ](http://www.linux-usb.org/usb-ids.html)を試してください –
[USB IDデータベース](http://www.the-sz.com/products/usbid/) ) –
私は何を意味しています..私は1つだけのUSBに絞り込み、すべてのリストのすべての代わりに出てくる。コードを改善して、USBデバイスの検出に柔軟に対応できるようにしようとしています。 –