USB data received packets...

USB PICs and the UBW

Moderator: phalanx

Post Reply
Posts: 2
Joined: Thu May 16, 2013 10:45 am

USB data received packets...

Post by dtvonly » Thu May 16, 2013 10:51 am

Please see attached simple sample USB code. One part I do not understand is how the received data is placed in the 2nd element in the btnGetPBState_Click subroutine? Please clarify. The code did not take me to the correct definition of the Read routine therefore I don't know how the received data is placed in the USB received buffer. thank you in advance.

Code: Select all

Imports HIDLibrary
Imports System.Threading

Public Class Form1

    Dim HidDeviceList As HIDLibrary.HidDevice()
    Dim AnyHidDevice As HidDevice
    Dim HidDevice_detected As Boolean

   Private Sub btnGetPBState_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetPBState.Click

        Dim OutData(AnyHidDevice.Capabilities.OutputReportByteLength - 1) As Byte
        'Dim InData(AnyHidDevice.Capabilities.InputReportByteLength - 1) As Byte
        Dim DataFromTarget As HidDeviceData

            If Not AnyHidDevice.IsOpen Then
            End If
            OutData(0) = &H0
            OutData(1) = &H81
            AnyHidDevice.Write(OutData) 'Send out report to get push button state

            DataFromTarget = AnyHidDevice.Read(250) 'Get input report
            If DataFromTarget.Data(2) = 0 Then 'Element 2 contains the button state ??????? how????
                Label1.Text = "Pressed"
            ElseIf DataFromTarget.Data(2) = 1 Then
                Label1.Text = "Not Pressed"
            End If

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

User avatar
Edward Ronald
Posts: 7
Joined: Sat Jun 01, 2013 12:43 am

Re: USB data received packets...

Post by Edward Ronald » Thu Jun 13, 2013 9:43 pm

Thanks for sharing valued information with source code. This is acknowledging for me and helpful to save my precious record.

Post Reply