Author Topic: USB generic hid for VB.NET does not read continuously  (Read 1270 times)

Frank Neumann

  • Member
  • ***
  • Posts: 17
USB generic hid for VB.NET does not read continuously
« on: November 21, 2019, 10:58:12 am »
Hi,

I have built a USB board with the AT90USB162, can also send and receive data. Have 8 LEDs connected and they shine when switching.

For the PC sided control software the software from the Internet of
the page http://janaxelson.com/files/generic_hid_vb_50.zip
downloaded.

I send the date from 0 - 255 for the 8 LEDs.
So far everything is fine.

Well, my HW also constantly sends back data, so I can see synonymous s.PC, what is switched or not.

But the software does not read continuously, It read only than if I send data.

Can someone tell me what this is due to the VB.NET software?

I did not change anything about the software, so I have it one on one
accepted. Only that I work with Byte instead of Hex.

BR
Frank

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2927
    • Lakeview Research
Re: USB generic hid for VB.NET does not read continuously
« Reply #1 on: November 21, 2019, 11:17:22 am »
Yes, that application is written to send, then read, data. You can edit the source code to read reports continuously.

For the code to read a report, see the ExchangeInputAndOutputReports routine.

Frank Neumann

  • Member
  • ***
  • Posts: 17
Re: USB generic hid for VB.NET does not read continuously
« Reply #2 on: November 21, 2019, 11:49:49 am »
Hi Jan,

thanks for your reply.
Can you help me, how can I edit the source code to read reports continuously.

Can you show me a this with a small code?

thnaks for advanced
Frank

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2927
    • Lakeview Research
Re: USB generic hid for VB.NET does not read continuously
« Reply #3 on: November 21, 2019, 12:27:00 pm »
In the ExchangeInputAndOutputReports routine, delete the code that writes a report. Leave the code that reads a report.

Frank Neumann

  • Member
  • ***
  • Posts: 17
Re: USB generic hid for VB.NET does not read continuously
« Reply #4 on: November 21, 2019, 02:19:33 pm »
Hi Jan,

sorry but I don't know what you mean.
Shall I delete this part?

 fileStreamdevicedata.Write(outputReportBuffer, 0, outputReportBuffer.Length)

I yes, than I can not sent data to device.

BR
Frank

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2927
    • Lakeview Research
Re: USB generic hid for VB.NET does not read continuously
« Reply #5 on: November 21, 2019, 05:32:41 pm »
Remove this entire If...End If construction

If (MyHid.Capabilities.OutputReportByteLength > 0) Then

Frank Neumann

  • Member
  • ***
  • Posts: 17
Re: USB generic hid for VB.NET does not read continuously
« Reply #6 on: November 21, 2019, 09:38:38 pm »
Hi Jan,

I have edit like below in the code, but doesn't works.


Code: [Select]
Try
            success = False


            If (Not (hidHandle.IsInvalid)) Then

                'If (MyHid.Capabilities.OutputReportByteLength > 0) Then

                Array.Resize(outputReportBuffer, MyHid.Capabilities.OutputReportByteLength)

                outputReportBuffer(0) = 0

                outputReportBuffer(1) = CByte(1) 

                If UBound(outputReportBuffer) > 1 Then
                    outputReportBuffer(2) = CByte(1)
                End If

                outputReportBuffer(3) = CByte(255)
                outputReportBuffer(4) = CByte(255)
                outputReportBuffer(5) = CByte(255)
                outputReportBuffer(6) = CByte(255)
                outputReportBuffer(7) = CByte(255)
                outputReportBuffer(8) = CByte(255)
                outputReportBuffer(9) = CByte(255)
                outputReportBuffer(10) = CByte(255)
                outputReportBuffer(11) = CByte(1)
                outputReportBuffer(12) = CByte(2)
                outputReportBuffer(13) = CByte(0)
                outputReportBuffer(14) = CByte(0)


                If (fileStreamdevicedata.CanWrite) Then
                    fileStreamdevicedata.Write(outputReportBuffer, 0, outputReportBuffer.Length)
                    success = True
                Else
                    CloseCommunications()
                    ' lstResults.Items.Add("The attempt to read an Input report has failed.")
                End If


                'If success Then

                '    ' lstResults.Items.Add("An Output report has been written.")

                '    ' lstResults.Items.Add(" Output Report ID: " & String.Format("{0:X2} ", outputReportBuffer(0)))
                '    '  lstResults.Items.Add(" Output Report Data:")

                '    'txtBytesReceived.Text = ""
                '    'For count = 1 To UBound(outputReportBuffer)

                '    '    'byteValue = String.Format("{0:X2} ", outputReportBuffer(count))
                '    '    ' lstResults.Items.Add(" " & byteValue)

                '    'Next count
                'Else
                '    CloseCommunications()
                '    ' lstResults.Items.Add("The attempt to write an Output report failed.")
                'End If


                'Else
                ' lstResults.Items.Add("The HID doesn't have an Output report.")
                'End If

                success = False


                If (MyHid.Capabilities.InputReportByteLength > 0) Then

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

                Dim ar As IAsyncResult = Nothing
                transferInProgress = True

                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 If

        Catch ex As Exception
            DisplayException(Me.Name, ex)
            Throw
        End Try

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2927
    • Lakeview Research
Re: USB generic hid for VB.NET does not read continuously
« Reply #7 on: November 22, 2019, 08:21:25 pm »
Use single-stepping or other debugging tools to isolate where the code is failing.

Frank Neumann

  • Member
  • ***
  • Posts: 17
Re: USB generic hid for VB.NET does not read continuously
« Reply #8 on: November 23, 2019, 12:27:33 am »
Hi,

shall I put this part in a Timer for to read reports continuously?
see below

Code: [Select]
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Dim inputReportBuffer() As Byte = Nothing

        Dim i As Integer
     

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

        Dim ar As IAsyncResult = Nothing
       
     
        fileStreamdevicedata.BeginRead(inputReportBuffer, 0, inputReportBuffer.Length, New AsyncCallback(AddressOf GetInputReportData), inputReportBuffer)

    End Sub

I have Remove this entire If...End If construction

If (MyHid.Capabilities.OutputReportByteLength > 0) Then
as you said but the staus was the same.
First write
second read

BR
Frank

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2927
    • Lakeview Research
Re: USB generic hid for VB.NET does not read continuously
« Reply #9 on: November 23, 2019, 11:57:36 am »
Yes, you can use a timer.