HI..Good day Every One..
I am developing a Windows application to communicate with a USB HID for target board MCB1700 in visual c++ 6.0. here i'm able to get vendor id, product id, version number. But i'm not able to execute the writefile function. I'm trying to write 64 bytes of data. for that it is giving 1784 as getlast error.
my code is
HIDHandle = CreateFile(FunctionClassDeviceData.DevicePath,GENERIC_WRITE|GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, &SecurityAttributes, OPEN_EXISTING, 0, NULL); . //code to get HIDAttributes . //here the issue code int retval = 0; DWORD BytesWritten; BYTE OutReport[64] = {0x00}; retval = WriteFile(HIDHandle, OutReport, sizeof(OutReport), (LPDWORD)&BytesWritten, NULL); printf("return Value: %d\n", retval); // returning 0 value retval = GetLastError(); printf("Last error Value: %d\n", retval); //it is 1784.
And same hardware is working fine with generic_hid_cs_50 www.lvr.com/.../generic_hid_cs_50.zip. For target side details please go refer below link http://www.keil.com/forum/20085/
Anybody has any suggestion of what I should do? Thanks. Thanks & Regards, Raja Kumar
One thing you may want to check is that your hid can actually accept an output of 64 bytes. I found out that some hid have a fixed output size and you must pad your output or break it in multiple blocks.
Below a snippet showing what I mean:
/* Assumed that HIDHandle is already opened... */ PHIDP_PREPARSED_DATA preparsedData; HIDP_CAPS hidCapabilities; // Get the device capabilities HidD_GetPreparsedData(HIDHandle, &preparsedData); HidP_GetCaps(preparsedData,&hidCapabilities); // Free data HidD_FreePreparsedData(preparsedData); // Now in your Write call... // Make sure the size you need to send match: hidCapabilities.OutputReportByteLength // If not then manipulate your buffer to send it in multiple blocks or pad it with 0x00 retval = WriteFile(HIDHandle, OutReport, hidCapabilities.OutputReportByteLength, (LPDWORD)&BytesWritten, NULL);
Hope this helps!