Daniel Yount | 14 Nov 11:46
Picon
Favicon

USB libhid is writing to PIC but errors out reading from it.

Using Linux 3.x kernel and debian 6.0 stable distro.

USB flash program 1.3
http://code.google.com/p/mphidflash/

libhid 0.2.16

I have installed a Generic HID bootloader  and a basic p18F2455 circuit setup for reading and writing USB data.
20mhz crystal no LEDs one jumper for bootloader mode and a switch for reset., nothing special. 

When I plug it in and use the "dmesg" commandline program I get.

[19195.480407] usb 1-1.2: reset full speed USB device number 6 using ehci_hcd
[19238.616399] usb 1-1.4: new full speed USB device number 50 using ehci_hcd
[19238.711891] usb 1-1.4: New USB device found, idVendor=2233, idProduct=7001
[19238.711900] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[19238.711907] usb 1-1.4: Product: Generic HID
[19238.711912] usb 1-1.4: Manufacturer: Test
[19238.714576] generic-usb 0003:2233:7001.000F: hiddev0,hidraw3: USB HID v1.11 Device [Test Generic HID] on usb-0000:00:13.5-1.4/input0

I type "lsusb -v" and get.

Bus 001 Device 050: ID 2233:7001 RadioShack Corporation
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x2233 RadioShack Corporation
  idProduct          0x7001
  bcdDevice            0.01
  iManufacturer           1 Test
  iProduct                2 Generic HID
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           41
    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         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      47
          Report Descriptor: (length is 47)
            Item(Global): Usage Page, data= [ 0xa0 0xff ] 65440
                            (null)
            Item(Local ): Usage, data= [ 0x01 ] 1
                            (null)
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Local ): Usage, data= [ 0x03 ] 3
                            (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= [ 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= [ 0x04 ] 4
                            (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= [ 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= [ 0x05 ] 5
                            (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= [ 0x02 ] 2
            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
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
Device Status:     0x0000
  (Bus Powered)



Now this I had hacked around on mphidflsh to see if I could track it down.
./mphidflash -v 2233 -p 7001 -e

Turned on debugging and added some extra check points and I added data into the default buffer and added a second buffer to make sure it read it to a clean buffer. As you see the only data that is read back is one byte into the second buffer.Writing of the initial buffer gave no errors.

USB HID device found
Sending:
31 32 33 34 35 36 37 38 : 39 30 61 62 63 64 65 66 67 68 69 6a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

About To Write

Done Write

About to read into empty buffer
Done reading
Received:
31 59 00 00 00 00 00 00 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

./mphidflash Error: USB read error


Tracked the error down to this function in mphidflash. usb-linux.c

    if(HID_RET_SUCCESS != hid_interrupt_read(hid,0x81,usbBuf2,64,0))

What would cause libhid to return error on reading while writing is fine?


Daniel Yount












_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Picon
Favicon

Invitation to connect on LinkedIn

LinkedIn

Vinnicyus Gracindo requested to add you as a connection on LinkedIn:

David,

I'd like to add you to my professional network on LinkedIn.

- Vinnicyus

 
View invitation from Vinnicyus Gracindo

 

WHY MIGHT CONNECTING WITH VINNICYUS GRACINDO BE A GOOD IDEA?

People Vinnicyus Gracindo knows can discover your profile

Connecting to Vinnicyus Gracindo will attract the attention of LinkedIn users. See who's been viewing your profile.

 

© 2011, LinkedIn Corporation

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
JamesPK | 8 Sep 12:45

libhid with python: help appreciated

Hi,

Apologies for what might be a basic libhid question.

I'm running Ubuntu, and using libhid via Python to communicate with a 
HID device (and have used 'lsusb' to glean all the details of the device).

I've started out with the example code here: 
http://anonscm.debian.org/viewvc/libhid/trunk/swig/test_libhid.py .I 
added  the vendor and product ID and the example code itself worked FINE.

I then added some code to the example. From the 'snooping' on the 
communication with the device under Windows it needs a control message 
with an initialisation string to initialise the device, which I thought 
would be:

INIT_SEQ='0x20 0x00 0x08 0x01 0x00 0x00 0x00 0x00'
ret = hid_interrupt_write(hid, 0, INIT_SEQ, 8)
  if ret != HID_RET_SUCCESS:
         log_error("hid_set_output_report", ret)

But when I added the above spinet to the example and run it I get:
(ALL messages fine up to here)
---------------------
NOTICE: hid_force_open(): successfully opened USB device 006/002[0].
   TRACE: hid_reset_parser(): resetting the HID parser for USB device 
006/002[0]...
   TRACE: hid_dump_tree(): iterating the parse tree for USB device 
006/002[0]...
   TRACE: hid_reset_parser(): resetting the HID parser for USB device 
006/002[0]...
   TRACE: hid_interrupt_write(): writing interrupt report to device 
006/002[0] ...
WARNING: hid_interrupt_write(): failed to perform interrupt write to 
device 006/002[0]: error submitting URB: No such file or directory
---------------------

Any ideas/pointers would be much appreciated.

Thanks

James

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/

Xiaofan Chen | 7 Aug 12:49
Picon

Invitation to connect on LinkedIn

LinkedIn

I'd like to add you to my professional network on LinkedIn.

- Xiaofan

Xiaofan Chen
Staff Engineer at Rockwell Automation
Singapore

Confirm that you know Xiaofan

© 2011, LinkedIn Corporation

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Avishay Orpaz | 21 Jul 23:23
Picon
Favicon

Preventing HID driver attachment

Hi
I have a device that exposes two interfaces - one HID and one mass storage. I would like to know if there is a way to prevent the attachment of a HID driver in linux. Is it possible to do so while keeping the other interface ability to be attached to its standard driver?

Thanks,
Avishay
_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Info | 21 Jun 11:42
Picon

Libhid

Hello, I have to use libhid in python. I tried test_libhid, and I'm able to open and close the hid port, get the identification and parameters of the hid port.
I don't understand how to read and write packets on the port, I searched on the web other examples and documentation but I found nothing.
Can anyone help me?

Thanks


Sol Invictus srl
P.zza D. Chiesa, 13
38068 - Rovereto (TN)
web-site: http://www.solinvictus.it
Please consider the consequences for our environment before printing this
e-mail.
_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/

Trying to get reports from hid device - unsuccessful

Hello,

I have some questions and cannot find answers. Hope that you will be 
able to help.

I have a USB scale which appears as HID device. On plugin it claimed by 
hidraw driver and appears as /dev/hidraw4 . Scales repeatedly send 6 
bytes blocks containing current status. I would like to read these 6 
bytes, decode them and then feed relevant representation to /dev/uinput 
so it would act similar to barcode scanners which act as keyboards. So I 
am going to make a daemon which will do it. However something tells me 
that most appropriate way to access HID will be libhid instead of 
hidraw. I tried to use it and run into problems and need some guidance.

1. As I understand libhid does not support asynchronous transfer? ie I 
cannot register a callback function which will be triggered each time as 
data appears on interface?
2. I have compiled test_libhid.c and I can detach the device from hidraw 
and can dump its tree:

TRACE: hid_dump_tree(): iterating the parse tree for USB device 
003/005[0]...
parse tree of HIDInterface 003/005[0]:
   path: 0x008d0020.0x008d0030.0x008d0027.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x008d0050.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0032.0x008d0070.0x00000000; type: 0x80
   path: 0x008d0020.0x008d0032.0x008d0050.0x00000000; type: 0x80
   path: 0x008d0020.0x008d0032.0x008d0041; type: 0x80
   path: 0x008d0020.0x008d0032.0x008d0040; type: 0x80
   path: 0x008d0020.0x008d0031.0x008d0080; type: 0x90
   path: 0x008d0020.0x008d0031.0x008d0081; type: 0x90
   path: 0x008d0020.0x008d0031.0x00000000; type: 0x90
   path: 0x008d0020.0x008d003a.0x008d00ff; type: 0x90
   path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
   path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
   path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
   path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
   path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
   path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
   path: 0x008d0020.0x008d0030.0x008d0040; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
   path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0

As I understand I need to read reports from path of type 0x80. So I do:

   unsigned char const PATHLEN = 4;
   int const PATH_OUT[4] = { 0x008d0020, 0x008d0032, 0x008d0070, 
0x00000000 };

   unsigned char const RECV_PACKET_LEN = 6;
   char packet[RECV_PACKET_LEN];
   ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, packet, 
RECV_PACKET_LEN);
   if (ret != HID_RET_SUCCESS) {
     fprintf(stderr, "hid_get_input_report failed with return code 
%d\n", ret);
   }

and it comes back with

   TRACE: hid_get_input_report(): looking up report ID...
   TRACE: hid_prepare_parse_path(): preparing search path of depth 4 for 
parse tree of USB device 003/005[0]...
   TRACE: hid_prepare_parse_path(): search path prepared for parse tree 
of USB device 003/005[0].
  NOTICE: hid_find_object(): found requested item.
   TRACE: hid_get_input_report(): retrieving report ID 0x03 (length: 6) 
from USB device 003/005[0]...
WARNING: hid_get_input_report(): failed to retrieve report from USB 
device 003/005[0]:error sending control message: Broken pipe.
hid_get_input_report failed with return code 20

And it is the same for all paths of type 0x80. What I do wrong? Perhaps 
answer is simple but I have tried everything and cannot get scales to 
report as expected.

Regards,
Vladimir

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/

Günther Sohler | 26 Apr 09:52

Strange behaviour of LIBHID in Linux


Hello Group,

As I am a HID beginner, please excuse myself if I do absolutely stupid things and rather help me :)


I have  built a LIBHID Hardware device and I'd like to send and receive reports from it.
It generally works but its quite circular and definitely not the way as it should be.

to send reports, I do:

ret = hid_set_output_report(handle[ind], locptr, loclen, temp, buflen);
...
ret = hid_interrupt_read(handle[ind], 0x01, temp, buflen, 1000); // sync write

even tough the second command returns an error- without it the information is not transmitted

to receive reports, I do

ret = hid_interrupt_read(handle[ind], 0x01, temp, buflen, 1000); // sync read
...
ret = hid_get_input_report(handle[ind], locptr, loclen, temp, buflen);

without the "sync read" line, hid_get_input_report does not deliver up-to-date data

I'd like to get rid of the the "sync" lines but It does not work without.
Can anybody tell me, whats wrong ?

===
My HID Slave device has only one Interrupt IN Endpoint. Is this correct ?This is an template example from a HID Keyboard,
which can send(led indicators) and receive(key buttons) data.
This is the code which creates the usb config descriptor:

const hcc_u8 config_descriptor[] = {
       USB_FILL_CFG_DESC(9+3+9+9+7, 1, 1, 4, CFGD_ATTR_SELF_PWR, 0),
        USB_FILL_OTG_DESC(1, 1),
        USB_FILL_IFC_DESC(CUSTOM_IFC_INDEX, 0, 1, 0x3, 0x0, 0x0, 5), /* HID, none, none */
        USB_FILL_HID_DESC(9, 0x0100, 0x0, 1, 0x22, sizeof(report_descriptor)),
        USB_FILL_EP_DESC(0x1, 1, 0x3, 8, 0x20),
};

my report descriptor looks like

const hcc_u8 report_descriptor[39] = {
        0x06, 0x02,0xff,                /* USAGE_PAGE  */
        0x09, 0x01,                    /* USAGE  */
        0xa1, 0x01,                    /* COLLECTION  */
       
        0x06, 0x02,0xff,                /* USAGE_PAGE  */
        0x09, 0x01,                    /*   USAGE  */

        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
        0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
        0x75, 0x01,                    //   REPORT_SIZE (1)
        0x95, 0x08,                    //   REPORT_COUNT (8)
        0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)


        0x05, 0x02,                    /*     USAGE_PAGE  */
        0x19, 0x01,                    /*     USAGE_MINIMUM (Sensor 1) */
        0x29, 0x08,                    /*     USAGE_MAXIMUM (Sensor 8) */
        0x15, 0x00,                    /*     LOGICAL_MINIMUM (0) */
        0x25, 0xFF,                    /*     LOGICAL_MAXIMUM (255) */
       
        0x95, 0x08,                    /*     REPORT_SIZE (8) */
        0x75, 0x08,                    /*     REPORT_COUNT (8) */
        0x81, 0x02,                    /*     INPUT (Data,Var,Rel) */
       
        0xc0                           /* END_COLLECTION */
};

Any Hints are appreciated

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Rudolf Muehlbauer | 12 Apr 20:53
Picon

Re: libhid-discuss Digest, Vol 53, Issue 4


> > Receiving strings is still somewhat strange, only the first
> > character is received.
> 
> If your device is not actually a human interface device and you have
> some control over the firmware I very strongly recommend not using
> the HID device class. If no class fits then vendor specific is an
> excellent choice; it allows you complete freedom in how communication
> works, and it can take advantage of the packet based nature of USB
> communication. Reading a string could be as simple as giving a string
> number and receiving the string bytes.
> 
> 
> //Peter
> 

No control over the firmware. The problem with the strings was in my
Mono P/Invoke code, a little misunderstanding with Mr. Marshal and
string encodings, fixed. 

Well of course a vendor-specific device would be very beneficial. I
remember a small project I did once: ATMega with software-only USB
(http://www.obdev.at/products/vusb/index.html) and some lines of kernel
code or libusb - voilà!

--

-- 
Rudolf Muehlbauer <rudolf.muehlbauer <at> gmail.com>
_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Rudolf Muehlbauer | 8 Apr 19:25
Picon

libhid + swig -> c#

Hello, 

I am wondering what the current status of libhid is. Is it still
maintained, used? The last svn commit was back in 2008.

I am interested to use it in a project written with Mono/C#. Is it much
of a hassle to generate the C# bindings?

Is there a more vivid alternative to libhid?

Any hints appreciated.

--

-- 
Rudolf Muehlbauer <rudolf.muehlbauer <at> gmail.com>
_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Jacques Dirac | 31 Mar 13:27
Picon

Missing reports in hid_interrupt_read()

Hi,

My program reads reports from a device using the hid_interrupt_read()
function, but when reports follow each other quickly, they could get
lost (not returned by hid_interrupt_read()).

With help of the developer of the device we could get some information
about what is going on in the device:
- the device has a queue for the IN-reports, so a report is not lost
in the device
- in each report there is a value that counts how many times the
device has placed a report in the IN-report-buffer
- in each report there is a value that contains the time that the last
IN-report waited in the register to be fetched by the host

With this information we see that:
- the device puts all messages in the IN-report-buffer, but not all
messages could be fetched with hid_interrupt_read()
- a lost message is fetched (by something) in <10ms (this is the same
time as the other messages)

Then my questions are:
- Is there some routine in libhid (or libusb) that is fetching the
reports from the IN-report-buffer of the device and saves them in a
'buffer' where hid_interrupt_read() is reading from? In my case it
looks like that buffer is overwritten.
- If so, can this be disabled or influenced?
- If not, what else can be going on here?

Hope someone can help to clear things up.

Best regards.

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/


Gmane