Posted: 08:13am 23 Sep 2019 |
|
|
|
for serial time out
Option EXPLICIT
const maxto = 500 'exemple time out 5 sec dim cptto as integer 'count time$ dim flgeot as integer
SETTICK 10,sptim Open "COM1:9600,255,spcomrec" As #2
flgeot=0
do
' if need to read serial cptto=maxto .... if flgeot=1 then flgeot=0 ..... 'task receive text end if ' ... 'if no need read serail cptto=0
loop
sub sptim if cptto>0 then 'if cptto=0 then do nothing cptto=cpto-1 if cptto=0 then 'if end of time-out do task "timeout" .... end if end if end sub
sub spcomrec Local tx$ As string Local i2 As integer Local a$ As string length 1 nbcar=Loc(#2) If nbcar>0 Then tx$=Input$(nbcar,#2) cptto=maxto 'do task read serial 'exemple For i2=1 To nbcar a$=Mid$(tx$,i2,1) If (asc(a$)=13 or asc(a$)=10) Then 'end rec texte ..... flgeot=1 end if next i2 end if end sub
Edited 2019-09-23 18:19 by goc30 |