Shop OBEX P1 Docs P2 Docs Learn Events
SX/B Equivalent/s for WAIT — Parallax Forums

SX/B Equivalent/s for WAIT

PJAllenPJAllen BannedPosts: 5,065
edited 2007-02-06 23:28 in General Discussion
Anybody have an SX/B equivalent for the PBASIC formatter WAIT (for SERIN)?

Comments

  • BeanBean Posts: 8,129
    edited 2007-02-03 04:40
    There isn't one. You just have to read characters until you get the one you are waiting for.

    DO
    · SERIN sPin, BAUD, char
    LOOP UNTIL char = "!"

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-02-03 13:16
    OK, Bean.· Thought it'd be something like that.· I'll have to go with it and see what happens then.· Was hoping there was a clever angle I'd overlooked.

    Henry Casson -- you could have Deleted your Post/s by clicking the Delete (Red-X) button.· It's next to the Pencil (edit) button.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-02-05 19:42
    Here's how we (EFX-TEK) do that with our little accessory products; this code is for something we probably won't build (serial to KIT-74 interface), but the code is identical in our RC-4, DC-16, and AP-8.

    You can see the code at Main waits for a specific header (!K74) before moving on.

    ' =========================================================================
    '
    '   File...... K-74.SXB
    '   Purpose... Serial to KIT-74 Adapter (EFX-TEK K-74, #31274)
    '   Author.... Jon Williams / John Barrowman
    '              Copyright (c) 2005-2006 EFX-TEK
    '              Some Rights Reserved
    '              -- see http://creativecommons.org/licenses/by/2.5/
    '   E-mail.... teamefx@efx-tek.com
    '   Started... 12 SEP 2006
    '   Updated... 31 OCT 2006
    '
    ' =========================================================================
    
    
    ' -------------------------------------------------------------------------
    ' Program Description
    ' -------------------------------------------------------------------------
    '
    ' KIT-74 serial interface control program.
    '
    ' Commands:
    '
    '   "!K74", addr, "V"                     - Returns version string (3 byte)
    '   "!K74", addr, "G"                     - Returns relays status (1 byte)
    '   "!K74", addr, "S", status             - Sets relays to new status
    '   "!K74", addr, "R", relay, status      - Sets selected relay to status
    '   "!K74", addr, "T", msLo, msHi         - test relays (on-off) for ms
    '   "!K74", addr, "B", relay, msLo, msHi  - "blip" relay (on-off) for ms
    '   "!K74", addr, "X"                     - Resets all relays to off
    
    
    ' -------------------------------------------------------------------------
    ' Conditional Compilation Symbols
    ' -------------------------------------------------------------------------
    
    '{$DEFINE TEST_SX28_OFF}                        ' use SX28 for testing
    
    
    ' -------------------------------------------------------------------------
    ' Device Settings
    ' -------------------------------------------------------------------------
    
    '{$IFDEF TEST_SX28}
    DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
    '{$ELSE}
    DEVICE          SX20, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
    '{$ENDIF}
    
    FREQ            20_000_000
    ID              "K74 v0.5"
    
    
    ' -------------------------------------------------------------------------
    ' IO Pins
    ' -------------------------------------------------------------------------
    
    ID0             PIN     RA.0    INPUT           ' id jumpers (%00-%11)
    ID1             PIN     RA.1    INPUT
    BaudSelect      PIN     RA.2    INPUT           ' baud rate select input
    Sio             PIN     RA.3    INPUT           ' serial I/O to host
    
    Relays          PIN     RB      OUTPUT          ' relay outputs (8 bits)
    
    
    ' -------------------------------------------------------------------------
    ' Constants
    ' -------------------------------------------------------------------------
    
    BaudSlow        CON     "OT2400"                ' open true for chaining
    BaudFast        CON     "OT38400"               ' -- match PSC fast baud
    
    AllOff          CON     %00000000               ' for active-high outputs
    CmdAll          CON     $FF                     ' command all devices
    
    Yes             CON     1
    No              CON     0
    
    ToUpper         CON     1
    
    
    ' -------------------------------------------------------------------------
    ' Variables
    ' -------------------------------------------------------------------------
    
    flags           VAR     Byte
    allCall         VAR     flags.0                 ' request for all boards
    
    char            VAR     Byte                    ' character in/out
    devID           VAR     Byte                    ' id of target device
    addr            VAR     Byte                    ' board address (%00-%11)
    idx             VAR     Byte                    ' index pointer
    mask            VAR     Byte                    ' for bit masks
    tmr             VAR     Word                    ' for long timing
    
    tmpB1           VAR     Byte                    ' work vars
    tmpB2           VAR     Byte
    tmpW1           VAR     Word
    
    
    ' =========================================================================
      PROGRAM Start
    ' =========================================================================
    
    
    ' -------------------------------------------------------------------------
    ' Subroutine Declarations
    ' -------------------------------------------------------------------------
    
    RX_BYTE         FUNC    1, 0, 1                 ' receive a byte
    
    TX_BYTE         SUB     1, 2                    ' transmit a byte
    DELAY_US        SUB     1, 2                    ' delay 1 to 65535 uSecs
    DELAY_MS        SUB     1, 2                    ' delay 1 to 65535 mSecs
    
    
    ' -------------------------------------------------------------------------
    ' Program Code
    ' -------------------------------------------------------------------------
    
    Start:
    '{$IFDEF TEST_SX28}
      PLP_C = %00000000                             ' pull-up unused test pins
    '{$ENDIF}
      GOTO Reset_All                                ' clear outputs
    
    
    Main:
      char = RX_BYTE                                ' wait for header
      IF char <> "!" THEN Main
      char = RX_BYTE ToUpper
      IF char <> "K" THEN Main
      char = RX_BYTE
      IF char <> "7" THEN Main
      char = RX_BYTE
      IF char <> "4" THEN Main
    
    
    Check_Addr:
      char = RX_BYTE                                ' rx addr
      allCall = No                                  ' clear global request
      IF char = CmdAll THEN                         ' all call requested?
        allCall = Yes                               '   yes, set flag
        GOTO Get_Cmd                                '   and skip ID check
      ENDIF
      addr = %00                                    ' clear old setting
      addr.0 = ~ID0                                 ' get low bit of address
      addr.1 = ~ID1                                 ' get high bit of address
      IF char <> addr THEN Main                     ' validate
    
    
    Get_Cmd:
      char = RX_BYTE ToUpper                        ' rx command byte
      IF char = "V" THEN Show_Version
      IF char = "G" THEN Get_Status
      IF char = "S" THEN Set_Status
      IF char = "R" THEN Relay_Control
      IF char = "T" THEN Test_Relays
      IF char = "B" THEN Blip_Relay
      IF char = "X" THEN Reset_All
      GOTO Main
    
    
    Show_Version:                                   ' cmd = "V"
      IF allCall = Yes THEN Main                    ' prevent response collision
      DELAY_MS 15                                   ' let host get ready
      idx = 0
      DO
        READINC Rev_Code + idx, char                ' read character
        IF char = 0 THEN EXIT                       ' if 0, we're done
        TX_BYTE char                                ' tx the character
        DELAY_US 52                                 ' add pacing for fast baud
      LOOP
      GOTO Main
    
    
    Get_Status:                                     ' cmd = "G"
      IF allCall = Yes THEN Main                    ' prevent response collision
      DELAY_MS 15                                   ' let host get ready
      char = Relays                                 ' get current status
      TX_BYTE char                                  ' send to host
      GOTO Main
    
    
    Set_Status:                                     ' cmd = "S"
      Relays = RX_BYTE                              ' get new status
      TRIS_B = %00000000                            ' refresh direction reg
      GOTO Main
    
    
    Relay_Control:                                  ' cmd = "R"
      idx = RX_BYTE                                 ' get relay number
      tmpB1 = RX_BYTE                               ' get status
      IF idx >= 1 THEN                              ' check 1 - 8
        IF idx <= 8 THEN
          DEC idx                                  ' make 0 - 7
          mask = 1 << idx                          ' build mask
          IF tmpB1.0 = 1 THEN
            Relays = Relays | mask                  ' activate selected
          ELSE
            mask = ~mask                            ' invert mask
            Relays = Relays & mask                  ' deactivate selected
          ENDIF
          TRIS_B = %00000000                        ' refresh direction reg
        ENDIF
      ENDIF
      GOTO Main
    
    
    Test_Relays:                                    ' cmd = "T"
      tmr_LSB = RX_BYTE                             ' get timing
      tmr_MSB = RX_BYTE
      Relays = %00000001                            ' start with #1
      DO
        DELAY_MS tmr                                ' hold
        Relays = Relays << 1                        ' move to next
      LOOP UNTIL Relays = %00000000
      GOTO Reset_All
    
    
    Blip_Relay:                                     ' cmd = "B"
      idx = RX_BYTE                                 ' get relay number
      tmr_LSB = RX_BYTE                             ' get timing
      tmr_MSB = RX_BYTE
      IF idx >= 1 THEN                              ' check 1 - 8
        IF idx <= 8 THEN
          DEC idx                                   ' make 0 - 7
          mask = 1 << idx                           ' build mask
          Relays = Relays | mask                    ' activate selected
          TRIS_B = %00000000                        ' refresh direction reg
          DELAY_MS tmr                              ' hold
          mask = ~mask                              ' invert mask
          Relays = Relays & mask                    ' deactivate selected
          TRIS_B = %00000000                        ' refresh direction reg
        ENDIF
      ENDIF
      GOTO Main
    
    
    Reset_All:                                      ' cmd = "X"
      Relays = AllOff                               ' all off
      TRIS_B = %00000000                            ' make relays outputs
      GOTO Main
    
    
    ' -------------------------------------------------------------------------
    ' Subroutine Code
    ' -------------------------------------------------------------------------
    
    ' Use: theByte = RX_BYTE { ConvertToUpper }
    ' -- converts "a".."z" to "A".."Z" if "ConvertToUpper" bit 0 is 1
    
    RX_BYTE:
      IF __PARAMCNT = 1 THEN                        ' option specified
        tmpB2 = __PARAM1                            ' yes, save it
      ELSE
        tmpB2 = 0                                   ' no, set to default
      ENDIF
      IF BaudSelect = 1 THEN
        SERIN Sio, BaudSlow, tmpB1                  ' for Prop-1/BS1
      ELSE
        SERIN Sio, BaudFast, tmpB1                  ' for Prop-2/BS2
      ENDIF
      IF tmpB2.0 = ToUpper THEN                     ' convert to uppercase?
        IF tmpB1 >= "a" THEN                        ' lowercase?
          IF tmpB1 <= "z" THEN
            tmpB1.5 = 0                             ' ...yes, make uppercase
          ENDIF
        ENDIF
      ENDIF
      RETURN tmpB1
    
    ' -------------------------------------------------------------------------
    
    ' Use: TX_BYTE theByte
    
    TX_BYTE:
      IF BaudSelect = 1 THEN
        SEROUT Sio, BaudSlow, __PARAM1              ' for Prop-1/BS1
      ELSE
        SEROUT Sio, BaudFast, __PARAM1              ' for Prop-2/BS2
      ENDIF
      RETURN
    
    ' -------------------------------------------------------------------------
    
    ' Use: DELAY_US usecs
    
    DELAY_US:
      IF __PARAMCNT = 1 THEN
        tmpW1 = __PARAM1                            ' save byte value
      ELSE
        tmpW1 = __WPARAM12                          ' save word value
      ENDIF
      PAUSEUS tmpW1
      RETURN
    
    ' -------------------------------------------------------------------------
    
    ' Use: DELAY_MS msecs
    
    DELAY_MS:
      IF __PARAMCNT = 1 THEN
        tmpW1 = __PARAM1                            ' save byte value
      ELSE
        tmpW1 = __WPARAM12                          ' save word value
      ENDIF
      PAUSE tmpW1
      RETURN
    
    
    ' =========================================================================
    ' User Data
    ' =========================================================================
    
    Rev_Code:
      DATA  "0.5", 0
    
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-02-06 03:38
    Thanks, JonnyMac.· By Jove,·I'll bet that you could tell·that I was going to poll for a $GPxxx sentence.·
  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-02-06 23:28
    I didn't know your intent, but you certainly can -- as I did in the attached program (see the GETRMC subroutine).
Sign In or Register to comment.