Author Topic: HID Keyboard with control interface (composite device)  (Read 10226 times)

Dobaz

  • Member
  • ***
  • Posts: 23
HID Keyboard with control interface (composite device)
« on: August 27, 2012, 02:08:12 pm »
Hi all,

We developed a device for gamers. It, emulates a keyboard and we can configure the device with a control interface we also developed.
So the device is a composite device with a keyboard interface and a control interface to configure it.

Configuration example:
                               button 1 will send 'a'
                               button 2 will send 'b'
                               button 3 will send 'c'
                               button 4 will send 'd'
                               rename device
                               set new led pattern
                              etc...

It all works except one bug I still have.  When I open my control GUI and then plug the device in the usb port,  I can use the device control interface to configure the device without a problem but the device doesn't write to Note Pad. If I plug in the device and then I open my control interface, I can configure the device and the keyboard can write text to Note Pad.  

The GUI polls the port to find out if new device have been plugged in or old device plugged out using (see file attached):
  //Get the number of devices;
   Result = mUsbHidIO.GetHIDCollectionDevices( mHIDDevices, arrayDetailData, arrayAttributes, arrayValueCaps);

It seems that if the GUI is started first, it locks or swallow the port and no other process can access it. The problem doesn't come from the device,  I used a usb sniffer and it sends the right chars.

Anyone has a clue on how to solve this?

Thank you
                              

[attachment deleted by admin]
« Last Edit: August 27, 2012, 02:28:04 pm by Dobaz »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID Keyboard with control interface (composite device)
« Reply #1 on: August 27, 2012, 09:30:40 pm »
The device has two HID interfaces, a keyboard and a generic HID?

Look at/experiment with dwShareMode in CreateFile.

Dobaz

  • Member
  • ***
  • Posts: 23
Re: HID Keyboard with control interface (composite device)
« Reply #2 on: August 27, 2012, 10:07:34 pm »
Hi,

thanks for the reply.  Yes,  a keyboard and a generic HID.

Here's what I did:

AuxDeviceHandle=CreateFile (arrayDetailData->DevicePath,
               0, FILE_SHARE_READ|FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL,
               OPEN_EXISTING,    0, NULL);

I would like to explain it but not so easy here.  To resume,  I used CreateFile to be able to get information on the devices, then I closed the handle, sort devices and then I used Create File again to dig more in the interesting devices.  I removed the second Create File and did the whole job on the first call.  It solved the problem but I don't really know why, I had closed the first handle from the first CreateFile call.

Any idea?

Thank you