Can anyone verify if I am doing this right?
I am able to read the product and vendor ID's from an HID
device, so the CreateFile and the Get_Attributes
functions are working well. I am having a hard time
using WriteFile to send bytes to the device. I am
sending just 2 bytes to and x10 usb hid device. The
WriteFile call returns false.

Here is the CreateFile call:
handle = CreateFile(DeviceName,GENERIC_READ |
GENERIC_WRITE,FILE_SHARE_READ |
FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);

Here is the WriteFile definition and call:
[DllImport("kernel32.dll", SetLastError=true)]
private static extern unsafe bool WriteFile(int
hFile,void* lpBuffer,int nBytesToWrite,int*
nBytesWritten,int overlapped);


public unsafe bool WriteBytes(int handle, byte[]
OutputReportBytes)
{
int BytesWritten = 0;

fixed (byte* p = OutputReportBytes)
{
return WriteFile(handle, p,
OutputReportBytes.Length, &BytesWritten, 0);
}
}

Any help here would be greatly appreciated.
Thanks in advance.

Re: Unable to write to USB HID Device by Doron

Doron
Sat Aug 02 11:06:18 CDT 2003

are you using hid.dll to format your data at all?

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Mike Serra" <info@macllc.com> wrote in message
news:0e2d01c358fc$02e2b280$3501280a@phx.gbl...
> Can anyone verify if I am doing this right?
> I am able to read the product and vendor ID's from an HID
> device, so the CreateFile and the Get_Attributes
> functions are working well. I am having a hard time
> using WriteFile to send bytes to the device. I am
> sending just 2 bytes to and x10 usb hid device. The
> WriteFile call returns false.
>
> Here is the CreateFile call:
> handle = CreateFile(DeviceName,GENERIC_READ |
> GENERIC_WRITE,FILE_SHARE_READ |
> FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
>
> Here is the WriteFile definition and call:
> [DllImport("kernel32.dll", SetLastError=true)]
> private static extern unsafe bool WriteFile(int
> hFile,void* lpBuffer,int nBytesToWrite,int*
> nBytesWritten,int overlapped);
>
>
> public unsafe bool WriteBytes(int handle, byte[]
> OutputReportBytes)
> {
> int BytesWritten = 0;
>
> fixed (byte* p = OutputReportBytes)
> {
> return WriteFile(handle, p,
> OutputReportBytes.Length, &BytesWritten, 0);
> }
> }
>
> Any help here would be greatly appreciated.
> Thanks in advance.
>



Re: Unable to write to USB HID Device by Robert

Robert
Sat Aug 02 11:28:35 CDT 2003

Do you take into account that the first byte of the report is the
ReportID which is usually a 0x0 byte?


Re: Unable to write to USB HID Device by Robert

Robert
Sun Aug 03 01:30:10 CDT 2003

Mike Serra wrote:
> No I did not. I thought the beauty of hid was that you
> can read and write just like it was a file system file.
> How exactly does the data need to be formatted?

You have to write a properly formatted report. The proper way is to use
HidP_SetUsages and the other functions of this family. They set usages
into a report. Usually this can also be done directly because most HID
devices have rather simple reports, but sometimes you can get a real
complicated HID device. Have a look at the MS Sidewinder FF joystick. It
has the most complicated HID descriptor i have seen.


Re: Unable to write to USB HID Device by Mike

Mike
Mon Aug 04 15:57:16 CDT 2003

Thanks. I was able to get the report format and it works
well now.


>-----Original Message-----
>Mike Serra wrote:
>> No I did not. I thought the beauty of hid was that
you
>> can read and write just like it was a file system file.
>> How exactly does the data need to be formatted?
>
>You have to write a properly formatted report. The
proper way is to use
>HidP_SetUsages and the other functions of this family.
They set usages
>into a report. Usually this can also be done directly
because most HID
>devices have rather simple reports, but sometimes you
can get a real
>complicated HID device. Have a look at the MS Sidewinder
FF joystick. It
>has the most complicated HID descriptor i have seen.
>
>.
>