Author Topic: [SOLVED] Uart0Receive() Read  (Read 863 times)

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Uart0Receive() Read
« on: June 18, 2016, 01:12:42 pm »
We had previous problems with 1000000 baud where it lost characters but we have a large application with 115200 and that works fine. Just watched your video and it looks like that you don't handle the -1 correctly. The event is not related to the fact that there is one character in the queue, it just indicates that there "could" be something in the queue. So you should always filter the -1 out. Placing the characters in a ListOfByte provides you with "readable information" See example below:
Code: [Select]
    Shared Event Uart0Receive()
        Dim chr As Integer = ser.Read
       
        While chr >= 0
           
            serBuf.Add(chr.ToByte)
           
            'check To see If end of message ("OK\r\n")
            If serBuf.Count> 20 Then
                If serBuf(serBuf.Count- 1) = 0x0a And serBuf(serBuf.Count- 2) = 0x0d And serBuf(serBuf.Count- 3) = 0x4b And serBuf(serBuf.Count- 4) = 0x4f Then
                    'If serBuf(serBuf.Count- 1) = 0x4f Then
                    Dim serString As String = serBuf.ToString()
                    serBuf.Clear()
                    ParseAndSendLapMessage(serString)
                    'increment message group
                    gMessageGroup = gMessageGroup + 1
                    If gMessageGroup > 3 Then
                        '2 bit number, if 3 then roll over to 0
                        gMessageGroup = 0
                    End If
                    'turn off ESP and Sigfox radio
                    rf_pwr_on = False
                    wifi_en = False
                    wifi_rst = False
                   
                End If
            End If
           
            chr = ser.Read()
        End While
       
    End Event