identifying text commands


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2014
    Posts
    17

    Default identifying text commands

    I need to have my microcontroller act upon different commands sent. For example if "GC" is sent it turns on a motor. If "GQ" is sent it sends back data.

    I would expect it to be something like this, as many other BASIC languages use:

    hserin [command]
    if command = "GC" then ....

    if command = "GQ" then....

    where the text inside the parentheses is what is compared. How is this done in PicBasic?

    WAIT kind of does that but if I understand its operation correctly the program is suspend waiting for the text string. I need to check to see if anything was received and if so act on it but if not go do other things. I can't suspend everything and wait.

    A STRING variable type would be handy.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516

    Default Re: identifying text commands

    Hi,
    PBP doesn't have a string type variable per se but it does have array type variable which is pretty much the same thing.

    If all your commands are two character command then declare a 2 byte array, like
    Code:
    command VAR BYTE [2]
    Then, once you have the command IN the array you can, for example, do something like
    Code:
    IF command[0] = "G" AND command[1] = "C" THEN
      ' Do Whatever
    ENDIF
    
    IF command[0] = "G" AND command[1] = "Q" THEN
      ' Do Whatever
    ENDIF
    This is a pretty straight forward way, depending on the number of different commands there might be "cleaner" and/or more efficient ways of doing it.

    /Henrik.

  3. #3
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305

    Default Re: identifying text commands

    I'm just curious if PBP could differentiate between caps and lower case? i.e.

    Would this:
    Code:
    IF command[0] = "G" AND command[1] = "C" THEN
      ' Do Whatever
    ENDIF
    
    IF command[0] = "G" AND command[1] = "Q" THEN
      ' Do Whatever
    ENDIF
    Produce the same results as this:
    Code:
    IF command[0] = "g" AND command[1] = "c" THEN
      ' Do Whatever 
    ENDIF
    
    IF command[0] = "g" AND command[1] = "q" THEN
      ' Do Whatever
    ENDIF
    If this is too elemental of a question I apologize for any inconvenience.

  4. #4
    Join Date
    Sep 2009
    Posts
    737

    Default Re: identifying text commands

    It's not same...
    Take look at ASSCI table
    http://www.asciitable.com/index/asciifull.gif
    "G" and "g" are just constant. You also could write 71 instead of "G", 103 instead "g".
    IF command[0] = "G" AND command[1] = "C" THEN
    is same as
    IF command[0] = 71 AND command[1] = 67 THEN

    For parsing string commands I use this:
    http://www.picbasic.co.uk/forum/show...009#post117009
    Scroll down code to CommandParser: label.
    You can easily convert upper case to lower and lower to upper as in this sample
    http://melabs.com/samples/PBP-mixed/serin.htm

Similar Threads

  1. Need a connector identifying
    By The Master in forum Off Topic
    Replies: 1
    Last Post: - 24th June 2012, 20:03
  2. How to prepare text (lots of text) for HSEROUT ?
    By Byte_Butcher in forum General
    Replies: 0
    Last Post: - 15th February 2010, 23:31
  3. Identifying which port to use
    By fadibasic in forum Schematics
    Replies: 2
    Last Post: - 24th April 2008, 03:21
  4. Help Identifying Mystery IC
    By paul borgmeier in forum Documentation
    Replies: 5
    Last Post: - 28th May 2007, 06:20
  5. Replies: 0
    Last Post: - 28th May 2004, 18:25

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts