Hi Charles
Deep Apologies for inconvience caused due to 3 emails ! result of Desperation !
I tried with hid_set_report_idle() for input report (0x03) and also by looking
at lsusb -vv
listing of HID descriptor device will send 8 bytes for report id 0x03 but I am
getting only byte which is also some junk.
I have attached the test program , with its output and also lsusb -vvv output.
<lsusb -vvv _output>
<start
Bus 001 Device 004: ID 14d4:0000
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 Interface
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 32
idVendor 0x14d4
idProduct 0x0000
bcdDevice 1.00
iManufacturer 1 LOP
iProduct 2 COIN DISPENSER HID MACHINE.
iSerial 3 0.0.1
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 41
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 3 Human Interface Devices
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.11
bCountryCode 8
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 113
Report Descriptor: (length is 113)
Item(Global): Usage Page, data= [ 0x00 0xff ] 65280
(null)
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Main ): Collection, data= [ 0x00 ] 0
Physical
Item(Local ): Usage, data= [ 0xa7 ] 167
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x10 ] 16
Item(Global): Report ID, data= [ 0x01 ] 1
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Local ): Usage, data= [ 0xa8 ] 168
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x32 ] 50
Item(Global): Report ID, data= [ 0x03 ] 3
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Local ): Usage, data= [ 0xa9 ] 169
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x10 ] 16
Item(Global): Report ID, data= [ 0x01 ] 1
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Local ): Usage, data= [ 0xa2 ] 162
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x32 ] 50
Item(Global): Report ID, data= [ 0x02 ] 2
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Local ): Usage, data= [ 0xa3 ] 163
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x0a ] 10
Item(Global): Report ID, data= [ 0x02 ] 2
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Local ): Usage, data= [ 0xa3 ] 163
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x3a ] 58
Item(Global): Report ID, data= [ 0x04 ] 4
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Local ): Usage, data= [ 0xa4 ] 164
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x3a ] 58
Item(Global): Report ID, data= [ 0x04 ] 4
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Main ): End Collection, data=none
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type none
wMaxPacketSize 64
bInterval 32
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type none
wMaxPacketSize 64
bInterval 32
Language IDs: (length=4)
0409 English(US)
</end>
</lsusb -vv _output>
--------------------------
<test_hid source code>
<start>
#include <hid.h>
#include <stdio.h>
#include <string.h>
bool match_serial_number(struct usb_dev_handle* usbdev, void* custom, unsigned
int len)
{
bool ret;
char* buffer = (char*)malloc(len);
usb_get_string_simple(usbdev, usb_device(usbdev)->descriptor.iSerialNumber,
buffer, len);
ret = strncmp(buffer, (char*)custom, len) == 0;
free(buffer);
return ret;
}
#define RECV_PACKET_LEN 30
int main(void)
{
HIDInterface* hid;
hid_return ret;
int i = 0, j = 0 ;
unsigned char const PATHLEN = 2;
//int const PATH_IN[4] = { 0xff0000a7,0xff0000a8,0xff0000a2,0xff0000a3};
int const PATH_IN[][2] = { {0xff000001,0xff0000a7} ,
{0xff000001,0xff0000a8},
{0xff000001,0xff0000a2 },
{0xff000001,0xff0000a3}
};
int const PATH_OUT[][2] = { {0xff000001,0xff0000a9},
{0xff000001,0xff0000a3}
} ;
// fill an example packet:
char const PACKET[6] = { 0x01, 0x04, 'C', 'v', 0x05,0x00};
char packet[RECV_PACKET_LEN];
HIDInterfaceMatcher matcher = { 0x14d4, 0x0000, NULL, NULL, 0 };
hid_set_debug(HID_DEBUG_ALL);
hid_set_debug_stream(stderr);
hid_set_usb_debug(5);
ret = hid_init();
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_init failed with return code %d\n", ret);
return 1;
}
hid = hid_new_HIDInterface();
if (hid == 0) {
fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");
return 1;
}
ret = hid_force_open(hid, 0, &matcher, 3);
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_force_open failed with return code %d\n", ret);
return 1;
}
ret = hid_write_identification(stdout, hid);
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_write_identification failed with return code %d\n",
ret);
return 1;
}
ret = hid_dump_tree(stdout, hid);
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_dump_tree failed with return code %d\n", ret);
return 1;
}
ret = hid_set_output_report(hid, PATH_IN[3],PATHLEN, PACKET, 1);
if (ret != HID_RET_SUCCESS)
{
fprintf(stderr, "hid_set_output_report failed with return code %d\n",
ret);
}
fprintf(stderr,"READ DATAA \n\n");
hid_set_idle(hid,240,0x01);
hid_set_idle(hid,240,0x03);
ret = hid_get_input_report(hid, PATH_OUT[1], 2, packet, 8);
if (ret != HID_RET_SUCCESS)
fprintf(stderr, "get_input_report failed\n");
else
fprintf(stderr, "get_input_report SUCCESS ::%c::\n", packet[0]);
ret = hid_close(hid);
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_close failed with return code %d\n", ret);
return 1;
}
hid_delete_HIDInterface(&hid);
ret = hid_cleanup();
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_cleanup failed with return code %d\n", ret);
return 1;
}
return 0;
}
</end>
</test_hid source code>
-------------------------------------
<test_hid _output>
<start>
usb_set_debug: Setting debugging level to 5 (on)
NOTICE: hid_init(): libhid 0.2.15+20060325.0.0 is being initialized.
TRACE: hid_init(): initialising USB subsystem...
usb_os_init: Found USB VFS at /proc/bus/usb
TRACE: hid_init(): scanning for USB busses...
usb_os_find_busses: Skipping non bus directory devices
usb_os_find_busses: Skipping non bus directory drivers
usb_os_find_busses: Found 002
usb_os_find_busses: Found 001
TRACE: hid_init(): scanning for USB devices...
usb_os_find_devices: Found 001 on 002
usb_os_find_devices: Found 001 on 001
usb_os_find_devices: Found 004 on 001
skipped 1 class/vendor specific interface descriptors
NOTICE: hid_init(): successfully initialised HID library.
TRACE: hid_new_HIDInterface(): creating a new HIDInterface instance...
HID FORCE OPEN CALLED
HID FORCE OPEN CALLED
HID FORCE OPEN CALLED
HID FORCE OPEN CALLED
forcefully opening a device interface according to matching
criteria...acquiring handle for a USB device...enumerating USB
busses...enumerating USB devices on bus 002...inspecting USB device
002/001[0]...Check that you have permissions to write to 002/001 and, if you
don't, that you set up hotplug (http://linux-hotplug.sourceforge.net/)
correctly.
USB error: could not claim interface 0: Device or resource busy
comparing match specifications to USB device...inspecting vendor ID...
TRY on vendor ID: 0x0000. == 0x14d4.
no match on vendor ID.inspecting product ID...match on product ID: 0x0000. ==
0x0000
match on product ID: 0x0000.no custom matching function supplied.vendor 0x0000
of USB device 002/001[0] does not match 0x14d4.enumerating USB devices on bus
001...inspecting USB device 001/001[0]...Check that you have permissions to
write to 001/001 and, if you don't, that you set up hotplug
(http://linux-hotplug.sourceforge.net/) correctly.
USB error: could not claim interface 0: Device or resource busy
comparing match specifications to USB device...inspecting vendor ID...
TRY on vendor ID: 0x0000. == 0x14d4.
no match on vendor ID.inspecting product ID...match on product ID: 0x0000. ==
0x0000
match on product ID: 0x0000.no custom matching function supplied.vendor 0x0000
of USB device 001/001[0] does not match 0x14d4.inspecting USB device
001/004[0]...comparing match specifications to USB device...inspecting vendor
ID...
TRY on vendor ID: 0x14d4. == 0x14d4.
match on vendor ID: 0x14d4.inspecting product ID...match on product ID: 0x0000.
== 0x0000
match on product ID: 0x0000.no custom matching function supplied.found a
matching USB device 001/004[0].claiming USB device 001/004[0].successfully
claimed USB device 001/004[0]. TRACE: hid_init_parser(): initialising the HID
parser for USB Device 001/004[0]...
TRACE: hid_init_parser(): allocating space for HIDData structure...
TRACE: hid_init_parser(): successfully allocated memory for HIDData strcture.
TRACE: hid_init_parser(): allocating space for HIDParser structure...
TRACE: hid_init_parser(): successfully allocated memory for HIDParser
strcture.
NOTICE: hid_init_parser(): successfully initialised the HID parser for USB
Device 001/004[0].
TRACE: hid_prepare_hid_descriptor(): initialising the HID descriptor for USB
device 001/004[0]...
TRACE: hid_prepare_hid_descriptor(): retrieving HID descriptor for USB device
001/004[0]...
NOTICE: hid_prepare_hid_descriptor(): successfully initialised HID descriptor
for USB device 001/004[0] (113 bytes).
TRACE: hid_prepare_report_descriptor(): initialising the report descriptor
for USB device 001/004[0]...
TRACE: hid_prepare_report_descriptor(): retrieving report descriptor for USB
device 001/004[0]...
NOTICE: hid_prepare_report_descriptor(): successfully initialised report
descriptor for USB device 001/004[0].
TRACE: hid_prepare_parser(): setting up the HID parser for USB device
001/004[0]...
TRACE: hid_reset_parser(): resetting the HID parser for USB device
001/004[0]...
TRACE: hid_prepare_parser(): dumping the raw report descriptor
TRACE: hid_prepare_parser(): 0x000: 0x06 0x00 0xff 0x09 0x01 0xa1 0x00 0x09
TRACE: hid_prepare_parser(): 0x008: 0xa7 0x15 0x00 0x26 0xff 0x00 0x75 0x08
TRACE: hid_prepare_parser(): 0x010: 0x95 0x10 0x85 0x01 0x81 0x02 0x09 0xa8
TRACE: hid_prepare_parser(): 0x018: 0x15 0x00 0x26 0xff 0x00 0x75 0x08 0x95
TRACE: hid_prepare_parser(): 0x020: 0x32 0x85 0x03 0x81 0x02 0x09 0xa9 0x15
TRACE: hid_prepare_parser(): 0x028: 0x00 0x26 0xff 0x00 0x75 0x08 0x95 0x10
TRACE: hid_prepare_parser(): 0x030: 0x85 0x01 0x91 0x02 0x09 0xa2 0x15 0x00
TRACE: hid_prepare_parser(): 0x038: 0x26 0xff 0x00 0x75 0x08 0x95 0x32 0x85
TRACE: hid_prepare_parser(): 0x040: 0x02 0x81 0x02 0x09 0xa3 0x15 0x00 0x26
TRACE: hid_prepare_parser(): 0x048: 0xff 0x00 0x75 0x08 0x95 0x0a 0x85 0x02
TRACE: hid_prepare_parser(): 0x050: 0x91 0x02 0x09 0xa3 0x15 0x00 0x26 0xff
TRACE: hid_prepare_parser(): 0x058: 0x00 0x75 0x08 0x95 0x3a 0x85 0x04 0x81
TRACE: hid_prepare_parser(): 0x060: 0x02 0x09 0xa4 0x15 0x00 0x26 0xff 0x00
TRACE: hid_prepare_parser(): 0x068: 0x75 0x08 0x95 0x3a 0x85 0x04 0x91 0x02
TRACE: hid_prepare_parser(): 0x070: 0xc0
TRACE: hid_prepare_parser(): parsing the HID tree of USB device 001/004[0]...
NOTICE: hid_prepare_parser(): successfully set up the HID parser for USB
device 001/004[0].
successfully opened USB device 001/004[0]. TRACE: hid_reset_parser():
resetting the HID parser for USB device 001/004[0]...
TRACE: hid_dump_tree(): iterating the parse tree for USB device 001/004[0]...
TRACE: hid_reset_parser(): resetting the HID parser for USB device
001/004[0]...
looking up report ID... TRACE: hid_prepare_parse_path(): preparing search path
of depth 2 for parse tree of USB device 001/004[0]...
TRACE: hid_prepare_parse_path(): search path prepared for parse tree of USB
device 001/004[0].
NOTICE: hid_find_object(): found requested item.
sending report ID 0x02 (length: 1) to USB device 001/004[0]... NOTICE:
hid_set_output_report(): successfully sent report to USB device 001/004[0].
READ DATAA
looking up report ID... TRACE: hid_prepare_parse_path(): preparing search path
of depth 2 for parse tree of USB device 001/004[0]...
TRACE: hid_prepare_parse_path(): search path prepared for parse tree of USB
device 001/004[0].
NOTICE: hid_find_object(): found requested item.
retrieving report ID 0x03 (length: 8) from USB device 001/004[0]...
LEN1 RETRIEVE report from USB device 1 failed to retrieve complete report from
USB device 001/004[0]; requested: 8 bytes, got: 1 bytes.get_input_report failed
closing USB device 001/004[0]...closing handle of USB device
001/004[0]...successfully closed USB device 001/004[0]. TRACE:
hid_reset_parser(): resetting the HID parser for USB device 001/004[0]...
freeing memory allocated for HID parser...resetting HIDInterface... NOTICE:
hid_cleanup(): successfully deinitialised HID library.
</end>
</test_hid _output>
Thanks in advance for help !
Regards
Himanshu
--- [EMAIL PROTECTED] wrote:
From: Charles Lepple <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED], "[email protected] list"
<[email protected]>
Subject: Re: HELP !! Gettting data from usb device using libhid
Date: Fri, 8 Sep 2006 08:34:54 -0400
On Sep 8, 2006, at 7:05 AM, Himanshu Bafna wrote:
> I have tried with hid_input_read_report() as well but it does not
> give me any
> output.
You may need to use the hid_set_idle() function before using
hid_interrupt_read(). Also, it is important to request the same
number of bytes that the device is expecting to send (this can be
determined from the HID descriptor).
The new mailing list is now at lists.alioth.debian.org, so I would
suggest subscribing to that one (as indicated on the libhid web page)
and continuing the discussion there (cc'd).
Also, emailing me at three different email addresses will not make me
answer three times as fast.
--
Charles Lepple
[EMAIL PROTECTED]
_______________________________________________
libhid-discuss mailing list
[email protected]
https://ailab.ch/mailman/listinfo/libhid-discuss
_____________________________________________________________
Get your free web-based e-mail account from http://www.Math.net
Your online tourguide of Mathematics, with books, links, news,
message boards, and much more!_______________________________________________
libhid-discuss mailing list
[email protected]
https://ailab.ch/mailman/listinfo/libhid-discuss