Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp 2e Parse Serial — Parallax Forums

Basic Stamp 2e Parse Serial

Hey All,

I'm trying to get a basic stamp parse serial data from my surround sound receiver, the receiver sends an entire string of data when it does something. Right now, I'm looking for the basic stamp to read "PWR ON" at the end of the string when the receiver turns on and "STANDBY" when it turns off. I can't for the life of me figure out how to have the basic stamp look for those particular words and respond to it (jump to a particular subroutine). :-(

Comments

  • If you know which message is coming next, you can use SERIN's WAIT qualifier, alternately waiting for PWR ON and STANDBY.

    Otherwise, you'll have to read the string into memory, if it's not too long, and parse it there. What else does the string consist of? Is it always the same length?

    -Phil
  • Hey Phil,
    The receiver's string is of varying length, for example, when it turns off, the serial sting is simply "PWSTANDBY" when it turns on (the string is below), the line I need the stamp to read is "PWON"

    Down the road, I would like to be able to have the stamp adjust the gain on the sub when the sound mode changes between 5.1 and Stereo by reading a few of the other lines (MSDIRECT specifically). As it is now, when Dish inserts their stereo commercials/promos, the subwoofer is too loud and could stand to be turned down a few db.

    But, I'm starting slow and want to read the power state of the receiver so I can turn the amp for the sub on and off automatically.

    CVFL 51
    CVFR 51
    CVC 495
    CVSW 445
    CVSL 52
    CVSR 525
    CVSBL 535
    CVSBR 535
    CVSB 50
    CVFHL 50
    CVFHR 50
    MVMAX 98
    MSDIRECT
    DCAUTO
    PSDCO OFF
    PSDRC AUTO
    PSLFE 00
    PSBAS 50
    PSTRE 50
    PSTONE CTRL OFF
    PWON
  • Hey Tom,
    I'm going to try the code in the link you've provided although, I'm curious how the stamp will respond as the string it sends during POST is sent pretty quickly with carriage returns...
    I know I can do this easily with a raspberry pi but, that's CRAZY overkill for this... :-P
  • What baud rate does the receiver use? At 4800 and below, you can use all the SERIN formatting; above 4800 you are pretty much restricted to STR.
  • By itself, the on/off stuff should be pretty easy:
    SERIN port, baud, [WAIT("PW"), value]
    IF (value = "O") THEN
      'Do power on stuff.
    ELSE
      'Do power off stuff.
    ENDIF
    

    -Phil
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2016-11-13 22:42
    The WAIT modifier supports up to 6 characters and it can include both CR and letters. This instruction is pretty good even at 9600 baud once ready and waiting...
    main:
      SERIN port, baud, [WAIT(13,"PWON",13)]
      GOSUB turnon
      SERIN port, baud, [WAIT("PWSTAN")]
      GOSUB turnoff
    goto main
    

    The question about baud rate is critical. Handling input a byte at a time as it comes in for decoding would be best but need a very slow baud rate or else long pacing between received characters. And at high baud rate, the Stamp simply does not have enough conventional or scratch ram to accommodate the whole long string for processing after the fact.
Sign In or Register to comment.