Я работаю над проектом и мне нужно связаться с датчиком отпечатков пальцев (gt-511c1r) через порт usb (у меня не работает Uart). Я использую библиотеку libusb, чтобы попытаться установить связь с помощью простого кода, который прилагается.
По-видимому, все работает хорошо, пока в тот момент, когда я пытаюсь отправить данные на датчик, возникает ошибка LIBUSB_ERROR_TIMEOUT.
Я Я использую Raspberry Pi 3 с обновленной прошивкой. Я также прикрепляю вывод команды lsusb -v к устройству.
Также проверьте код на ПК с SO ubuntu, и у меня такая же проблема, тогда это будет проблема с кодом ??
Любая помощь или подсказка что может дать мне решить проблему, я буду благодарна вам. Привет
//codigo de prueba
#include <stdio.h>
#include <libusb-1.0/libusb.h>
#include <stdint.h>
#include <string.h>
/*--------------------------------------------------------------------*/
int main(int argc, char*argv[])
{
int res = 0; /* return codes from libusb functions */
libusb_device_handle* handle = 0; /* handle for USB device */
int kernelDriverDetached = 0; /* Set to 1 if kernel driver detached*/
int numBytes = 0; /* Actual bytes transferred. */
uint8_t buffer[64]; /* 64 byte transfer buffer */
int ep_out = 0x02;
int ep_in = 0x81;
/* Initialise libusb. */
res = libusb_init(0);
if (res != 0)
{
fprintf(stderr, "Error initialising libusb.\n");
return 1;
}
/* Get the first device with the matching Vendor ID and Product ID.If
* intending to allow multiple demo boards to be connected at once,you
* will need to use libusb_get_device_list() instead. Refer to the libusb
* documentation for details. */
handle = libusb_open_device_with_vid_pid(0, 0x04d9, 0x8008);
if (!handle)
{
fprintf(stderr, "Unable to open device.\n");
return 1;
}
/* Check whether a kernel driver is attached to interface #0. If so, we'll
* need to detach it.*/
if (libusb_kernel_driver_active(handle, 0))
{
res = libusb_detach_kernel_driver(handle, 0);
if (res == 0)
{
kernelDriverDetached = 1;
}
else
{
fprintf(stderr, "Error detaching kernel driver.\n");
return 1;
}
}
/* Claim interface #0. */
res = libusb_claim_interface(handle, 0);
if (res != 0)
{
fprintf(stderr, "Error claiming interface.\n");
return 1;
}
memset(buffer, 0, 12);
buffer[0] = 0x55;
buffer[1] = 0xAA;
buffer[2] = 0x01;
buffer[3] = 0x00;
buffer[4] = 0x00;
buffer[5] = 0x00;
buffer[6] = 0x00;
buffer[7] = 0x00;
buffer[8] = 0x01;
buffer[9] = 0x00;
buffer[10] = 0x01;
buffer[11] = 0x01;
res = libusb_bulk_transfer(handle, ep_out, buffer, 12, &numBytes, 100);
if (res == 0)
{
printf("%d bytes transmitted successfully.\n", numBytes);
}
else
{
fprintf(stderr, "Error during send message: %s\n",libusb_error_name(res));
}
memset(buffer, 0, 12);
res = libusb_bulk_transfer(handle, ep_in, buffer, 12, &numBytes, 100);
if (res == 0)
{
printf("%d bytes receibed successfully.\n", numBytes);
}
else
{
fprintf(stderr, "Error during receibe response:
%s\n",libusb_error_name(res));
}
/* Release interface #0. */
res = libusb_release_interface(handle, 0);
if (0 != res)
{
fprintf(stderr, "Error releasing interface.\n");
}
/* If we detached a kernel driver from interface #0 earlier, we'll now
* need to attach it again. */
if (kernelDriverDetached)
{
libusb_attach_kernel_driver(handle, 0);
}
/* Shutdown libusb. */
libusb_exit(0);
return 0;
}
а вот вывод lsusb -v
Bus 001 Device 013: ID 04d9:8008 Holtek Semiconductor, Inc.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x04d9 Holtek Semiconductor, Inc.
idProduct 0x8008
bcdDevice 1.00
iManufacturer 1 FINGER
iProduct 2 USB-MASS STORAGE
iSerial 3 000000000001
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xc0
Self Powered
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 8 Mass Storage
bInterfaceSubClass 6 SCSI
bInterfaceProtocol 80 Bulk-Only
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Device Status: 0x0001
Self Powered