简体   繁体   English

如何使用usb4java读取和写入我的USB设备数据

[英]how to read & write my usb device data using usb4java

I want to read and write sandisk usb data using usb4java lib in java. 我想使用Java中的usb4java lib读写Sandisk USB数据。

i can get usb device list. 我可以获得USB设备列表。

but i don't know how to read my usb data. 但我不知道如何读取我的USB数据。

This is my dump usblist code. 这是我的转储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);
}

And this code print out all usb device. 并且此代码打印出所有USB设备。

But i want to check my sandisk device once. 但是我想检查一下我的sandisk设备。

How to change my code? 如何更改我的代码?

think u have to sniff OS requests during writing and reading data using kernel usb driver. 认为您在使用内核USB驱动程序写入和读取数据时必须嗅探OS请求。 and after that u should to send the same requests to your device. 之后,您应该将相同的请求发送到您的设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM