PsychHID, windows XP 32bit

>> PsychtoolboxVersion
ans =
3.0.9 - Flavor: beta - Corresponds to SVN Revision 2352
~~~~~~

Running on Windows XP 32bit OS. Running Matlab R2009a.

Brand new to PTB, and I'm trying to interface to an expandIO board
http://www.firmwarefactory.com/expandIOUSB.aspx

>> PsychHIDTest
TestPsychHID
Making a list of all your HID-compliant devices. ...

You have 2 HID-compliant devices:
device 1: TBD, Dell, Dell USB Keyboard Hub, 0 inputs, 0 outputs, serialNumber ?
device 2: TBD, expandIO-USB, Firmware Factory Ltd, 0 inputs, 0 outputs, serialNumber Prototype Board
~~~~~~

So, PsychHIDTest can see the board (device 2).
I was trying to get the Firmware ID, report 0x94 (148), as a simple test.

Here's what I've tried, and what I get:

>> [report,err]=PsychHID('GetReport', 2, 1, 148, 4)
report =
0 0 0 0
err =
n: -1
name: 'The supplied user buffer is not valid for the requested operation.'
description: 'The supplied user buffer is not valid for the requested operation.'
reportLength: -1
reportTime: 9.7406e-286
~~~~~
similar for ('GetReport', 2, 2, 148, 4)
~~~~~
>> x=uint8([148,0,0,0,])
>> PsychHID('SetReport', 2, 1, 0, x)
ans =
n: -1
name: 'The supplied user buffer is not valid for the requested operation.'
description: 'The supplied user buffer is not valid for the requested operation.'
~~~~~
similar for ('SetReport', 2, 2, 0, x)
~~~~~
>> PsychHID('SetReport', 2, 1, 148, x)
ans =
n: -1
name: 'The parameter is incorrect.'
description: 'The parameter is incorrect.'




I've also tried USBControlTransfer (remember, mine is the second device):

>> devices.vendorID
ans =
16700
ans =
2880

>> devices.productID
ans =
8198
ans =
306

>> handle = PsychHID('OpenUSBDevice', 2880, 306)
Error in function OpenUSBDevice: Usage error
Failed to open the specified type of generic USB device. Make sure it is plugged in or not already open.
PTB-INFO: Multi-display setup in explicit multi-display mode detected. Using the following mapping:
PTB-INFO: Screen 0 corresponds to the full Windows desktop area. Useful for stereo presentations in stereomode=4 ...
PTB-INFO: Screen 1 corresponds to the display area of the monitor with the Windows-internal name \\.\DISPLAY1 ...
PTB-INFO: Screen 2 corresponds to the display area of the monitor with the Windows-internal name \\.\DISPLAY2 ...
~~~~~


So, what am I missing? If you need a tester for the PsychHID windows side, I'm can do that.
Congratulations, you are probably the first person ever testing that part of PsychHID for Windows. There could be all kinds of bugs in PsychHID causing this, or it is a bug on your side, who knows? I didn't have any test hardware to try if it actually works as expected and nobody ever stepped up to test it. I also don't have time atm to work on this, so let's hope any of the below works aka it is not a bug in PsychHID:

One thing you could try is following the approach in DaqDIn.m:

First a 1-byte 'SetReport' command to send the reportId to the device via output transfer, basically a query for its serial number:

PsychHID('SetReport', deviceid, 2, 148, uint8(0))

Then a 'GetReport' to receive the response via input report:

[rep, err] = PsychHID('GetReport', deviceid, 1, 148, 4)

trying [rep, err] = PsychHID('GetReport', deviceid, 1, 148, 5) can't hurt either, in case there's some problem with buffersize.

You could also try if using reportType 3 "feature reports" instead of 1 or 2 for input or output reports make any difference.

Look at DaqDIn.m and other Daq... functions though, it also uses some more calls to clear out queues etc. That file at least works on os/x, so it demonstrates correct use for a similar task on a different device.

good luck,
-mario

--- In psychtoolbox@yahoogroups.com, "David" <dknovick@...> wrote:
>
> >> PsychtoolboxVersion
> ans =
> 3.0.9 - Flavor: beta - Corresponds to SVN Revision 2352
> ~~~~~~
>
> Running on Windows XP 32bit OS. Running Matlab R2009a.
>
> Brand new to PTB, and I'm trying to interface to an expandIO board
> http://www.firmwarefactory.com/expandIOUSB.aspx
>
> >> PsychHIDTest
> TestPsychHID
> Making a list of all your HID-compliant devices. ...
>
> You have 2 HID-compliant devices:
> device 1: TBD, Dell, Dell USB Keyboard Hub, 0 inputs, 0 outputs, serialNumber ?
> device 2: TBD, expandIO-USB, Firmware Factory Ltd, 0 inputs, 0 outputs, serialNumber Prototype Board
> ~~~~~~
>
> So, PsychHIDTest can see the board (device 2).
> I was trying to get the Firmware ID, report 0x94 (148), as a simple test.
>
> Here's what I've tried, and what I get:
>
> >> [report,err]=PsychHID('GetReport', 2, 1, 148, 4)
> report =
> 0 0 0 0
> err =
> n: -1
> name: 'The supplied user buffer is not valid for the requested operation.'
> description: 'The supplied user buffer is not valid for the requested operation.'
> reportLength: -1
> reportTime: 9.7406e-286
> ~~~~~
> similar for ('GetReport', 2, 2, 148, 4)
> ~~~~~
> >> x=uint8([148,0,0,0,])
> >> PsychHID('SetReport', 2, 1, 0, x)
> ans =
> n: -1
> name: 'The supplied user buffer is not valid for the requested operation.'
> description: 'The supplied user buffer is not valid for the requested operation.'
> ~~~~~
> similar for ('SetReport', 2, 2, 0, x)
> ~~~~~
> >> PsychHID('SetReport', 2, 1, 148, x)
> ans =
> n: -1
> name: 'The parameter is incorrect.'
> description: 'The parameter is incorrect.'
>
>
>
>
> I've also tried USBControlTransfer (remember, mine is the second device):
>
> >> devices.vendorID
> ans =
> 16700
> ans =
> 2880
>
> >> devices.productID
> ans =
> 8198
> ans =
> 306
>
> >> handle = PsychHID('OpenUSBDevice', 2880, 306)
> Error in function OpenUSBDevice: Usage error
> Failed to open the specified type of generic USB device. Make sure it is plugged in or not already open.
> PTB-INFO: Multi-display setup in explicit multi-display mode detected. Using the following mapping:
> PTB-INFO: Screen 0 corresponds to the full Windows desktop area. Useful for stereo presentations in stereomode=4 ...
> PTB-INFO: Screen 1 corresponds to the display area of the monitor with the Windows-internal name \\.\DISPLAY1 ...
> PTB-INFO: Screen 2 corresponds to the display area of the monitor with the Windows-internal name \\.\DISPLAY2 ...
> ~~~~~
>
>
> So, what am I missing? If you need a tester for the PsychHID windows side, I'm can do that.
>
Oh and this passage from your devices manual also sounds relevant and suggests zero-padding report sizes to 64 bytes:

"Commands are sent from the host and responses are
received from expandIO in the form of HID reports. With
the exception of the EXESPI, EXEI2C and EXEUNIO
commands, all commands and responses are 4 bytes
long. Full speed device reports contain 16 commands /
responses each. Low speed device reports contain 2
commands / responses each. If fewer commands are
sent in a report, the remainder of the report should be
padded out with nulls."


--- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@...> wrote:
>
>
>
> Congratulations, you are probably the first person ever testing that part of PsychHID for Windows. There could be all kinds of bugs in PsychHID causing this, or it is a bug on your side, who knows? I didn't have any test hardware to try if it actually works as expected and nobody ever stepped up to test it. I also don't have time atm to work on this, so let's hope any of the below works aka it is not a bug in PsychHID:
>
> One thing you could try is following the approach in DaqDIn.m:
>
> First a 1-byte 'SetReport' command to send the reportId to the device via output transfer, basically a query for its serial number:
>
> PsychHID('SetReport', deviceid, 2, 148, uint8(0))
>
> Then a 'GetReport' to receive the response via input report:
>
> [rep, err] = PsychHID('GetReport', deviceid, 1, 148, 4)
>
> trying [rep, err] = PsychHID('GetReport', deviceid, 1, 148, 5) can't hurt either, in case there's some problem with buffersize.
>
> You could also try if using reportType 3 "feature reports" instead of 1 or 2 for input or output reports make any difference.
>
> Look at DaqDIn.m and other Daq... functions though, it also uses some more calls to clear out queues etc. That file at least works on os/x, so it demonstrates correct use for a similar task on a different device.
>
> good luck,
> -mario
>
> --- In psychtoolbox@yahoogroups.com, "David" <dknovick@> wrote:
> >
> > >> PsychtoolboxVersion
> > ans =
> > 3.0.9 - Flavor: beta - Corresponds to SVN Revision 2352
> > ~~~~~~
> >
> > Running on Windows XP 32bit OS. Running Matlab R2009a.
> >
> > Brand new to PTB, and I'm trying to interface to an expandIO board
> > http://www.firmwarefactory.com/expandIOUSB.aspx
> >
> > >> PsychHIDTest
> > TestPsychHID
> > Making a list of all your HID-compliant devices. ...
> >
> > You have 2 HID-compliant devices:
> > device 1: TBD, Dell, Dell USB Keyboard Hub, 0 inputs, 0 outputs, serialNumber ?
> > device 2: TBD, expandIO-USB, Firmware Factory Ltd, 0 inputs, 0 outputs, serialNumber Prototype Board
> > ~~~~~~
> >
> > So, PsychHIDTest can see the board (device 2).
> > I was trying to get the Firmware ID, report 0x94 (148), as a simple test.
> >
> > Here's what I've tried, and what I get:
> >
> > >> [report,err]=PsychHID('GetReport', 2, 1, 148, 4)
> > report =
> > 0 0 0 0
> > err =
> > n: -1
> > name: 'The supplied user buffer is not valid for the requested operation.'
> > description: 'The supplied user buffer is not valid for the requested operation.'
> > reportLength: -1
> > reportTime: 9.7406e-286
> > ~~~~~
> > similar for ('GetReport', 2, 2, 148, 4)
> > ~~~~~
> > >> x=uint8([148,0,0,0,])
> > >> PsychHID('SetReport', 2, 1, 0, x)
> > ans =
> > n: -1
> > name: 'The supplied user buffer is not valid for the requested operation.'
> > description: 'The supplied user buffer is not valid for the requested operation.'
> > ~~~~~
> > similar for ('SetReport', 2, 2, 0, x)
> > ~~~~~
> > >> PsychHID('SetReport', 2, 1, 148, x)
> > ans =
> > n: -1
> > name: 'The parameter is incorrect.'
> > description: 'The parameter is incorrect.'
> >
> >
> >
> >
> > I've also tried USBControlTransfer (remember, mine is the second device):
> >
> > >> devices.vendorID
> > ans =
> > 16700
> > ans =
> > 2880
> >
> > >> devices.productID
> > ans =
> > 8198
> > ans =
> > 306
> >
> > >> handle = PsychHID('OpenUSBDevice', 2880, 306)
> > Error in function OpenUSBDevice: Usage error
> > Failed to open the specified type of generic USB device. Make sure it is plugged in or not already open.
> > PTB-INFO: Multi-display setup in explicit multi-display mode detected. Using the following mapping:
> > PTB-INFO: Screen 0 corresponds to the full Windows desktop area. Useful for stereo presentations in stereomode=4 ...
> > PTB-INFO: Screen 1 corresponds to the display area of the monitor with the Windows-internal name \\.\DISPLAY1 ...
> > PTB-INFO: Screen 2 corresponds to the display area of the monitor with the Windows-internal name \\.\DISPLAY2 ...
> > ~~~~~
> >
> >
> > So, what am I missing? If you need a tester for the PsychHID windows side, I'm can do that.
> >
>
Thanks for the suggestions. Yeah, I also caught the 64 bytes of padding.

So this is what I tried, and the response that I received:

>> err=PsychHID('SetReport', 2, 2, 148, uint8(0))
err =
n: -1
name: 'The parameter is incorrect.'
description: 'The parameter is incorrect.'


>> x64 = uint8(zeros(1,64))
>> err=PsychHID('SetReport', 2, 2, 148, x64)
err =
n: -1
name: 'The parameter is incorrect.'
description: 'The parameter is incorrect.'


Doesn't look like the SetReport is working correctly?



--- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@...> wrote:
>
> Oh and this passage from your devices manual also sounds relevant and suggests zero-padding report sizes to 64 bytes:
>
> "Commands are sent from the host and responses are
> received from expandIO in the form of HID reports. With
> the exception of the EXESPI, EXEI2C and EXEUNIO
> commands, all commands and responses are 4 bytes
> long. Full speed device reports contain 16 commands /
> responses each. Low speed device reports contain 2
> commands / responses each. If fewer commands are
> sent in a report, the remainder of the report should be
> padded out with nulls."
>
>
> --- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@> wrote:
> >
> >
> >
> > Congratulations, you are probably the first person ever testing that part of PsychHID for Windows. There could be all kinds of bugs in PsychHID causing this, or it is a bug on your side, who knows? I didn't have any test hardware to try if it actually works as expected and nobody ever stepped up to test it. I also don't have time atm to work on this, so let's hope any of the below works aka it is not a bug in PsychHID:
> >
> > One thing you could try is following the approach in DaqDIn.m:
> >
> > First a 1-byte 'SetReport' command to send the reportId to the device via output transfer, basically a query for its serial number:
> >
> > PsychHID('SetReport', deviceid, 2, 148, uint8(0))
> >
> > Then a 'GetReport' to receive the response via input report:
> >
> > [rep, err] = PsychHID('GetReport', deviceid, 1, 148, 4)
> >
> > trying [rep, err] = PsychHID('GetReport', deviceid, 1, 148, 5) can't hurt either, in case there's some problem with buffersize.
> >
> > You could also try if using reportType 3 "feature reports" instead of 1 or 2 for input or output reports make any difference.
> >
> > Look at DaqDIn.m and other Daq... functions though, it also uses some more calls to clear out queues etc. That file at least works on os/x, so it demonstrates correct use for a similar task on a different device.
> >
> > good luck,
> > -mario
> >
> > --- In psychtoolbox@yahoogroups.com, "David" <dknovick@> wrote:
> > >
> > > >> PsychtoolboxVersion
> > > ans =
> > > 3.0.9 - Flavor: beta - Corresponds to SVN Revision 2352
> > > ~~~~~~
> > >
> > > Running on Windows XP 32bit OS. Running Matlab R2009a.
> > >
> > > Brand new to PTB, and I'm trying to interface to an expandIO board
> > > http://www.firmwarefactory.com/expandIOUSB.aspx
> > >
> > > >> PsychHIDTest
> > > TestPsychHID
> > > Making a list of all your HID-compliant devices. ...
> > >
> > > You have 2 HID-compliant devices:
> > > device 1: TBD, Dell, Dell USB Keyboard Hub, 0 inputs, 0 outputs, serialNumber ?
> > > device 2: TBD, expandIO-USB, Firmware Factory Ltd, 0 inputs, 0 outputs, serialNumber Prototype Board
> > > ~~~~~~
> > >
> > > So, PsychHIDTest can see the board (device 2).
> > > I was trying to get the Firmware ID, report 0x94 (148), as a simple test.
> > >
> > > Here's what I've tried, and what I get:
> > >
> > > >> [report,err]=PsychHID('GetReport', 2, 1, 148, 4)
> > > report =
> > > 0 0 0 0
> > > err =
> > > n: -1
> > > name: 'The supplied user buffer is not valid for the requested operation.'
> > > description: 'The supplied user buffer is not valid for the requested operation.'
> > > reportLength: -1
> > > reportTime: 9.7406e-286
> > > ~~~~~
> > > similar for ('GetReport', 2, 2, 148, 4)
> > > ~~~~~
> > > >> x=uint8([148,0,0,0,])
> > > >> PsychHID('SetReport', 2, 1, 0, x)
> > > ans =
> > > n: -1
> > > name: 'The supplied user buffer is not valid for the requested operation.'
> > > description: 'The supplied user buffer is not valid for the requested operation.'
> > > ~~~~~
> > > similar for ('SetReport', 2, 2, 0, x)
> > > ~~~~~
> > > >> PsychHID('SetReport', 2, 1, 148, x)
> > > ans =
> > > n: -1
> > > name: 'The parameter is incorrect.'
> > > description: 'The parameter is incorrect.'
> > >
> > >
> > >
> > >
> > > I've also tried USBControlTransfer (remember, mine is the second device):
> > >
> > > >> devices.vendorID
> > > ans =
> > > 16700
> > > ans =
> > > 2880
> > >
> > > >> devices.productID
> > > ans =
> > > 8198
> > > ans =
> > > 306
> > >
> > > >> handle = PsychHID('OpenUSBDevice', 2880, 306)
> > > Error in function OpenUSBDevice: Usage error
> > > Failed to open the specified type of generic USB device. Make sure it is plugged in or not already open.
> > > PTB-INFO: Multi-display setup in explicit multi-display mode detected. Using the following mapping:
> > > PTB-INFO: Screen 0 corresponds to the full Windows desktop area. Useful for stereo presentations in stereomode=4 ...
> > > PTB-INFO: Screen 1 corresponds to the display area of the monitor with the Windows-internal name \\.\DISPLAY1 ...
> > > PTB-INFO: Screen 2 corresponds to the display area of the monitor with the Windows-internal name \\.\DISPLAY2 ...
> > > ~~~~~
> > >
> > >
> > > So, what am I missing? If you need a tester for the PsychHID windows side, I'm can do that.
> > >
> >
>
--- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@...> wrote:
>
>
>
> --- In psychtoolbox@yahoogroups.com, "David" <dknovick@> wrote:
> >
> > Thanks for the suggestions. Yeah, I also caught the 64 bytes of padding.
> >
> > So this is what I tried, and the response that I received:
> >
> > >> err=PsychHID('SetReport', 2, 2, 148, uint8(0))
> > err =
> > n: -1
> > name: 'The parameter is incorrect.'
> > description: 'The parameter is incorrect.'
> >
> >
> > >> x64 = uint8(zeros(1,64))
> > >> err=PsychHID('SetReport', 2, 2, 148, x64)
> > err =
> > n: -1
> > name: 'The parameter is incorrect.'
> > description: 'The parameter is incorrect.'
> >
> >
> > Doesn't look like the SetReport is working correctly?
> >
>
> Or you're using it the wrong way. This...
>
> err = PsychHID('SetReport', 2, 2, 0, uint8([0 7]));
>
...
>
> PsychHID on Linux and Windows both use the HIDAPI library as HID-USB backend. The PsychHID source code on Linux and Windows is identical, so apparently no bug there. The error message 'The parameter is incorrect' is reported by the Windows OS itself. According to this closed bug report...
>
> <https://github.com/signal11/hidapi/issues/13>
>
> ... this likely means no bug, but that the provided reportId is wrong for the given device.
>
> Comparing the docs of your device with what works and what doesn't with my keyboard, i think the command code 148 is not meant to be the reportId, your docs actually never talk about reportId at all. Maybe what you need is a reportId of zero + 64 bytes of zero-padded command buffer for your device, so:
>
> x64 = uint8(zeros(1,65));
> x64(2) = 148;
> err=PsychHID('SetReport', 2, 2, 0, x65)
>
> 65-Byte buffer, zero filled. x64(1) as a placeholder for the reportId of zero. Actual 64-Byte zero-padded command buffer for device starts at x64(2) with the command code 148.
>
> Similar logic could apply to the 'GetReport' calls to retrieve a 65 byte buffer with 1 byte reportid + 64 byte payload.
>
> -mario
>
>
> >
> >

Ah, now that I know the messages are peculating up from hidapi, it makes more sense. And that also gave me another idea. I'm familiar with hidapi, I was trying to use it first within Matlab (using calllib), I could enumerate the hid devices, but when I tried to write to a hid, it would crash Matlab.

So I used the testgui that comes with the hidapi code to run some tests. If I supply an incorrect value, I get 'The parameter is incorrect.' (Ah-ha!). I tried your suggestion of a 0, report_id, and then 63 more zeros. It worked, and I received 64 bytes back of data, with the first 4 containing the firmware id (yeah!)

So now I take the knowledge, and use it for PsychHID:
>> x65=uint8(zeros(1,65))
>> x65(2)=148
>> err=PsychHID('SetReport', 2, 2, 0, x65)
err =
n: 65
name: ''
description: ''

so that seems to work.

but, when I do:
>> [rep,err]=PsychHID('GetReport', 2,1,0,64)
err =
n: -1
name: 'The supplied user buffer is not valid for the requested operation.'
description: 'The supplied user buffer is not valid for the requested operation.'
reportLength: -1
reportTime: 8.9133e-286


So, now that I know the error doesn't come from you, I do some looking, and found this:

http://www.techtalkz.com/microsoft-device-drivers/246343-hid-different-report-id.html
"This is a bug of the HID API. Use the max report size aka
OutputReportByteLength. Windows will write the correct number of bytes."

How big is the buffer?
http://www.lvr.com/hidfaq.htm (scroll down to "How large is the ReadFile buffer?")

So I've tried buffer sizes of:
4,64,65,70,256 (what is used in testgui),512, 1024

and it always says: 'The supplied user buffer is not valid for the requested operation.'

suggestions on buffer size, or how I can find the maximum value?
Ok, that makes sense. The reports are of size 64 Bytes + 1 Byte for the reportId = 65 Bytes, just as for sending. PsychHID had a hard compiled limit of 64 Bytes. Now i've raised it to 65 Bytes. A future version will implement proper dynamic sizes instead of hard compiled sizes.

Get a fresh PsychHID for 32-Bit Matlab R2007a and later from this link:

<http://psychtoolbox-3.googlecode.com/svn-history/r2358/trunk/Psychtoolbox/PsychBasic/MatlabWindowsFilesR2007a/PsychHID.mexw32>

Let me know asap if it works.
-mario

--- In psychtoolbox@yahoogroups.com, "David" <dknovick@...> wrote:
>
>
>
> --- In psychtoolbox@yahoogroups.com, "David" <dknovick@> wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > --- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@> wrote:
> > >
> > >
> > >
> > > --- In psychtoolbox@yahoogroups.com, "David" <dknovick@> wrote:
> > > >
> > > > Thanks for the suggestions. Yeah, I also caught the 64 bytes of padding.
> > > >
> > > > So this is what I tried, and the response that I received:
> > > >
> > > > >> err=PsychHID('SetReport', 2, 2, 148, uint8(0))
> > > > err =
> > > > n: -1
> > > > name: 'The parameter is incorrect.'
> > > > description: 'The parameter is incorrect.'
> > > >
> > > >
> > > > >> x64 = uint8(zeros(1,64))
> > > > >> err=PsychHID('SetReport', 2, 2, 148, x64)
> > > > err =
> > > > n: -1
> > > > name: 'The parameter is incorrect.'
> > > > description: 'The parameter is incorrect.'
> > > >
> > > >
> > > > Doesn't look like the SetReport is working correctly?
> > > >
> > >
> > > Or you're using it the wrong way. This...
> > >
> > > err = PsychHID('SetReport', 2, 2, 0, uint8([0 7]));
> > >
> > ...
> > >
> > > PsychHID on Linux and Windows both use the HIDAPI library as HID-USB backend. The PsychHID source code on Linux and Windows is identical, so apparently no bug there. The error message 'The parameter is incorrect' is reported by the Windows OS itself. According to this closed bug report...
> > >
> > > <https://github.com/signal11/hidapi/issues/13>
> > >
> > > ... this likely means no bug, but that the provided reportId is wrong for the given device.
> > >
> > > Comparing the docs of your device with what works and what doesn't with my keyboard, i think the command code 148 is not meant to be the reportId, your docs actually never talk about reportId at all. Maybe what you need is a reportId of zero + 64 bytes of zero-padded command buffer for your device, so:
> > >
> > > x64 = uint8(zeros(1,65));
> > > x64(2) = 148;
> > > err=PsychHID('SetReport', 2, 2, 0, x65)
> > >
> > > 65-Byte buffer, zero filled. x64(1) as a placeholder for the reportId of zero. Actual 64-Byte zero-padded command buffer for device starts at x64(2) with the command code 148.
> > >
> > > Similar logic could apply to the 'GetReport' calls to retrieve a 65 byte buffer with 1 byte reportid + 64 byte payload.
> > >
> > > -mario
> > >
> > >
> > > >
> > > >
> >
> > Ah, now that I know the messages are peculating up from hidapi, it makes more sense. And that also gave me another idea. I'm familiar with hidapi, I was trying to use it first within Matlab (using calllib), I could enumerate the hid devices, but when I tried to write to a hid, it would crash Matlab.
> >
> > So I used the testgui that comes with the hidapi code to run some tests. If I supply an incorrect value, I get 'The parameter is incorrect.' (Ah-ha!). I tried your suggestion of a 0, report_id, and then 63 more zeros. It worked, and I received 64 bytes back of data, with the first 4 containing the firmware id (yeah!)
> >
> > So now I take the knowledge, and use it for PsychHID:
> > >> x65=uint8(zeros(1,65))
> > >> x65(2)=148
> > >> err=PsychHID('SetReport', 2, 2, 0, x65)
> > err =
> > n: 65
> > name: ''
> > description: ''
> >
> > so that seems to work.
> >
> > but, when I do:
> > >> [rep,err]=PsychHID('GetReport', 2,1,0,64)
> > err =
> > n: -1
> > name: 'The supplied user buffer is not valid for the requested operation.'
> > description: 'The supplied user buffer is not valid for the requested operation.'
> > reportLength: -1
> > reportTime: 8.9133e-286
> >
> >
> > So, now that I know the error doesn't come from you, I do some looking, and found this:
> >
> > http://www.techtalkz.com/microsoft-device-drivers/246343-hid-different-report-id.html
> > "This is a bug of the HID API. Use the max report size aka
> > OutputReportByteLength. Windows will write the correct number of bytes."
> >
> > How big is the buffer?
> > http://www.lvr.com/hidfaq.htm (scroll down to "How large is the ReadFile buffer?")
> >
> > So I've tried buffer sizes of:
> > 4,64,65,70,256 (what is used in testgui),512, 1024
> >
> > and it always says: 'The supplied user buffer is not valid for the requested operation.'
> >
> > suggestions on buffer size, or how I can find the maximum value?
> >
>
>
> Here's an update, I adapted the hdipid test program to interface to my hid board. The C code opens the device, requests the firmwareID and received a reply.
>
> If I set the rec buffer to less that 65 char, I receive the same error as above "The supplied user buffer is not valid for the requested operation". Which, looking through the code means that the returned string is longer then the supplied buffer.
>
> If I set the rec buffer to 65+, I get my 64 byte message from the board.
>