Shop OBEX P1 Docs P2 Docs Learn Events
Bs1 -- serin — Parallax Forums

Bs1 -- serin

PJAllenPJAllen BannedPosts: 5,065
edited 2005-12-01 21:52 in BASIC Stamp
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?


' {$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

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2005-12-01 21:42
    Guess I'm going to have to have a conversation with myself.

    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.]
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-12-01 21:52
    Here's another option that requires one more line of code, but means that your string doesn't have to end with a non-numeric character (this works if the string ends in one digit):

    · SERIN Sin, Baud, ("PHASE"), state
    · state = state - "0"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.