LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-24-2011, 01:23 AM   #1
zyroot998
LQ Newbie
 
Registered: Feb 2011
Location: China
Posts: 17

Rep: Reputation: 0
In linux platform how to use ioctl function to read/write data to hid device


Dear all:
Now i have a problem.I want to used a hid usb device under linux 2.6.11.But i can't know how to used ioctl function to send and receive data to a hid device.
Please help me.Give me some demo or code could be better.Thanks a lot.
 
Old 06-24-2011, 07:30 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,037

Rep: Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756
Without knowing what you have, Google may be you friend here; try searching for
Code:
hid device ioctl example your_device_name
That will turn up quite a few references.

Hope this helps some.

Last edited by tronayne; 06-24-2011 at 07:31 AM.
 
Old 06-28-2011, 10:03 PM   #3
zyroot998
LQ Newbie
 
Registered: Feb 2011
Location: China
Posts: 17

Original Poster
Rep: Reputation: 0
In linux kernel 2.6.11.1 how to used ioctl to send multi data,and receive data from hid device?
 
Old 06-28-2011, 10:06 PM   #4
zyroot998
LQ Newbie
 
Registered: Feb 2011
Location: China
Posts: 17

Original Poster
Rep: Reputation: 0
i used follow code to send data to hid device:
for ( i = 0; i < uiSendDataLen+3; i++ ){
out_uref.usage_index = i;
out_uref.value = bTmp[i];
ioctl(fd, HIDIOCGUCODE, &out_uref);
ret = ioctl(fd, HIDIOCSUSAGE, &out_uref);
if ( ret < 0 ){
return -2;
}
}
// tell the driver about the usage values
out_report.report_type = HID_REPORT_TYPE_OUTPUT;
out_report.report_id = HID_REPORT_ID_FIRST;
// this ioctl puts the report on the wire
ret = ioctl(fd, HIDIOCSREPORT, &out_report);
if ( ret < 0 ){
return -4;
}


and follow source to receive data from hid device:
in_report.report_type = HID_REPORT_TYPE_INPUT;
in_report.report_id = HID_REPORT_ID_FIRST;
// this ioctl gets the report on the wire
ret = ioctl(fd, HIDIOCGREPORT, &in_report);
if ( ret < 0 ){
return -6;
}
in_uref.report_type = HID_REPORT_TYPE_INPUT;
in_uref.report_id = HID_REPORT_ID_FIRST;
in_uref.field_index = 0;
in_uref.usage_index = 0;
// fist read 3 bytes,2 is the len
memset( bResp, 0x00, 4096);
for ( i = 0; i < 3; i++ ){
in_uref.usage_index = i;
ioctl(fd, HIDIOCGUCODE, &in_uref);
ret = ioctl(fd, HIDIOCGUSAGE, &in_uref);
usleep(1);
if ( ret < 0 ){
return -7;
}
bResp[i] = in_uref.value;
}

but, i can't receive all the data.In 2.6.11.1,must send data each byte by each byte,receive is the same,byte by byte.But receive data not integrity.What's the problem?????????
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Problem with ioctl function when openning TUN/TAP device on Linux. shmilt24 Linux - Newbie 2 09-10-2010 02:14 AM
Read/write to/from USB HID devices jimspruell Linux - Newbie 0 05-04-2009 10:18 AM
how to send datas to HID device?why I can only send two bytes data to HID device? wch_zj Linux - Software 1 01-05-2006 07:14 AM
why I can only send two bytes data to HID device? wch_zj Programming 0 01-05-2006 12:04 AM


All times are GMT -5. The time now is 01:05 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration