| Posted: 08:39am 20 Jan 2018 |
Copy link to clipboard |
 Print this post |
|
Hi cs
I try not to use LINE INPUT (or INPUT). It takes away control from your prog. Fine if you are waiting for someone to type something but no timers fire etc so for input in a process flow they are a bit primitive and blunt - you are inside a looping routine inside MMBasic and not in your prog.
I use a similar device (M590) and here are the get and the flush routines I use (and have performed without failure for 2 years on my SMS Gateway)... It isn't rocket-science but I don't get crap left in the buffer. I have removed some lines where I look for specific messages which would only confuse here.
Check the buffer and remove stuff and build up the string yourself, checking for CHR(13) to tell you have a complete line (and discarding other control characters).
Here's my "get stuff from the 3Gmodem" routine... you can pick the bones from it. I build a line in LN$ and finally any data will be in LNBUF$. If no CR was recieved within the timeout, LNBUF$ will be empty. I get one character at a time so I can recieve multiple messages without snipping off the front of the next. saves complex checking and concatenating... the MM is fast enough that this is a mere eye-twinkle and it gives perfect control over where a message ends The only way out is a nice, complete string or a timeout. Any stuff after the string will remain in the buffer until the next pass (or you flush it).
LNBuf$="" DO IF LOC(#GSM)<>0 THEN A$=INPUT$(1,#GSM):C=ASC(A$) SELECT CASE C CASE 13 IF LN$<>"" THEN LNBuf$=LN$ END IF EXIT DO CASE 0 TO 31 CASE ELSE LN$=LN$+A$ END SELECT END IF
IF FlagTest(TOFg) THEN EXIT DO LOOP ClearTOTimer
... parse your string here
Set a timeout counter before hand and then if anything came back it will be in LNBUF$. Note the timeout here is a "everything must complete" timer - it isn't reset each time we get a character - we could get unmitigate-able (its a word now) hang-ups as characters dribble in. We give it something to do and the response must come back at most 7 seconds, say.
For Flushing; I use the same SUB in the code to flush two different devices so just send it the number you opened the com port as (see my #GSM above).
e.g. FlushIO 2
SUB FlushIO(stream) LOCAL STRING A$ DO WHILE LOC(#stream)<>0 PAUSE 50:A$=INPUT$(MIN(255,LOC(#stream)),#stream) LOOP END SUB
might give you some pointers but you have probably tried this. Good luck
oh, and the use of MIN() to ensure we don't get an error on the input might not work on your version of MMBasic... tbh I never had a problem but I understand there was an obscure bug that was fixed in 5.04.08
h
Edited by CaptainBoing 2018-01-21 |