repeat until i==1023 works, but repeat until i==1024 or false does not in Serial Terminal
zepperik
Posts: 16
I've got a cog listeningto the Parallax Serial Terminal object. I am sending 1024 bytes to it to construct a waveform. I've been struggling to get it to timeout if for whatever reason all 1024 bytes aren't sent. I've added " or (cnt-t>TIME_OUT) " to CharIn which seems to work fine. (Yes I know about RxTime in FullDuplexSerial). But now that I've got the repeat loop within CharIn timing out correctly, I need the loop within my function to timeout so that I can set i to 0 again.
I've replaced my timeout condition "or (cnt-t>TIME_OUT)" with "or false" and it still changes the behavior. This code works correctly if "or false" is not present. Any idea how that addition could possibly change the behavior?
I have increased MAXSTR_LENGTH in case you were wondering.
I've replaced my timeout condition "or (cnt-t>TIME_OUT)" with "or false" and it still changes the behavior. This code works correctly if "or false" is not present. Any idea how that addition could possibly change the behavior?
PUB Listener | i repeat i:=0 repeat until i==1023 or false byte[@Waveform+i]:=Pst.CharIn i++ ConstructOutput(@Waveform)
I have increased MAXSTR_LENGTH in case you were wondering.
Comments
just another question, what does "or false" do there ?
I did. Its at 2000 longs.
I started with a code similar to RxTime which is looks like :
I added the second condition to the end of my repeat until i==1023 and it didn't work. It just stops in the middle of incrementing "i" like the buffer disappears. In trying to diagnose, I changed the second condition to just say false so that it really should have no effect, but it does.
I must be overflowing the rx buffer whenever I slow down grabbing bytes. I just noticed that although I was able to set BUFFER_LENGTH to 2048 in FullDuplexSerial, I cannot do it in Parallax Serial Terminal. I'll try to rewrite it so that I grab 128 bytes at a time and see if that works.
Note that your loop is ending one iteration too soon. As for the "false" issue, no idea...
To answer Ale's question, == has higher precedence than or.
Also, Seairth is right: change 1023 to 1024.
Finally, how exactly does or false "change the behavior" ?
-Phil
I've got it working pretty well now that I've slowed down the communication. I've got Matlab on the other end of the port. I've found that sending the bytes one at a time in a for loop takes about 1 second to execute and the Parallax sees all the data. If I send the entire 1024 bytes at once, Parallax seems to drop the data.
I suppose this makes sense if the buffer in the Parallax Serial Terminal is overflowing. Should I set BUFFER_SIZE to 256 bytes and send chunks with a response in between? (I was going to delete the post in fear that I haven't been helpful in posting but I don't see a delete button. Maybe I should change the title to be more relevant?)
For example, if you changed your initial assignment to i := 1022 the code inside the repeat would only execute once:
(check i (1022) < 1023) succeeds.
byte[@Waveform+1022]:=Pst.CharIn
i++ (i is now 1023)
(check i (1023) < 1023) fails, loop exits.
Well, it'll make it slower.
Try it without the "or (cnt - t) / (clkfreq / 1000) > ms"
-Phil
-Phil
(Oh! the S for stikeout doesn't work in code blocks.)