【问题标题】:how to read & write my usb device data using usb4java如何使用 usb4java 读写我的 USB 设备数据
【发布时间】:2015-12-02 16:00:50
【问题描述】:

我想在java中使用usb4java lib读写sandisk usb数据。

我可以获取 USB 设备列表。

但我不知道如何读取我的 USB 数据。

这是我的转储 usblist 代码。

{
    // 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);
            }
            System.out.format(
                "Bus %03d, Device %03d: Vendor %04x, Product %04x%n",
                busNumber, address, descriptor.idVendor(),
                descriptor.idProduct());
        }
    }
    finally
    {
        // Ensure the allocated device list is freed
        LibUsb.freeDeviceList(list, true);
    }

    // Deinitialize the libusb context
    LibUsb.exit(context);
}

这段代码打印出所有的 USB 设备。

但我想检查一下我的 Sandisk 设备。

如何更改我的代码?

【问题讨论】:

    标签: java usb4java


    【解决方案1】:

    认为您必须在使用内核 USB 驱动程序写入和读取数据期间嗅探操作系统请求。然后你应该向你的设备发送相同的请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多