UART TIMEOUT


Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 3426
Posted: 02:37am 23 Sep 2019      

It depends a lot on the flow of the rest of the program.

This routine uses the console as input but a serial port would be much the same.
Instead of k$=INKEY$, use IF LOC(#1) > 0 THEN doKEY

I choose to check for input in the main loop instead of using interrupts because the program is doing time critical things and I don't want them interrupted.

SUB doKey is entered when there is at least one character available.
It then loops through, gathering additional characters until
there is a LF indicating end of data or
empty k$ indicating data flow has stopped or
more than 20 characters have been received because in this setup, that would be an error condition or
there has been more than 500 * 2 mS

The size of the delay needs to match the baud rate and take into account any delays in the sending device (such as manual key entry)

Remove any condition tests that don't suit your data input method.

  Quote    DO
   
IF readNow = 1 THEN doread
   
IF loopNow = 1 THEN doLoop
   
'if debugNow = 1 then debugSub
   IF quit = 1 THEN EXIT DO
   k$=
INKEY$
   
IF k$ <> "" THEN doKey
   
 
LOOP
 
END
 
'
SUB doKey
 cmd$ =
""
 w =
0
 
DO
   
PAUSE 2
   cmd$ = cmd$+k$
   k$=
INKEY$
   w = w +
1
 
LOOP UNTIL k$="" OR k$ = lf$ OR LEN(cmd$)>=20 OR w > 500
 DoCMD
END SUB
 
SUB DoCMD
 
LOCAL temp$
 cmd$ =
UCASE$(cmd$)
 
'print #1, cmd$+cr$
 IF cmd$ = lf$ THEN ' wake up call
   PRINT cr$;
 
ENDIF
 
' etc
END SUB
 


Jim
It all started with the ZX81....
VK7JH
http://www.c-com.com.au/MMedit.htm