Author Topic: Error while reading and writing the data to USB keyboard.  (Read 44490 times)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error while reading and writing the data to USB keyboard.
« Reply #15 on: February 22, 2012, 10:31:08 am »
MY HID example code includes Feature reports:

http://www.lvr.com/hidpage.htm#MyExampleCode

The device firmware reads the report and sets the LED accordingly.

You can send any kind of data in a Feature report.

How to read data from a proximity sensor is outside the scope of this forum! I would suggest starting with the sensor's data sheet.

Jan

jain1.anuj

  • Member
  • ***
  • Posts: 28
Re: Error while reading and writing the data to USB keyboard.
« Reply #16 on: February 23, 2012, 12:06:56 am »
Thanks JAN but i didn't get any code related to LED. Can you tell me which properties i need to use for controlling the LED. By what method i can access them?

Also i saw in your HID example that GetHidUsage() method can be modified to check other usage. How can i check for LED with the help of this method ? What modifications i need to do?

NOTE:- The usage for LED is -> 0X108
« Last Edit: February 23, 2012, 01:04:03 am by jain1.anuj »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error while reading and writing the data to USB keyboard.
« Reply #17 on: February 23, 2012, 10:46:01 am »
You can add an LED usage to the report descriptor or just call it vendor defined as in my example. In either case, the device firmware will need to know what to do with the data.

The HID spec has an example keyboard report descriptor with LEDs.

Jan

jain1.anuj

  • Member
  • ***
  • Posts: 28
Re: Error while reading and writing the data to USB keyboard.
« Reply #18 on: February 24, 2012, 04:29:43 am »
Thanks JAN

I worked on it and make LED controlled by application.

But the problem is that the reports are not been saved in the device. Whenever i plug my device and search for Feature report, it says that no Feature report exists.
I need to write the Report again. As soon as device is unplugged, reports get deleted automatically.
How can i make my reports to be stored on device so that i need not to write them again and again?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error while reading and writing the data to USB keyboard.
« Reply #19 on: February 24, 2012, 10:17:39 am »
>But the problem is that the reports are not been saved in the device. Whenever i plug my device and search for Feature report, it says that no Feature report exists.

If you want the device to remember the last Feature report sent before device removal, you'll need to store the report's values in non-volatile memory in the device or resend the report on attachment.

If the values on attachment are always the same, the device firmware can initialize the LEDs to those values.

Jan


jain1.anuj

  • Member
  • ***
  • Posts: 28
Re: Error while reading and writing the data to USB keyboard.
« Reply #20 on: February 27, 2012, 12:43:44 am »
The data is not same every time. It can vary. Even the user can change the data saved in the device too. If he changes the saved values, than the altered values should get save in the device.

Moreover, i am not just concerned about the LEDs but the every piece of information that is been send to the device.

In the current scenario, the reports are not getting saved in my device if i remove it. Than how can i resend the reports on attachment ? How can i save the data in the non volatile memory of the device? Can you please throw some more light on it?

If i once Write the data to the device using HidD_SetFeature() method, doesn't it get saved on the device for future use, even if the device is been removed?

I also want to perform the Read operations when the device is been connected to the system automatically to display the values in the application which are saved previously in the device. How can i do the same?

« Last Edit: February 27, 2012, 01:39:32 am by jain1.anuj »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error while reading and writing the data to USB keyboard.
« Reply #21 on: February 28, 2012, 05:40:55 pm »
You will need to program the device firmware to save the values. If you aren't the developer of the device, you'll need to live with whatever capabilities the device has.

Jan

jain1.anuj

  • Member
  • ***
  • Posts: 28
Re: Error while reading and writing the data to USB keyboard.
« Reply #22 on: February 28, 2012, 10:36:09 pm »
I have an application which saves the data in the device even after it has been removed. But i don't have the code for it. It means device has memory to save the data.
How can i do the same? Isn't there any way to do it?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error while reading and writing the data to USB keyboard.
« Reply #23 on: February 28, 2012, 10:41:56 pm »
If you "have an application which saves the data in the device after it has been removed," why don't you use that application to save the data?

Jan

jain1.anuj

  • Member
  • ***
  • Posts: 28
Re: Error while reading and writing the data to USB keyboard.
« Reply #24 on: February 28, 2012, 11:29:10 pm »
That application is developed in c++. I need to developed it again using c#. It's what client want. So i can't used that in my new application. I don't have the code for this application. So can't use it's functionality.
It's necessary to save the data in the device.
« Last Edit: February 29, 2012, 01:08:55 am by jain1.anuj »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error while reading and writing the data to USB keyboard.
« Reply #25 on: February 29, 2012, 10:32:25 am »
If you are developing the device, you can examine the firmware to find out how it saves and uses the data from the last Feature report received.

If you aren't the developer of the device, you need some kind of documentation that shows how to do what you need to do.

A USB protocol analyzer will show the traffic that results from the application you have. From there, you could attempt to duplicate that traffic with an application you write.

Jan

jain1.anuj

  • Member
  • ***
  • Posts: 28
Re: Error while reading and writing the data to USB keyboard.
« Reply #26 on: March 01, 2012, 03:15:49 am »
I solved the problem.

I want to detect and read the data automatically as soon as device is plugged into the system. So should i call the FindTheHid() and Read() method when i get the Device Arrival message? Or is there some other way i can do it?

My device has only one LED which changes the color accordingly.

If the user is in range of device than it will show GREEN LED
If the user goes out of range from the device than it shows RED LED
There is a transition state also. When GREEN changes to RED or vice versa, it first changes to YELLOW than the appropriate color.

How can i manage there ON/OFF state.
Suppose if I OFF the GREEN LED, than there should not be any effect on other two. Same goes with all the LEDs. How can i do the same?
« Last Edit: March 01, 2012, 05:27:53 am by jain1.anuj »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error while reading and writing the data to USB keyboard.
« Reply #27 on: March 01, 2012, 09:57:09 am »
See your device's schematic and the LED's data sheet to find out how to control the LED in device firmware.

Jan

jain1.anuj

  • Member
  • ***
  • Posts: 28
Re: Error while reading and writing the data to USB keyboard.
« Reply #28 on: March 01, 2012, 11:13:21 pm »
Can you please explain it in the layman's language. I am a newbie to this kind of work.
 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error while reading and writing the data to USB keyboard.
« Reply #29 on: March 02, 2012, 10:29:41 am »
Then I would suggest starting with web searches on the terms you don't know.

Here is a group with discussions on basic electronics:

http://groups.google.com/group/sci.electronics.basics/topics?lnk

Jan