21. januar 2012 - 11:49
Der er
17 kommentarer og
1 løsning
Hjælp til libusb_interrupt_transfer (debian)
Jeg forsøger at rette noget kode, så det understøtter min USB vægt.
Jeg har taget udgangspunkt i
https://github.com/erjiang/usbscaleVægten er en Dymo M10
Koden registrerer at der er en vægt, men giver fejlen:
libusb:error [submit_bulk_transfer] submiturb failed error -1 errno=22
Jeg har afgrænset problemet, til denne kodestump:
r = libusb_interrupt_transfer(
handle,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS,
data,
WEIGH_REPORT_SIZE, // length of data
&len,
10000 //timeout => 10 sec
);
Umiddelbart gætter jeg at r burde være 0 (som er succes-retur-værdi for andre libusb funktioner) men:
r = -1
Værdierne af variablerne, er som følger:
LIBUSB_ENDPOINT_IN = 128
LIBUSB_REQUEST_TYPE_CLASS = 32
WEIGH_REPORT_SIZE = 0x06
Jeg har aldrig brugt libusb-funktioner før, så jeg er lidt på bar bund.
Hvor kommer værdierne 128 og 32 fra?
Vægten sender tilsyneladende data over usb konstant.
Jeg kan få fat på hexkoden direkte, ved at køre denne funktion:
# hexdump -v -e '6/1 "%02x " "\n"' < /dev/hidraw4
03 02 0b ff 00 00
03 04 02 00 0a 01
03 04 02 00 38 08
03 04 02 00 f8 0a
03 04 02 00 d6 01
03 04 02 00 2a 0e
03 04 02 00 38 18
...i dette eksempel trykker jeg hårdere og hårdere på vægten.
De enkelte bytes passer med brugen i koden.
De 2 sidste bytes er vægten. (eks. sidste linjes "38 18" - konverterer man "1838" til et tal, får man "6200" som var vægten der stod, da jeg trykkede hårdest.
Jeg vil dog helst bruge libusb, til at trække dataene ud.
Nogen der kan hjælpe med det?
24. januar 2012 - 11:08
#4
lsusb, for vægten:
Bus 002 Device 003: ID 0922:8006 Dymo-CoStar Corp.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0922 Dymo-CoStar Corp.
idProduct 0x8006
bcdDevice 1.00
iManufacturer 1 DYMO
iProduct 2 M10 10 Kg Digital Postal Scale
iSerial 3 0000000001098
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 34
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 64mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.01
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 221
Report Descriptor: (length is 221)
Item(Global): Usage Page, data= [ 0x8d ] 141
Scale Page (POS)
Item(Local ): Usage, data= [ 0x20 ] 32
(null)
Item(Main ): Collection, data= [ 0x01 ] 1
Application
Item(Local ): Usage, data= [ 0x30 ] 48
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Report ID, data= [ 0x01 ] 1
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x01 ] 1
Item(Global): Logical Minimum, data= [ 0x01 ] 1
Item(Local ): Usage, data= [ 0x27 ] 39
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Logical Maximum, data= [ 0x0a ] 10
Item(Local ): Usage Minimum, data= [ 0x21 ] 33
(null)
Item(Local ): Usage Maximum, data= [ 0x2a ] 42
(null)
Item(Main ): Feature, data= [ 0x00 ] 0
Data Array Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Local ): Usage, data= [ 0x50 ] 80
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Logical Maximum, data= [ 0x0c ] 12
Item(Local ): Usage Minimum, data= [ 0x51 ] 81
(null)
Item(Local ): Usage Maximum, data= [ 0x5c ] 92
(null)
Item(Main ): Feature, data= [ 0x00 ] 0
Data Array Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Main ): End Collection, data=none
Item(Local ): Usage, data= [ 0x31 ] 49
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Report ID, data= [ 0x02 ] 2
Item(Global): Report Size, data= [ 0x01 ] 1
Item(Global): Report Count, data= [ 0x02 ] 2
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0x01 ] 1
Item(Local ): Usage, data= [ 0x81 ] 129
(null)
Item(Local ): Usage, data= [ 0x80 ] 128
(null)
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Global): Report Size, data= [ 0x06 ] 6
Item(Global): Report Count, data= [ 0x01 ] 1
Item(Main ): Output, data= [ 0x03 ] 3
Constant Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Local ): Usage, data= [ 0x32 ] 50
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Report ID, data= [ 0x03 ] 3
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Logical Minimum, data= [ 0x01 ] 1
Item(Local ): Usage, data= [ 0x70 ] 112
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Logical Maximum, data= [ 0x08 ] 8
Item(Local ): Usage Minimum, data= [ 0x71 ] 113
(null)
Item(Local ): Usage Maximum, data= [ 0x78 ] 120
(null)
Item(Main ): Input, data= [ 0x00 ] 0
Data Array Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Local ): Usage, data= [ 0x50 ] 80
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Logical Maximum, data= [ 0x0c ] 12
Item(Local ): Usage Minimum, data= [ 0x51 ] 81
(null)
Item(Local ): Usage Maximum, data= [ 0x5c ] 92
(null)
Item(Main ): Input, data= [ 0x00 ] 0
Data Array Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Global): Logical Minimum, data= [ 0x81 ] 129
Item(Global): Logical Maximum, data= [ 0x7f ] 127
Item(Local ): Usage, data= [ 0x41 ] 65
(null)
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Global): Report Size, data= [ 0x10 ] 16
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0xff 0x00 0x00 ] 65535
Item(Local ): Usage, data= [ 0x40 ] 64
(null)
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Local ): Usage, data= [ 0x34 ] 52
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Report ID, data= [ 0x05 ] 5
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x01 ] 1
Item(Local ): Usage, data= [ 0x50 ] 80
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Logical Minimum, data= [ 0x01 ] 1
Item(Global): Logical Maximum, data= [ 0x0c ] 12
Item(Local ): Usage Minimum, data= [ 0x51 ] 81
(null)
Item(Local ): Usage Maximum, data= [ 0x5c ] 92
(null)
Item(Main ): Feature, data= [ 0x00 ] 0
Data Array Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Global): Logical Minimum, data= [ 0x81 ] 129
Item(Global): Logical Maximum, data= [ 0x7f ] 127
Item(Local ): Usage, data= [ 0x41 ] 65
(null)
Item(Main ): Feature, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Global): Report Size, data= [ 0x10 ] 16
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0xff 0x00 0x00 ] 65535
Item(Local ): Usage, data= [ 0x40 ] 64
(null)
Item(Main ): Feature, data= [ 0x03 ] 3
Constant Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Local ): Usage, data= [ 0x35 ] 53
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Report ID, data= [ 0x06 ] 6
Item(Global): Report Size, data= [ 0x10 ] 16
Item(Global): Report Count, data= [ 0x02 ] 2
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0xff 0x00 0x00 ] 65535
Item(Local ): Usage, data= [ 0x60 ] 96
(null)
Item(Local ): Usage, data= [ 0x61 ] 97
(null)
Item(Main ): Feature, data= [ 0x03 ] 3
Constant Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Local ): Usage, data= [ 0x30 ] 48
(null)
Item(Main ): Collection, data= [ 0x02 ] 2
Logical
Item(Global): Report ID, data= [ 0x07 ] 7
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x0f ] 15
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0x7f ] 127
Item(Local ): Usage, data= [ 0x40 ] 64
(null)
Item(Main ): Feature, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Item(Main ): End Collection, data=none
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 200
Device Status: 0x0000
(Bus Powered)