Bs1 -- serin
PJAllen
BannedPosts: 5,065
With the BS1, I'm trying to use SERIN with the # formatter.
I have a device which is sending out, constantly,·one of three messages: PHASE0, PHASE3, or PHASE8 (verified this.)
The "receiver", another unit with the program below, waits for a given message and branches from there (based on the number following PHASE.)
I thought that by using the # formatter that it would place in the variable (ST) either 0, 3, or 8, but instead I end up with 59, 103, 91, respectively.
So, I modified my program to look for 59, 103, 91.· At that point it branches, as I'd like, but only every other time, sort of.
If I send PHASE8 and then PHASE3, then it'll branch to Phs8G after it receives the PHASE3 message.· If I send it PHASE8 then another PHASE8, then it'll branch to the Phs8G subroutine after it receives the second PHASE8 message (and likewise with a double PHASE3.)
So:
Why doesn't ST = 0, 3, or 8 (instead of 59, 103, or 91)?
Why does it skip like?
I have a device which is sending out, constantly,·one of three messages: PHASE0, PHASE3, or PHASE8 (verified this.)
The "receiver", another unit with the program below, waits for a given message and branches from there (based on the number following PHASE.)
I thought that by using the # formatter that it would place in the variable (ST) either 0, 3, or 8, but instead I end up with 59, 103, 91, respectively.
So, I modified my program to look for 59, 103, 91.· At that point it branches, as I'd like, but only every other time, sort of.
If I send PHASE8 and then PHASE3, then it'll branch to Phs8G after it receives the PHASE3 message.· If I send it PHASE8 then another PHASE8, then it'll branch to the Phs8G subroutine after it receives the second PHASE8 message (and likewise with a double PHASE3.)
So:
Why doesn't ST = 0, 3, or 8 (instead of 59, 103, or 91)?
Why does it skip like?
' {$STAMP BS1} ' {$PBASIC 1.0} ' INs: P4 = SERIN ' OUTs: P0 = Phs3 G LED, P1= Phs8 G LED, P2 = Timer Trigger SYMBOL ST = B0 DIRS = $0F 'P0-3 = OUT, P4-7 = IN PINS = %00000000 ST = 0 Listen: SERIN 4,T1200,("PHASE"), #ST IF ST = 103 THEN Phs3G 'got NAME 1 IF ST = 91 THEN Phs8G 'got NAME 2 GOTO Neither 'default NAME0 Phs3G: PIN0 = 1 'Status1 LED on PULSOUT 2,10 'TRG '123 GOTO Listen Phs8G: PIN1 = 1 'Status2 LED on PULSOUT 2,10 'TRG '123 GOTO Listen Neither: PIN0 = 0 PIN1 = 0 GOTO Listen
Comments
Looking at the HELP, reallying studying on it, I see that my transmitted message must end with a NON-numeric character.
When I end with a NON-numeric character, then I DO get 0, 3, or 8·stashed in·my variable (ST) AND it executes each time [noparse][[/noparse]no more skipping.]
· SERIN Sin, Baud, ("PHASE"), state
· state = state - "0"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax