Shop OBEX P1 Docs P2 Docs Learn Events
SKIP command on BS2 — Parallax Forums

SKIP command on BS2

JomsJoms Posts: 279
edited 2008-02-16 00:53 in BASIC Stamp
I am trying to use the SKIP command in a Serial In application on a BS2.· What I am trying to do is skip like the first 8 hex charators that come in, store the next two, then skip the rest.· I can't seem to make it work right as everytime I add the skip command I start getting garbage for the rest of the string.· Please let me know if you have any idea on where I can look for information about this.· The help file didn't seem too 'helpful'.


And a big thank you to Terry_Bear for all the help on the last question I asked.· I couldn't find that topic back today.· Thanks!

Comments

  • KyeKye Posts: 2,200
    edited 2008-02-15 01:03
    I can't answer how to fix your problem with the skip command, but if you use a buffer variable to store the unneeded infomation you can easily get arround many problems.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye
  • JomsJoms Posts: 279
    edited 2008-02-15 01:43
    OK, I have been playing with storing the entire line of code in a Byte Variable. Maybe I do not understand this correctly because I can't seem to find a way to just see that data. In the end I am trying to take two charaters of HEX out of that line and make an output either high or low depending on what it says. (the answer will always be one of four)...
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-15 03:14
    Hi, can you attach your code and describe what information you are expecting to receive.

    Jeff T
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-15 05:14
    Joms -

    Unless I miss my guess as to what you have, the sub-parameter SKIP 4 should do what you need, if the rest of the SERIN statement is correct. There are TWO characters in each "HEX" byte. Thus, if you say you want to bypass "first 8 hex charactors that come in" that represents 4 characters of actual BYTE data.

    Additional information about the various SERIN formatters can be found in the PBASIC Reference Manual, or the PBASIC Help File near the end of the SERIN section.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison
  • terry_bearterry_bear Posts: 84
    edited 2008-02-15 15:38
    Joms,

    You're welcome; if any one of my thoughts is helpful, great. Otherwise, just ignore it!

    Bruce appears to have nailed the problem. That sort of thing ha a lot of people confused, and even the un-confused ones count characters vs. bytes incorrectly...

    Terry
  • terry_bearterry_bear Posts: 84
    edited 2008-02-15 15:39
    Joms,

    You're welcome; if any one of my thoughts is helpful, great. Otherwise, just ignore it!

    Bruce appears to have nailed the problem. That sort of thing ha a lot of people confused, and even the un-confused ones count characters vs. bytes incorrectly...

    Terry
  • JomsJoms Posts: 279
    edited 2008-02-15 20:59
    Below is my code that I have been using. I think that it is actually 24 Bytes of incoming information. I really only want to save the bytes 9 & 10 and ignore everything else because it is not used other then to fill up useful RAM. Also, I am then trying to compair those two bytes and turn an output on depending on what value they have. That is another place I am having a problem, I can not find what format it wants those numbers in.

    When I inserted the SKIP 4 command it actually just scrambles the data when it debugs it. Also, In my final product I will not be using the Debug command as I just want it compair the data.

    Thanks for all the ideas so far, I need all the help I can get...


    '{$STAMP BS2}
    '{$PBASIC 2.5}

    test VAR Byte(24)

    DO

    IF IN7=1 THEN
    SEROUT 0, 16468, [noparse][[/noparse]06,01,78,48,81,74,09,48,48,48,48,09,49,53,04]
    DO
    LOOP UNTIL IN7=0
    SERIN 1, 16468, [noparse][[/noparse]SKIP 4, STR test\24]
    PAUSE 15
    DEBUG STR test
    ENDIF

    IF TEST = (***Dont understand what format goes here***) THEN
    LOW 14
    ELSE
    HIGH 14
    ENDIF

    LOOP
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-15 23:14
    Hi Joms, you don't mention what device is sending the data, it's possible the baud constant should be true which would be 84, so thats worth trying. Maybe to begin you could try capturing the first 12 bytes, repeat several times and see if you get the same results. Forget the SKIP instruction for now you can deal with that when you are confident you are receiving the right data. Try the following modifications and make a note of the data you get each time.

    SEROUT 0, 84, [noparse][[/noparse]06,01,78,48,81,74,09,48,48,48,48,09,49,53,04]
    DO
    LOOP UNTIL IN7=0
    SERIN 1, 84, [noparse]/noparse]STR test\[b]12[/b

    Jeff T.
  • JomsJoms Posts: 279
    edited 2008-02-15 23:34
    THAT WORKED!... I messed around with it and finally figured out that I have to settle for 4800K or "16572" in the programing. I did change those setting on the sending unit aswell. I must have just been flooding the stamp with too much data, too fast.

    However...

    The problem I am still having is that I cant seem to find out what for to put the compair. When I run this script I now get "4C" on the display which is what I am expecting. I just cant find what form it wants that data in. My next test will be to make a second variable and try to compair the two. Hopefully I can find away around this as I plan on using the rest of the variables for something else. Please let me know if you have any ideas.

    IF TEST = (tried "4C", tried 5267) THEN
    LOW 14
    ELSE
    HIGH 14
    ENDIF
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-16 00:42
    Joms -

    You probably want to use a hexadecimal constant. The way you specify hexadecimal is with the $ character. Here's what it would look like in your program:

    IF test = $4C THEN ...

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison
  • JomsJoms Posts: 279
    edited 2008-02-16 00:53
    BRUCE YOU NAILED IT! I did get it to work that way. I did have to make a little modification for the second byte. This is how my code looks now:

    IF TEST(0)=$30 AND TEST(1)=$37 THEN
    LOW 14
    ELSE
    HIGH 14
    ENDIF
Sign In or Register to comment.