Shop OBEX P1 Docs P2 Docs Learn Events
How to store a string as a variable — Parallax Forums

How to store a string as a variable

jon123456789jon123456789 Posts: 11
edited 2009-10-17 22:58 in Propeller 1
Hi,
I'm pulling my hair out with this one, and I'm sure the answer is so simple. I just can not work it out.
So 2 browny points to the person who can point me in the right direction.
How do I store a text string in a single place in the code so I can use it in multiple locations?
I have tried:
DAT
 
    message byte "this is my message"

and then use:

    Serial.str(string(message))

But I get gobbledegook through on the serial interface.

The serial interface works fine as listed below:

I use the Prop linked to a GSM module to send me a text message if my house alarm is initiated.
I'm using the FullDuplexSerial object, as follows:
PUB sendsms1
    Serial.str(string("AT+CMGF=1"))             {set format to text mode}
    Serial.tx(13)
    waitcnt(100_000_000 + cnt)
    Serial.str(string("AT+CSDH=1"))             {Show Text Mode Parameters}
    Serial.tx(13)
    waitcnt(100_000_000 + cnt)
    Serial.str(string("AT+CSMP=17,167,0,0"))    {Set Text Mode Parameters}
    Serial.tx(13)
    waitcnt(100_000_000 + cnt)
    Serial.str(string("AT+CMGS="))
    Serial.tx(34)                               {" character}
    Serial.str(string("+44123456789"))
    Serial.tx(34)                               {" character}
    Serial.tx(13)                               {CR}
    waitcnt(100_000_000 + cnt)
    Serial.str(string("Alarm condition"))
    Serial.tx(26)                               {ctrl z}
    Serial.tx(13)

I would like to tidy up my code a bit·as I currently have multiple messages so I have multiple PUB's for each SMS (and duplicated again for 2 x mobile phone numbers) but it could be a lot neater and simpler.

With thanks

Jon

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-10-17 13:09
    The only datatype that the Propeller supports natively are integers. Strings are not natively supported as a variable type. So, the string command will store the text given as a zero terminated byte array, and returns the start address. So, for the first code that you posted, try serial.str(@message).
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-17 13:22
    You do need a zero byte at the end of the message as a string terminator like: message byte "this is a message",0
  • jon123456789jon123456789 Posts: 11
    edited 2009-10-17 13:57
    browny points all round. Thanks!!!

    The following worked just fine:

    PUB sendsms1
        Serial.str(string("AT+CMGF=1"))             {set format to text mode}
        Serial.tx(13)
        waitcnt(100_000_000 + cnt)
        Serial.str(string("AT+CSDH=1"))             {Show Text Mode Parameters}
        Serial.tx(13)
        waitcnt(100_000_000 + cnt)
        Serial.str(string("AT+CSMP=17,167,0,0"))    {Set Text Mode Parameters}
        Serial.tx(13)
        waitcnt(100_000_000 + cnt)
        Serial.str(string("AT+CMGS="))
        Serial.tx(34)                               {" character}
        Serial.str(string("+447123456789"))
        Serial.tx(34)                               {" character}
        Serial.tx(13)                               {CR}
        waitcnt(100_000_000 + cnt)
        Serial.str(@message)
        Serial.tx(26)                               {ctrl z}
        Serial.tx(13)
     
    DAT
      message byte "this is my message",0
     
    
  • jazzedjazzed Posts: 11,803
    edited 2009-10-17 22:58
    Amazing how many times this comes up in the forum ... twice a week?
    This is not an RTFM message, but an ETFM "Enhance the ... Manual" message.

    The information is described in gory detail in the "BYTE" section of the Propeller manual ... if you know where to look. I think the "opportunity" for the technical writers is to add a section to the manual on "data types" so that people who know what "data types" means can find it. Almost any programming language introduction I've seen has such a section. Of course the audience is not necessarily programmers so even a "data types" section might not help. Still, people with skills beyond the Basic Stamp should be considered.
Sign In or Register to comment.