Author Topic: Device Notify Host App  (Read 24447 times)

Babu

  • Member
  • ***
  • Posts: 11
Device Notify Host App
« on: March 23, 2015, 01:38:14 pm »
I'm very new to the driver development.

I'm developing a HID device which has say only one switch. And a host application for the same device.

I can continuously poll for the state of the device using HID_GetInputReport.

Instead how can I make whenever there is a change in the device ( switch on/off ), the driver should inform my host application.

How can my host application register for the notifications?

How to make my driver to notify the host application ( like sending the notification along with the data )?

Can we use RAWINPUT mechanism in windows? Does it work only for mice,keyboard or for any device?

If you can provide some link for the sample apps it will be great.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Device Notify Host App
« Reply #1 on: March 23, 2015, 04:59:58 pm »
My HID page has example code that uses a different thread to poll for received data and notify the main application when new data is available:

http://janaxelson.com/hidpage.htm#MyExampleCode

Babu

  • Member
  • ***
  • Posts: 11
Re: Device Notify Host App
« Reply #2 on: March 24, 2015, 05:17:11 pm »
Hi Jan
Thanks for your reply.
Can you let me know which sample code should I look for? Is it generic_hid_cs_62
I would like to know how are you broadcasting the data from the device to OS which in turn can notify the host app using WM_INPUT messages.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Device Notify Host App
« Reply #3 on: March 24, 2015, 08:33:17 pm »
Yes. The device sends data in interrupt IN transfers.

In my example, cmdGetInputReportInterrupt_Click calls the async routine RequestToGetInputReport, which waits until data is available or a timeout. You don't have to use a click event to request the data. Any routine could call RequestToGetInputReport. Because RequestToGetInputReport is async, the application can do other work while waiting.

« Last Edit: March 24, 2015, 08:51:08 pm by Jan Axelson »

Babu

  • Member
  • ***
  • Posts: 11
Re: Device Notify Host App
« Reply #4 on: March 25, 2015, 10:30:39 am »
Hi Jan
Thanks for your reply.
cmdGetInputReportInterrupt_Click is the call which host initiates whenever "Get Input Report" button is clicked.

What I'm looking for is say:
1. Whenever the button in the device is toggled, how can I make the device to inform it to the host? I mean to receive the WM_INPUT message in the host, what the device firmware should do? How the device firmware has to inform the OS about there is a change in the button state.I don't want my host to poll for the report continuously and listen for the states. Whenever there is a change in the device, how the device firmware can notify the host about the changes to host.

I have registered for WM_INPUT message in my host app like
RAWINPUTDEVICE rid;
   rid.usUsagePage = 65280;
   rid.usUsage     = 1;
   rid.dwFlags     = 0;
   rid.hwndTarget  = this->GetSafeHwnd();
   BOOL bFlag = ::RegisterRawInputDevices( &rid,1,sizeof(RAWINPUTDEVICE) );
But still I'm not getting the WM_INPUT message in my host app when there is button toggle in the device.
So I would like to know to receive this message in the host, what should be done from the device side?
Am I Clear?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Device Notify Host App
« Reply #5 on: March 25, 2015, 10:48:35 am »
I don't have a raw input example. If you haven't seen it, check out:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms645546%28v=vs.85%29.aspx

Be sure RegisterRawInputDevices succeeds. (See example above.)

A protocol analyzer will show whether the data is transferring on the bus.

The low-level HID driver retrieves data continuously by polling the device's interrupt IN endpoint according to the bInterval value in the endpoint descriptors. The driver stores the retrieved data, which applications can then access.

HID_GetInputReport bypasses the HID buffer and retrieves Input reports using control transfers.

Be sure your device is also sending data in response to token packets on the interrupt IN endpoint.

Babu

  • Member
  • ***
  • Posts: 11
Re: Device Notify Host App
« Reply #6 on: March 25, 2015, 11:12:55 am »
RegisterRawInputDevices call return true. So I dont see any problem.
But I'm not getting WM_INPUT message still.
Do you mean to check whether data transfer is happening when the button is pressed using protocol analyzer?
I was looking something like whenever the mouse is registered, the host gets all the state changes [ button clicks,mouse move etc ] via WM_INPUT message.
The same thing I want to have it with my HID device.
From the host side,everything looks fine [ The only thing to do from host side is to register the device using RegisterRawInputDevices ].
Should I to do something from the device side?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Device Notify Host App
« Reply #7 on: March 25, 2015, 11:31:49 am »
You mentioned retrieving data using HID_GetInputReport. This function uses control transfers. To use raw input, I believe the data must be sent using interrupt transfers. Be sure your device is doing that.

Babu

  • Member
  • ***
  • Posts: 11
Re: Device Notify Host App
« Reply #8 on: March 25, 2015, 12:31:25 pm »
Ok I'll check.
If I'm not wrong, if the device sends the data through interrupt transfer, my host app should receive it as WM_INPUT messages.
Am I correct on this?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research

Babu

  • Member
  • ***
  • Posts: 11
Re: Device Notify Host App
« Reply #10 on: April 01, 2015, 02:24:58 pm »
When I called HidD_GetInputReport it failed and GetLastError() returned an error saying "device attached to the system is not functioning"
What could be the problem?
I'm able to use the ReadFile but not HidD_GetInputReport?
Should I check something with the end desciptors of the device?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Device Notify Host App
« Reply #11 on: April 01, 2015, 05:34:20 pm »
Does your device firmware detect and respond to the HID-class Get_Report request?

Babu

  • Member
  • ***
  • Posts: 11
Re: Device Notify Host App
« Reply #12 on: April 01, 2015, 05:38:54 pm »
I'm not very clear on your question..

Babu

  • Member
  • ***
  • Posts: 11
Re: Device Notify Host App
« Reply #13 on: April 01, 2015, 05:40:08 pm »
I dont have the firmware code with me

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Device Notify Host App
« Reply #14 on: April 01, 2015, 06:11:38 pm »
ReadFile retrieves reports received on the interrupt IN endpoint and stored in the buffer maintained by the host's HID driver.

HidD_GetInputReport bypasses the HID buffer and sends a control request with a HID-class Get Report request.

If your device doesn't support Get Report, it won't send a report in response to the request.