Shop OBEX P1 Docs P2 Docs Learn Events
Syntax for ASCII format characters in Parallax Serial Terminal .str method — Parallax Forums

Syntax for ASCII format characters in Parallax Serial Terminal .str method

John KauffmanJohn Kauffman Posts: 653
edited 2010-11-16 13:56 in Propeller 1
I'm adding some ASCII format characters (for example 9 = tab) to strings to be printed by the Parallax_Serial_Terminal object's .str method.

If the string is held in DAT there is not problem adding the format characters there:
PUB Main
  pst.Start(57600)
  pst.str(@MyStringInDat1)
DAT
MyStringInDat1   byte   9,"A string w/tab held in the data block",0

But I have been unable to find a sample syntax for putting the format characters directly in the PST.str:
PUB Main
  pst.Start(57600)
' Attempt[1], but it does not compile:
  pst.str(9,@MyStringInDat1)

I have several more attempts in the attached file. Some don't compile, others create an odd result.

Thanks.

Comments

  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2010-11-16 12:49
    This should work:
    pst.Str(string(pst#TB))
    pst.Str(@MyStringInDat1)

    Alternatively, you should be able to do this:
    pst.Str(string(pst#TB, "Some test string", pst#TB, "more string", pst#NL))
  • John KauffmanJohn Kauffman Posts: 653
    edited 2010-11-16 13:11
    Both of your suggestions work, but the objective is to use the format on the same line as a string in DAT.

    Your suggestion #1 works on two lines (but I'm am trying for one line)
    pst.Str(string(pst#TB))
    pst.Str(@MyStringInDat1) 
    

    Your suggestion #2 works with literal string (but i am trying for source in DAT):
    pst.Str(string(pst#TB, "Some test string", pst#TB, "more string", pst#NL)) 
    

    I am shooting for something like the following:
    pst.Str(string(pst#TB, @MyStringInDat1, pst#TB, "temp string", pst#NL)) 
    

    It is not that I am adverse to two lines of code (your suggestion #1), I am mostly interested in learning if there is a syntax to do the job on one line and then learning how that syntax might apply to other places..

    THanks.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-11-16 13:37
    You won't be able to put a DAT address in a string constructor. The best you can do is either to put the tabs in the DAT section, or to use multiple calls to str.

    Well, okay, there is one more way, but it's not elegant:
    output(pst.tx(pst#TB) + pst.str(@MyStringInDat1))
    
    PUB output(dummy)
    
    

    The output method is empty and does nothing. It's arguments are evaluated in order before being called, and that's the sole purpose it serves.

    -Phil
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-11-16 13:56
    You could use the CLIB object to do C-formatted prints. Your example would look like
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      c : "clib"
    
    DAT
      MyStringInDat1   byte   "A string without/tab held in the data block", 0
    
    PUB main
      c.start
    
      c.printf1(string("\011%s\011temp string\n"), @MyStringInDat1)
    

    EDIT: I insert a tab by using the octal representation \011 (9 decimal). \t should work, but I just relized that this generates a backspace (decimal 8) instead. I'll fix this in a future update to CLIB.
Sign In or Register to comment.