Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: Общие вопросы > Получение данных от USB устройств - usb4java


Автор: Tsyklop 6.6.2017, 00:08

Подскажите как реализовать или если есть, то пример реализации, получения данных от usb девайса. пробовал usb4Java, но нормальных доков не нашел - не могу понять как подключится к устройству. VendorId и ProductID получил - но оно не подключается. Получаю список устройств:

Код

Bus 002, Device 002: Vendor 09da, Product 3e79
Bus 002, Device 001: Vendor 8086, Product 3b34
Bus 002, Device 003: Vendor 0c45, Product 8603
Bus 001, Device 001: Vendor 8086, Product 3b3c
Bus 002, Device 005: Vendor 1a86, Product 7523
Bus 002, Device 006: Vendor 0ac8, Product c40a
Bus 002, Device 004: Vendor 8087, Product 0020
Bus 002, Device 006: Vendor 0ac8, Product c40a
Bus 002, Device 002: Vendor 09da, Product 3e79
Bus 001, Device 002: Vendor 8087, Product 0020
Bus 002, Device 006: Vendor 0ac8, Product c40a
Bus 002, Device 003: Vendor 0c45, Product 8603
Bus 001, Device 003: Vendor 23a9, Product ef18


Как я понял моё устройство имеет данные:
Код


Bus 002, Device 005: Vendor 1a86, Product 7523


Делаю так:

Код

// Open test device (Samsung Galaxy Nexus)
        DeviceHandle handle = LibUsb.openDeviceWithVidPid(null, VENDOR_ID,
                PRODUCT_ID);
        if (handle == null)
        {
            System.err.println("Test device not found.");
            System.exit(1);
        }

        // Claim the ADB interface
        int result = LibUsb.claimInterface(handle, INTERFACE);
        if (result != LibUsb.SUCCESS)
        {
            throw new LibUsbException("Unable to claim interface", result);
        }

        // Send ADB CONNECT message
        write(handle, CONNECT_HEADER);
        write(handle, CONNECT_BODY);

        // Receive the header of the ADB answer (Most likely an AUTH message)
        ByteBuffer header = read(handle, 24);
        header.position(12);
        int dataSize = header.asIntBuffer().get();

        // Receive the body of the ADB answer
        @SuppressWarnings("unused")
        ByteBuffer data = read(handle, dataSize);

        // Release the ADB interface
        result = LibUsb.releaseInterface(handle, INTERFACE);
        if (result != LibUsb.SUCCESS)
        {
            throw new LibUsbException("Unable to release interface", result);
        }

        // Close the device
        LibUsb.close(handle);

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


Взято с примеров разраба.

но вылазит ошибка - не подключено

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)