Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9630
Posted: 04:54am 14 Oct 2022
Copy link to clipboard
Print this post
Interesting loopy problem.
Have isolated it down to this bit of code, which if you run, it will NOT wait till the timer is greater then or equal to the delay period. The loop exits within 2-3ms - it does not wait for 7000ms as I want it to.
MM2 chip, MMBASIC version 5.0501
Y=0 TIMER=0 DELAY=7000 Open "COM2:2400" as #2 Print TIMER,DELAY,LOC(#2) DO If LOC(#2) THEN Y=1 EXIT DO LOOP UNTIL TIMER>=DELAY Print "Hello." Print Timer,DELAY,LOC(#2)
The code should NOT exit the do loop, if there is nothing in the COM2 buffer, and there isn't. It is zero before the loop, and zero after the loop, but the loop just exits as though there IS something in there.
The debug print lines show 1 7000 0 at the start, and 4 7000 0 at the end, so the timer is only at 4ms, but the loop is exiting anyway, despite LOC(#2) still being zero.
Can someone please test this code snippet and tell me if they get the same issue.
The problem can be totally solved, if I simply comment out the two lines inside the loop that check if there is anything inside the serial port buffer, but I need to be checking this....
EDIT: Fixed it with a rewrite, but I would still like to know what I was doing wrong in the above.
The fix:
Y=0 TIMER=0 DELAY=7000 Open "COM2:2400" as #2 Print TIMER,DELAY,LOC(#2) DO:LOOP UNTIL TIMER>=DELAY or LOC(#2) Print "Hello." Print Timer,DELAY,LOC(#2)
Edited 2022-10-14 14:59 by GrogsterSmoke makes things work. When the smoke gets out, it stops!
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2446
Posted: 05:15am 14 Oct 2022
Copy link to clipboard
Print this post
i think the error may be in the two lines:
If LOC(#2) THEN Y=1 EXIT DO
they should be either:
If LOC(#2) THEN Y=1: EXIT DO
or:
If LOC(#2) THEN Y=1 EXIT DO END IF
cheers, rob :-)
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1270
Posted: 05:27am 14 Oct 2022
Copy link to clipboard
Print this post
try this
t=Timer delay=7000 Print Timer,delay Do Loop Until Timer >=t+delay Print "Hello."
(i left out the Com Section)
Reg. Mart!n Edited 2022-10-14 15:28 by Martin H.'no comment
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1642
Posted: 05:29am 14 Oct 2022
Copy link to clipboard
Print this post
Yes
DO If LOC(#2) THEN Y=1 EXIT DO LOOP UNTIL TIMER>=DELAY
EXIT DO is not controlled by the IF/THEN it is just the next statement to be executed
EDIT:
If LOC(#2) THEN : Y=1 : EXIT DO : endif
works
Bill Edited 2022-10-14 15:39 by Turbo46Keep safe. Live long and prosper.
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9630
Posted: 05:43am 14 Oct 2022
Copy link to clipboard
Print this post
D'OH!!!
Damn it! I should have seen that....
Thanks to everyone for all the suggestions.
Naturally, the damn code does EXACTLY what I told it to do, and exits the loop after checking the COM2 buffer! Whoopsie!
I've spent too much time on code today.Smoke makes things work. When the smoke gets out, it stops!
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171
Posted: 06:44am 14 Oct 2022
Copy link to clipboard
Print this post
Edit: memo to self... must read further into the post before replying - I just added my voice to the crowd Edited 2022-10-14 16:47 by CaptainBoing
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9630
Posted: 12:25pm 14 Oct 2022
Copy link to clipboard
Print this post
I'm guilty of doing THAT also, so I'm in good company! Smoke makes things work. When the smoke gets out, it stops!
Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646
Posted: 10:52am 15 Oct 2022
Copy link to clipboard
Print this post
@Grogster
But it's always nice to find that Mite hardware/firmware is not to blame.
Not a big deal to us but my client is still amazed that the only times that his E-100s get powered down is during Xmas and Summer breaks.
Not true for his megabuck Siemens/Windows laser machines.
Craig
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9630
Posted: 09:34am 16 Oct 2022
Copy link to clipboard
Print this post
That's really nice to hear - that a wee E100 board with MMBASIC can basically out-perform the super expensive alternatives. Smoke makes things work. When the smoke gets out, it stops!