Cannot access a HID device get code 5 error please let me know how to access a HID device, I need an example of code to access a HID device in windows 7.Thanks.R.M. Kiran

/*******************************************************
Simplification of Windows HID

Alan Ott
Software signal 11

22/08/2009

Copyright 2009, all rights reserved.
 
The contents of this file can be used by anyone
for any other reason without conditions and can be
used as a starting point for your own applications
that appeal to HIDAPI.
********************************************************/

#include
#include
#include
#include
#include "hidapi.h".

The headers needed to sleep.
#ifdef _WIN32
#include
#else
#include
#endif

int main (int argc, char * argv)
{
int RES;
unsigned char buf [256];
#define MAX_STR 255
WSTR wchar_t [MAX_STR];
hid_device * handle;
int i;

WIN32 #ifdef
UNREFERENCED_PARAMETER (ARGC);
UNREFERENCED_PARAMETER (argv);
#endif

struct hid_device_info * devs, * cur_dev;
   
devs = hid_enumerate (0x0, 0x0);
printf ("id=%d\tsproduct id = %d\n",devs-> vendor_id provider, devs-> product_id ");
cur_dev = devs;
so that {(cur_dev)
printf ("detecte\n device type: % 04hx %04hx\n path: %s\n Serial_number: %ls", cur_dev-> vendor_id, cur_dev-> cur_dev-> path, product_id, cur_dev-> Serial_number);
printf ("\n");
printf ("manufacturer: %ls\n", cur_dev-> manufacturer_string ");
printf ("product: %ls\n", cur_dev-> product_string ");
printf ("output: %hx\n", cur_dev-> release_number ");
printf ("Interface: %d\n", cur_dev-> interface_number);
printf ("\n");
cur_dev = cur_dev-> next;
}
hid_free_enumeration (devs);

To implement the command buffer.
Memset (buf, 0x00, sizeof (BUF));
buf [0] = 0x01;
buf [1] = 0x81;

Open the unit by using the VID, PID,
and possibly the serial number.
handle = hid_open (0x4d8, 0x3f, L "12345");
handle = hid_open (0 x 0461, 0x4d81, NULL);
If (! handle) {}
printf ("cannot open device\n");
Return 1;
}

Read the manufacturer string
WSTR [0] = 0x0000;
RES = hid_get_manufacturer_string (handle, wstr, MAX_STR);
If (res<>
printf ("could not read the manufacturer string\n");
printf ("string of the manufacturer: %ls\n", wstr ");

Read the product chain
WSTR [0] = 0x0000;
RES = hid_get_product_string (handle, wstr, MAX_STR);
If (res<>
printf ("cannot read string\n product");
printf ("string of product: %ls\n", wstr ");

Read the serial number string
WSTR [0] = 0x0000;
RES = hid_get_serial_number_string (handle, wstr, MAX_STR);
If (res<>
printf ("could not read the serial number string\n");
printf ("string of serial number: (%d) %ls', wstr [0], wstr");
printf ("\n");

Read the indexed string 1
WSTR [0] = 0x0000;
RES = hid_get_indexed_string (handle, 1, wstr, MAX_STR);
If (res<>
printf ("could not read the string indexed 1\n");
printf ("indexed 1 string: %ls\n", wstr);

Define the function hid_read() as non-blocking.
hid_set_nonblocking (handle, 1);
   
Try reading from the device. It is and must be without
given here, but enforcement should not block.
RES = hid_read (handle, buf, 17);

Send a report on the device
buf [0] = 0x2;
buf [1] = 0xa0;
buf [2] = 0x0a;
buf [3] = 0x00;
buf [4] = 0x00;
RES = hid_send_feature_report (handle, buf, 17);
If (res< 0)="">
printf ("cannot send a feature report. \n") ;
}

Memset (buf, 0, sizeof (BUF));

Read a report of the device
buf [0] = 0x2;
RES = hid_get_feature_report (handle, buf, sizeof (buf));
If (res< 0)="">
printf ("failed to get a feature report. \n") ;
printf ("%ls", hid_error (handle));
}
else {}
Print the buffer returned.
printf ("function Report\n");
for (i = 0; i< res;="">
printf ("% 02hhx", buf [i]);
printf ("\n");
}

Memset (buf, 0, sizeof (BUF));

LED toggle (cmd 0x80). The first byte is the report number (0 x 1).
buf [0] = 0x1;
buf [1] = 0x80;
RES = hid_write (handle, buf, 17);
If (res< 0)="">
printf ("could not write () \n");
printf ("error: %ls\n", hid_error (handle));
}

Status request (cmd 0x81). The first byte is the report number (0 x 1).
buf [0] = 0x1;
buf [1] = 0x81;
hid_write (handle, buf, 17);
If (res<>
printf ("impossible to write() (2) \n" ");

Read the requested State. hid_read() has been set to be
non-blocking by the call to hid_set_nonblocking() above.
This loop shows the non-blocking of hid_read() nature.
Res = 0;
While (res == 0) {}
RES = hid_read (handle, buf, sizeof (buf));
If (res == 0)
printf("waiting...\n");
If (res<>
printf ("could not read () \n");
WIN32 #ifdef
Sleep (500);
#else
usleep(500*1000);
#endif
}

printf ("read data: \n");
Print the buffer returned.
for (i = 0; i< res;="">
printf ("% 02hhx", buf [i]);
printf ("\n");

hid_close (handle);

/ * Free of static objects of HIDAPI. */
hid_exit();

WIN32 #ifdef
System ("pause");
#endif

return 0;
}

Hi KIRAN RM,.

Given that you need example code to access a HID device in windows 7, the question you have posted is better suited for the MSDN Forums. Please post your query in the link next to the support of the MSDN forum for further assistance.

Windows hardware development

Tags: Windows

Similar Questions

Maybe you are looking for