Hi
I am working on linux RH9 kernel 2.4.32 and have usb device board
for which windows device driver is already working successfully.
But I am not able to get it working on linux I have tried basic
commands for device in userspace programs using ioctls write/read reports.
Below is my source code , please help..
>>>>>>>>CODE_START
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <asm/types.h>
#include <linux/hiddev.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <string.h>
#ifndef HID_MAX_USAGES
#define HID_MAX_USAGES 1024
#endif
#define READ_BUFFER_LENGTH 64
#define RPT_SIZE 64
int getUsageCode_Out0( int );
unsigned long usageCode;
struct hiddev_report_info rep_info;
unsigned char ReportStr[6] = {
0x01,
0x04, // EOT;
'C', // C;
'v', // v;
0x05 , // ENQ;
0x00 ,
};
int getUsageCode_Out0( int fd )
{
struct hiddev_usage_ref uref;
int rc;
uref.report_type = HID_REPORT_TYPE_OUTPUT;
uref.report_id = 0x01;
uref.field_index = 0;
uref.usage_index = 0;
rc = ioctl( fd, HIDIOCGUCODE, &uref );
if (rc < 0) return rc;
usageCode = uref.usage_code;
printf("value of the uses code is %x \n",usageCode);
return 0;
}
void sendstring(int fd, unsigned char *psz)
{
struct hiddev_usage_ref uref;
struct hiddev_event eventset[6] ;
int i, j;
unsigned char c;
struct timeval timeout;
fd_set readFDS ;
timeout.tv_sec = 0;
timeout.tv_usec = 100000 ;
FD_ZERO(&readFDS);
FD_SET(fd,&readFDS);
select((fd+1),&readFDS,NULL,NULL,&timeout);
i = 0;
psz = CoinReportStr ;
fprintf(stderr," sendstring start %d\n",CoinReportStr[0]);
for (j = 0; j < 6; j++)
{
fprintf(stderr,"NUM: %d %d ::\n ", j, psz[j]);
uref.report_type = HID_REPORT_TYPE_OUTPUT;
uref.report_id = 0x01;
uref.field_index = 0;
uref.usage_code = usageCode;
uref.usage_index = j ;
uref.value = psz[j];
if (ioctl(fd, HIDIOCSUSAGE, &uref) < 0)
fprintf(stderr,"Error (SUSAGE) while talking to the UPS");
}
fprintf(stderr,"NEW\n");
rep_info.report_type = HID_REPORT_TYPE_OUTPUT ;
rep_info.report_id = 0x01 ;
rep_info.num_fields = 1;
if (ioctl(fd,HIDIOCSREPORT,&rep_info) <0)
{
fprintf(stderr,"ERROR: sendstring() failed: HIOIOCSREPORT\n");
return ;
}
else
fprintf(stderr,"SUCCESS...\n");
}
static void showReports(int fd)
{
struct hiddev_field_info finfo;
struct hiddev_usage_ref uref;
struct hiddev_event eventset[6] ;
struct hiddev_event events ;
int i, j, ret;
struct timeval timeout;
fd_set readFDS ;
timeout.tv_sec = 0;
timeout.tv_usec = 100000 ;
FD_ZERO(&readFDS);
FD_SET(fd,&readFDS);
select((fd+1),&readFDS,NULL,NULL,&timeout);
i = read(fd,(void *)&events,sizeof(struct hiddev_event));
fprintf(stderr,"DEBUG::RAMRAM: ii: %d\n",i);
rep_info.report_type = HID_REPORT_TYPE_INPUT;
rep_info.report_id = 0x03;
ret = ioctl(fd, HIDIOCGREPORTINFO, &rep_info);
ret = ioctl(fd, HIDIOCGREPORT, &rep_info);
// Get Reports
while (ret >= 0)
{
printf("HIDIOCGREPORTINFO: report_id=0x%X (%u fields)\n",
rep_info.report_id, rep_info.num_fields);
// Get Fields
for (i = 0; i < rep_info.num_fields; i++)
{
finfo.report_type = rep_info.report_type;
finfo.report_id = rep_info.report_id;
finfo.field_index = i;
ioctl(fd, HIDIOCGFIELDINFO, &finfo);
uref.report_type = finfo.report_type;
uref.report_id = finfo.report_id;
for (j=0;j<finfo.maxusage;j++)
{
// Get usages
uref.field_index = i;
uref.usage_index = j;
ioctl(fd, HIDIOCGUCODE, &uref);
ioctl(fd, HIDIOCGUSAGE, &uref);
ret = ioctl(fd, HIDIOCGREPORT, &rep_info);
printf(" >> usage_index=%u usage_code=0x%X () value=0x%X\n",
uref.usage_index,
uref.usage_code,
uref.value);
}
ret = ioctl(fd, HIDIOCGREPORT, &rep_info);
rep_info.report_id |= HID_REPORT_ID_NEXT;
ret = ioctl(fd, HIDIOCGREPORTINFO, &rep_info);
}
printf("\n");
}
}
int main(void)
{
int fd;
struct hiddev_devinfo device_info;
struct hiddev_string_descriptor string_desc;
struct hiddev_report_info rep_info;
char name[256] = {0};
char receive_buffer[RPT_SIZE];
int index;
int rc = 0;
fd = open("/dev/usb/hiddev0", O_RDWR);
if(fd < 0) {
perror("open of hiddev0 failed");
exit(errno);
}
if (ioctl(fd, HIDIOCINITREPORT,0) < 0)
{
fprintf(stderr,"ERROR: HIDIOCINREPORT FAILED \n");
exit(1);
}
getUsageCode_Out0(fd);
sendstring(fd,CoinReportStr);
showReports(fd);
close(fd);
return 0;
}
>>>>>>>>>>CODE_END
Regards
Himanshu Bafna
http://www.patni.com
World-Wide Partnerships. World-Class Solutions.
_____________________________________________________________________
This e-mail message may contain proprietary, confidential or legally
privileged information for the sole use of the person or entity to
whom this message was originally addressed. Any review, e-transmission
dissemination or other use of or taking of any action in reliance upon
this information by persons or entities other than the intended
recipient is prohibited. If you have received this e-mail in error
kindly delete this e-mail from your records. If it appears that this
mail has been forwarded to you without proper authority, please notify
us immediately at [EMAIL PROTECTED] and delete this mail.
_____________________________________________________________________
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Linux-usb-users@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-users