Shop OBEX P1 Docs P2 Docs Learn Events
SERIN string match? — Parallax Forums

SERIN string match?

astropaulastropaul Posts: 17
edited 2006-07-20 01:05 in BASIC Stamp
Hi,
I am processing SERIN data, and want to perform a different task depending on the incoming command.
Say my command is "get temp" or "put led,1"
So the first 3 chars could be get or put. How can I match on the first three chars?

IF buffer(3) = "get"

doesn't work. It only wants to process the first byte of the array.
How do I compare multi byte strings?
Thanks,
Paul

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-20 00:23
    Paul -

    PBASIC has very little in the way of string handling. Why not just limit the command to one character ("G" or "P") that simplifies the process immensely.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-07-20 01:05
    Two characters as a command are pretty easy, too, as you can define word size constants that consist of two bytes but compare as one word:

    [noparse][[/noparse]code]GT CON "G'" * 256 + "T" ' command "%GT", "%" is command tag
    PL CON "P" * 256 + "L" ' "%PL"

    command VAR word
    cmd0 VAR command.byte0 ' alias byte 0
    parameter VAR word


    DEBUGIN WAIT("%"),STR cmd0\4 ' reads in both command and parameter words
    LOOKDOWN command,[noparse][[/noparse]GT,L1],cmd0 ' convert to index
    BRANCH cmd0,...... ' branch on index, parameter intact[noparse][[/noparse]/tag]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.