Author Topic: Generic HID (VB) bug when writing to device  (Read 9197 times)

sportebois

  • Member
  • ***
  • Posts: 2
Generic HID (VB) bug when writing to device
« on: April 26, 2011, 11:41:05 am »
Hello

First, great thanks for making so much ressources publicly available, this is indeed invaluable !

Communicating with my devices and testing works nicely.
But I came across one issue which looks like a bug.

One of my device has a InputReportByteLength=0x0 and OutputReportByteLength=0x3

I have updated the application to send 3 bytes.

When trying to write to the device, the bug arise in the FindTheHid sub.
Since the INputReportByteLength is 0, the runtime flow don't go into

Code: [Select]
                       If (MyHid.Capabilities.InputReportByteLength > 0) Then

                            ' Set the size of the Input report buffer.
                            ' Subtract 1 from the value in the Capabilities structure because
                            ' the array begins at index 0.

                            Array.Resize(inputReportBuffer, MyHid.Capabilities.InputReportByteLength)

                            fileStreamdevicedata = New FileStream(hidHandle, FileAccess.Read Or FileAccess.Write, inputReportBuffer.Length, False)

                        End If


So in the ExchangeInputAndOutputReports sub, the
Code: [Select]
If (fileStreamdevicedata.CanWrite) Thentest throw a null object error


I have tried to fix the issue, by updating the ExchangeInputAndOutputReports to
Code: [Select]
                        ...
                        If (fileStreamdevicedata.CanWrite) Then
                            'fileStreamdevicedata.Write(outputReportBuffer, 0, outputReportBuffer.Length)
                            fileStreamdevicedata.BeginWrite(outputReportBuffer, 0, outputReportBuffer.Length, New AsyncCallback(AddressOf GetOutputReportData), outputReportBuffer)

                            success = True
                        Else
                        ...

And adding the fileStreamData initialization for this case in the FindTheHid handler:
Code: [Select]
                        ...
                        If (MyHid.Capabilities.OutputReportByteLength > 0) Then
                         
                            ' Set the size of the Output report buffer.
                            ' Subtract 1 from the value in the Capabilities structure because
                            ' the array begins at index 0.

                            Array.Resize(outputReportBuffer, MyHid.Capabilities.OutputReportByteLength)
                         
                            If (fileStreamdevicedata Is Nothing) Then
                                fileStreamdevicedata = New FileStream(hidHandle, FileAccess.Write, outputReportBuffer.Length, False)

                            End If

                        End If
                        ...



But I'm still getting a runtime error
(approximative text, the error string beeing in french)
"The IO operation will not work. The file will probably get to big or the handle wasn't open to handler the synhchronous IO operations"


I'm not a VB expert so I might be missing something obvious, and getting this working would be really helpful, therefore any advice or insight really welcome to help me.

Regards,

Sébastien Portebois

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Generic HID (VB) bug when writing to device
« Reply #1 on: April 26, 2011, 02:46:06 pm »
Which line causes the error?

Is the handle open?

According to the HID spec, every HID must have an Input report. That's probably not the problem however.

Jan

sportebois

  • Member
  • ***
  • Posts: 2
Re: Generic HID (VB) bug when writing to device
« Reply #2 on: June 21, 2011, 05:18:50 am »
Hello

I'm sorry to come back so late,

I have found the issue, the outputReportBuffer.Length was wrong, simple as that ...

Cheers,

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Generic HID (VB) bug when writing to device
« Reply #3 on: June 21, 2011, 11:13:42 am »
Thanks for reporting back!

Jan