SPIN newbie needs help with REPEAT UNTIL
K6MLE
Posts: 106
in Propeller 1
Here is the code I've got so far (snip of the pertinent section):
text.Start(12)
pst.StartRxTx(9,6,0,2_400)
BYTEFILL(@inbuf,0,bufsize)
repeat until inbuf[0] == $24
pst.StrIn(@inbuf) ' read the rxpin until CR encountered.
' repeat
WindSpeed
Temperature
WindDir
RainGuage
What I'm expecting is for the four routines to display Speed, Temp, Dir & Rain only when there is a valid read of the serial port (looking for "$"). Otherwise I want the program to just sit and wait for the incoming "$". The way it's written now, I get one pass through the program and no more. I'm confused with the nesting of the REPEAT commands.
text.Start(12)
pst.StartRxTx(9,6,0,2_400)
BYTEFILL(@inbuf,0,bufsize)
repeat until inbuf[0] == $24
pst.StrIn(@inbuf) ' read the rxpin until CR encountered.
' repeat
WindSpeed
Temperature
WindDir
RainGuage
What I'm expecting is for the four routines to display Speed, Temp, Dir & Rain only when there is a valid read of the serial port (looking for "$"). Otherwise I want the program to just sit and wait for the incoming "$". The way it's written now, I get one pass through the program and no more. I'm confused with the nesting of the REPEAT commands.

Comments
-Phil
can only work if another cog overwrites inbuf[0], but I think that is not the case here.
so you need something like that:
repeat inpuf[0] = pst.CharIn until inbuf[0] == $24or simpler:
Andy
PUB Main nbr.init DIRA[2..0] := %111 ' Set as outputs. DIRA[23..16] := %11111111 ' Set as outputs text.Start(12) pst.StartRxTx(9,6,0,2_400) BYTEFILL(@inbuf,0,bufsize) repeat until inbuf[0] == $24 pst.StrIn(@inbuf) ' read the rxpin until CR encountered. ' repeat WindSpeed Temperature WindDir RainGuageThis is the code for Main.
repeat pst.StrIn(@inbuf) if inbuf[0] == $24 WindSpeed Temperature WindDir RainGaugeYou want to keep reading lines from the serial terminal indefinitely which .StrIn does for you. If a line starts with "$" you want to display stuff. That's all. The initialization stuff is the same.