Shop OBEX P1 Docs P2 Docs Learn Events
Need help with Strings and SERIN, Maybe even a few lines of sample code??? — Parallax Forums

Need help with Strings and SERIN, Maybe even a few lines of sample code???

Grant_OGrant_O Posts: 36
edited 2006-04-19 22:40 in BASIC Stamp
Hey everyone.
I am trying to·use SERIN·to gather certian string data and match it to Conditional statements.
the strings are "Hello" and "Goodbye".

if the string = "Hello" then the BS2 will go to the lable, Hello:

if·the string = "Goodbye" then the BS2 will go to the lable, Goodbye:

If its something else the BS2 will goto the lable, TryAgain:

I have been trying to figure how to make the BS2 understand these Strings but·I havnt been secessful yet. and the help files dont describe it much. Please help!!!

Thanks.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-19 16:55
    That's not really practical with the BASIC Stamp. You can do a WAIT in SERIN, and look for up to 6 characters that way, but it's not really what you're after. Better to create a byte-code scheme; in my projects I use $C0, $C1, C2, etc. for various commands (hence, the C as a reminder).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-04-19 17:04
    Done VAR BIT
    String1 VAR BYTE(10)

    MAIN:
    GOSUB ClearString
    GOSUB GetString
    Done = 0
    IF String1(0) <> "H" THEN TryNext
    IF String1(1) <> "e" THEN TryNext
    IF String1(2) <> "l" THEN TryNext
    IF String1(3) <> "l" THEN TryNext
    IF String1(4) <> "o" THEN TryNext
    GOTO Hello

    TryNext:
    IF String1(0) <> "G" THEN EndTries
    IF String1(1) <> "o" THEN EndTries
    .
    .
    EndTries:
    GOTO MAIN
    ' etcetera. Well, I hope you get the idea.
    ' You COULD store the "Hello" and "Goodbye" check strings
    ' in a DATA statement, and condense the above code
    ...
    GOTO MAIN
    ' ************** Subroutines ********************
    ClearString:
    FOR I = 0 TO 9
    String1(I) = 0
    NEXT
    RETURN
    GetString:
    SERIN 16, 16384, [noparse][[/noparse]STR String1]
    RETURN
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-19 21:08
    Allan has provided a working solution, albeit code-heavy (not his fault, the BS2 doesn't really support strings). Make sure you that you define your string array to the bare minimum, otherwise your program won't have much variable space left.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Grant_OGrant_O Posts: 36
    edited 2006-04-19 21:57
    Thanks Allen!
    That program worked very well with my application.


    But hey Mr. Williams,
    I'm a little curious about your byte-code scheme. Do you have any information or resources about it? Because variable space is very important as well!
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-04-19 22:13
    Done VAR BIT
    String1 VAR BYTE

    MAIN:

    GOSUB ClearString
    GOSUB GetString

    IF String1 <> "H" THEN TryNext
    GOTO Hello

    TryNext:
    IF String1 <> "G" THEN EndTries
    GOTO Goodbye

    EndTries:
    GOTO MAIN

    ' ************** Subroutines ********************
    Hello:
    ' ... Whatever
    GOTO MAIN

    Goodbye:
    '... More stuff
    GOTO MAIN

    ClearString:
    String1 = 0
    RETURN

    GetString:
    SERIN 16, 16384, [noparse][[/noparse]STR String1] ' Where String1 will be "H" for 'Hello', or "G" for 'Goodbye'
    RETURN

    ' Jon's solution used "bytecodes" of $C0 or $C1 for the input characters,
    ' but you can just as easily use single type-able characters of "H" or "G".
    ' I believe you'll have to send the character with a 'linefeed' character after it,
    ' to tell the BS2 run-time that the "string" is done.
  • Grant_OGrant_O Posts: 36
    edited 2006-04-19 22:40
    Oh ok I understand, Jon was talking about instead of using whole words he uses parts of, or only the first letter of words that represent something. That’s a good way of doing it becuase I may use something like Lab View or Visual Basic with there nice GUIs as the front end control for the BS2s, but even though it takes huge amounts of memory to do this, I am still trying to make a nice user interface (Like a Cisco router) that someone can use with a simple terminal program and have to remember words like Menu, Exit, Motor on/off, Restart... ect to navigate through the functions.

    But hey thanks for all the help!
    I think I have enough now to get started.
Sign In or Register to comment.