Good afternoon everyone. I made a project using Florian Leitner-Fischer's usb library.
I can send data to the bus 100%, but when i read i get the recieve frame and then my application hangs for some reason.
When i uncomment out "MsgBox(content)" in the event catcher, the program no longer hangs and i cant figure out why. Any help will be greatly appreciated.
I am new to threading so i might be doing something wrong. here is my code.

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim CMD(8) As Byte

        '12 01 00 03 00 00 FF 97 00 00 00 00 00 

        CMD(0) = &H10 'Bridge command 
        CMD(1) = &H4
        CMD(2) = &H0
        CMD(3) = &H3 '
        CMD(4) = &H0
        CMD(5) = &H0
        CMD(6) = &HFF 'device address
        CMD(7) = &H90 
        usbI.write(CMD)

        usbI.startRead()
        readTimer.Start() 'start timing interval of 150

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Start()
        usbI.enableUsbBufferEvent(New System.EventHandler(AddressOf myEventCacher))
    End Sub  

Private Sub readTimer_Tick(sender As Object, e As EventArgs) Handles readTimer.Tick
        readTimer.Stop()
        usbI.stopRead() 'should generate an event if a packet was detected
    End Sub

 Public Sub myEventCacher(sender As Object, e As EventArgs)
        'catch the event 
        Dim content As String = ""
        Dim count As Integer = 0

        '12 73 00 00 FF 99 FF FF 03 00 00 00 00 expected recieve frame from device
        '12 72 00 00 00 00 00 4F 03 00 00 00 00 expected recieve frame from device

        If USBInterface.usbBuffer.Count > 0 Then

            SyncLock USBHIDDRIVER.USBInterface.usbBuffer(USBInterface.usbBuffer.Count - 1)
                Dim currentRecord() As Byte = USBHIDDRIVER.USBInterface.usbBuffer(USBInterface.usbBuffer.Count - 1) 'get the latest frame

                For counter As Integer = 0 To currentRecord.Length - 1
                    If currentRecord(counter) <> 0 Then
                        content += currentRecord(counter).ToString 'get rid of all those zeros
                    End If

                    If counter = 2 Or 4 Or 6 Or 8 Or 10 Then 'separate the bits
                        content += " "
                    End If
                Next
                'MsgBox(content)
                recieved = content
            End SyncLock
        End If
    End Sub

Is it possible that the message box breaks execution long enough for your buffer to catch up?

~WHy don't you try replacing MsgBox(Content) with a call to debug.print(Content) and run it in the debugger. We have had issues with MsgBox acting as a Modal display and not releasing the execution until it is closed.

Thank you for the feed back. I have found that the thread created by the reply sometimes doesnt terminate, so i added Threading.Thread.CurrentThread.Abort() and it seems to be working now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.