Author Topic: hid.dll --> fileStreamdevicedata.Read  (Read 14862 times)

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
hid.dll --> fileStreamdevicedata.Read
« on: September 10, 2012, 12:10:12 pm »
I am using fileStreamdevicedata.Read to read the bulk transfer data from the microcontroller. Is there any command that I can use to determine if there is bulk transfer data coming from the microcontroller before using this command?

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: hid.dll --> fileStreamdevicedata.Read
« Reply #1 on: September 10, 2012, 10:52:49 pm »
If there is no data coming in from the microcontroller but one calls the fileStreamdevicedata.Read, how to address this issue?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: hid.dll --> fileStreamdevicedata.Read
« Reply #2 on: September 11, 2012, 02:31:59 pm »
Time out and try again. See my example code:

http://www.lvr.com/hidpage.htm#MyExampleCode

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: hid.dll --> fileStreamdevicedata.Read
« Reply #3 on: September 12, 2012, 11:13:41 pm »
I tried to add in a Button1 for read operation only.

I clicked on "Find My Device" followed by "Button1" for "no incoming data" operation. It works with this message: "The attempt to read a report timed out.".
Then I clicked on "Find My Device" again followed by "Once". There is incoming data but somehow during fileStreamdevicedata.EndRead(ar), it gives error.

Unexpected Exception: Either the IAsyncResult object did not come from the corresponding async method on this type, or EndRead was called multiple times with the same IAsync Result.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim inputReportBuffer() As Byte = Nothing
        Dim ar As IAsyncResult = Nothing
        transferInProgress = True

        ' Timeout if no report is available.
        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)
            tmrReadTimeout.Start()

            If (fileStreamdevicedata.CanRead) Then

                fileStreamdevicedata.BeginRead(inputReportBuffer, 0, inputReportBuffer.Length, New AsyncCallback(AddressOf GetInputReportData), inputReportBuffer)

            Else
                CloseCommunications()
                lstResults.Items.Add("The attempt to read an Input report has failed.")
            End If
        End If
    End Sub

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: hid.dll --> fileStreamdevicedata.Read
« Reply #4 on: September 12, 2012, 11:56:09 pm »
I just solved it using On Error Resume Next and remove Try Catch.