LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-04-2006, 02:36 PM   #1
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Rep: Reputation: 16
Problems with USB HID Reports


To read data from USB HID device I use the following code:
Code:
struct hiddev_report_info rinfo;
struct hiddev_field_info finfo;
struct hiddev_usage_ref uref;
int i, j, ret, count;
while (1){
	rinfo.report_type = HID_REPORT_TYPE_INPUT;
	rinfo.report_id = HID_REPORT_ID_FIRST;
	ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);

	// Get Reports
	while (ret >= 0&&rinfo.num_fields>0&&rinfo.num_fields<64){

		// Get Fields
		for (i = 0; i < rinfo.num_fields; i++){
			finfo.report_type = rinfo.report_type;
			finfo.report_id   = rinfo.report_id;
			finfo.field_index = i;
			ioctl(fd, HIDIOCGFIELDINFO, &finfo);


			// Get usages
			for (j = 0; j < count+1; j++){
				uref.report_type = finfo.report_type;
				uref.report_id   = finfo.report_id;
				uref.field_index = i;
				uref.usage_index = j;
				ioctl(fd, HIDIOCGUCODE, &uref);
				ioctl(fd, HIDIOCGUSAGE, &uref);

				printf("0x%X ",uref.value);

				// First output usage: grab it.
				if(uref.report_type == HID_REPORT_TYPE_OUTPUT && j==0) {
					memcpy(&uref_out, &uref, sizeof(uref));
				}

			}
			for (; j < finfo.maxusage; j++){
				uref.report_type = finfo.report_type;
				uref.report_id   = finfo.report_id;
				uref.field_index = i;
				uref.usage_index = j;
				ioctl(fd, HIDIOCGUCODE, &uref);
				ioctl(fd, HIDIOCGUSAGE, &uref);
			}
		}
		printf("\n");

		rinfo.report_id = HID_REPORT_ID_NEXT;
		ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
		
	}
	usleep(1000000);
}
}
As a result, I receive only the last report from series report.

If I use
Code:
ret = ioctl(fd, HIDIOCGREPORT &rinfo);
instead of
Code:
ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
than nothing readable is received at all.

Any attempt to use smth else instead of
Code:
rinfo.report_id = HID_REPORT_ID_FIRST;
don't lead to any result.

The device receives Reports without any problems. Reports are sent with
Code:
ret = ioctl(fd, HIDIOSGREPORT &rinfo);
Could you please advice what could be wrong?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Talking to USB-HID ectech Programming 1 10-24-2005 06:24 AM
USB hid.o hijacking my USB Printer Relativity Linux - Hardware 0 12-09-2003 08:56 PM
USB mouse, keyboard, hid, console mouse problems jqcaducifer Linux - General 1 08-05-2003 09:43 AM
Usb-hid RanmaPhreak79 Linux - Hardware 1 07-18-2003 08:32 PM
Usb + Hid vexer Slackware 4 05-28-2003 09:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration