Hello,
I have some questions about the HID driver. I've seen similar questsions posted here
and other locations but never an answer.
I am writing software to talk to a USB ups. Rather than make it a standard HID Power
Device, the manufacturer cobbled their old serial protocol into a custom HID device.
The protocol takes and returns strings of 4-8 bytes.
Under Windoze I talk to the device by calling CreateFile on the driver and then using
ReadFile and WriteFile to send and receive the strings. I append a 0 to the beginning
of the data on the Write to indicate which report to use.
On the Mac I use the HIDDispatchTable call of pHIDSetReport, passing the string as the
third parameter.
On Linux I can find no way to send a string to the device. Using some of the tools
available I have queried the device and discovered that it has one input and one
output report, each with one field of two usages. I had assumed that since the usage
value is 4 bytes that I would need to munge my string into the two usages and send the
string to the device. I have not been able to make this work and always get 0 back in
response.
My question is, how exactly do you send a string to an HID device on Linux. I have
scoured the internet and seen others ask the same question but none have ever got an
answer. Any help you could provide would be extremely welcomed.
Attached it some test code and the output results.
Thanks,
James
#include <asm/types.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/hiddev.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
int nfile = open( "/dev/usb/hid/hiddev0", O_RDONLY);
printf( "Opened file\n");
ioctl( nfile, HIDIOCINITREPORT, 0);
printf( "Initialized reports\n");
hiddev_usage_ref usage = { 0 };
usage.report_type = HID_REPORT_TYPE_OUTPUT;
usage.report_id = HID_REPORT_ID_FIRST;
usage.field_index = 0;
usage.usage_index = 0;
usage.usage_code = 0;
//usage.value = *((__s32 *)(":\x00\xFF\r"));
usage.value = *((__s32 *)("\r\xFF\x00:"));
int nret = ioctl( nfile, HIDIOCSUSAGE, &usage);
printf( "SUSAGE returned %d\n", nret);
usage.usage_index = 1;
usage.value = 0;
nret = ioctl( nfile, HIDIOCSUSAGE, &usage);
printf( "SUSAGE returned %d\n", nret);
hiddev_report_info report = { 0 };
report.report_type = HID_REPORT_TYPE_OUTPUT;
report.report_id = HID_REPORT_ID_FIRST;
report.num_fields = 1;
nret = ioctl( nfile, HIDIOCSREPORT, &report);
printf( "SREPORT returned %d\n", nret);
report.report_type = HID_REPORT_TYPE_INPUT;
report.report_id = HID_REPORT_ID_FIRST;
report.num_fields = 2;
nret = ioctl( nfile, HIDIOCGREPORT, &report);
printf( "GREPORT returned %d\n", nret);
usage.report_type = HID_REPORT_TYPE_INPUT;
usage.report_id = HID_REPORT_ID_FIRST;
usage.field_index = 0;
usage.usage_index = 0;
usage.usage_code = 0;
usage.value = 0;
nret = ioctl( nfile, HIDIOCGUSAGE, &usage);
printf( "GUSAGE returned %d with value 0x%X\n", nret, usage.value);
close( nfile);
return 0;
}
Output:
Opened file
Initialized reports
SUSAGE returned 0
SUSAGE returned 0
SREPORT returned 0
GREPORT returned 0
GUSAGE returned 0 with value 0x0 <-- Should be UPS result
Need a new email address that people can remember
Check out the new EudoraMail at
http://www.eudoramail.com
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel