UART TIMEOUT


Author Message
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 12:38am 23 Sep 2019      

Frank,

This may not be the most elegant way and does not cater for day over-run but it may give you some ideas.

It is a blocking routine (that is, it loops internally for the timeout period). A neater solution would be to do something with flags.


Option explicit
dim S_Timeout,s_port

print "Wait for 10 seconds then print all characters waiting in Rx buffer"
' example: call routine, wait 10 seconds then print all characters
'   entered from console (s_port = 0)
print SerIn$(10,0)

function SerIn$(S_timeout,s_port)
' function to wait S_Timeout seconds from current time and
' return all characters waiting in Rx buffer of COM port s_port
' Note: this is a blocking routine
 local tout,start_secs,s_chars$
 tout = S_timeout
 start_secs = T_now()
 do
 loop while T_now() < start_secs + tout
 s_chars$ = input$(255,s_port) ' will get up to 255 characters from com port
 SerIn$ = s_chars$
end function
   
Function Time_now(arg1) ' arg1 unused
' returns current time in seconds, does not cater for day over-run
 local t_n
 t_n=(val(left$(time$,2))*3600)+(val(mid$(time$,4,2))*60)+val(right$(time$,2))
 T_now = t_n
end function


panky
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!