Hi,
I am trying to figure out how to use the USART.DataAvailableTimeout
command to read in a undetermined amount of bytes from the USART and store them to my SD card. Can someone show me a example on how to use this as a timeout to know when the data has stopped coming in.
Thanks for the help
What I am trying to get to work:
1 sit idle waiting for charcters to start coming into the USART RX pin
2 Open a File on the SD card and start writing the bytes
3 when the data stops then close the file
USART Question
Moderators: David Barker, Jerry Messina
This might work for you...I use it for my gps logger:
Code: Select all
Function NMEA_SENTENCE(pHEADER As String) As String * 100
Dim GPS_CHAR As Char
Dim GPS_CHARPOS As Byte
Dim GPS_RXBUFFER_LENGTH As Byte
GPS_RXBUFFER_LENGTH = 100
If WaitForStrTimeout(pHEADER,2500) = True Then
GPS_CHARPOS = 0
While True ' Create a loop to receive the serial string
GPS_CHAR = USART.ReadByte() ' Receive a character serially
RESULT(GPS_CHARPOS) = GPS_CHAR ' Store Character
Inc(GPS_CHARPOS) ' Increment the index
If GPS_CHAR = #13 Or GPS_CHAR = #10 Then
Break ' Exit the loop if the string reaches the end
EndIf
If GPS_CHAR = "*" Then
GPS_RXBUFFER_LENGTH = GPS_CHARPOS + 1 ' Set Test to get 2 more characters
EndIf
If GPS_CHARPOS > GPS_RXBUFFER_LENGTH Then ' Terminate reading
RESULT(GPS_CHARPOS) = NULL
Break ' Repeat the loop until the buffer runs out
EndIf
Wend
Else
UART.Write("USART TIMEOUT = ",RESULT,13,10)
EndIf
RESULT = pHEADER + RESULT
End Function