View Full Version : Syntax for ASCII format characters in Parallax Serial Terminal .str method

John Kauffman
11-16-2010, 07:36 PM
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
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
' Attempt[1], but it does not compile:

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


Roy Eltham
11-16-2010, 07:49 PM
This should work:

Alternatively, you should be able to do this:
pst.Str(string(pst#TB, "Some test string", pst#TB, "more string", pst#NL))

John Kauffman
11-16-2010, 08:11 PM
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)


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..


Phil Pilgrim (PhiPi)
11-16-2010, 08:37 PM
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.


Dave Hein
11-16-2010, 08:56 PM
You could use the CLIB object to do C-formatted prints. Your example would look like

_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

c : "clib"

MyStringInDat1 byte "A string without/tab held in the data block", 0

PUB main

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.