Shop OBEX P1 Docs P2 Docs Learn Events
TX_STR Problem — Parallax Forums

TX_STR Problem

edgellmhedgellmh Posts: 85
edited 2008-05-26 02:04 in General Discussion
I am using Jon Williams' functions for outputting characters via the serial port. I get bytes output correctly but not strings.

TX_BYTE: 'Use: TX_BYTE outgoing byte
'LET temp1 = __PARAM1 'Outgoing port
LET temp2 = __PARAM1 'Outgoing byte

SEROUT TX_DB9, Baud, temp2
RETURN

TX_STR: 'Use: TX_STR [noparse][[/noparse]string| label]
' "string" is an embedded literal string
' "label' is DATA statement for stored z-string
temp3 = __PARAM2 'get string offset
temp4 = __PARAM3 'Get string base
DO
READ temp4 + temp3, temp5 'Read a char from the string into temp5
IF temp5 = 0 THEN EXIT 'String complete
TX_BYTE temp5
INC temp3 'Point to next char
temp4 = temp4 + Z 'Update base on overflow
LOOP
RETURN

When I execute TX_STR "Start" here is what I get at the terminal

Comments

  • edgellmhedgellmh Posts: 85
    edited 2008-05-26 01:53
    Well, again when I reexamined the code I found a misused variable.
    The basic code now works fine.

    sigh,
    marshall
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-05-26 02:04
    That's old code -- use this version, it's cleaner:

    ' Use: TX_BYTE aByte
    
    SUB TX_BYTE
      SEROUT TX, Baud, __PARAM1
      ENDSUB
    
    ' -------------------------------------------------------------------------
    
    ' Use: TX_STR [noparse][[/noparse]String | Label]
    ' -- pass embedded string or DATA label
    
    SUB TX_STR
      tmpW1 = __WPARAM12                            ' get offset/base
    
      DO
        READINC tmpW1, tmpB1                        ' read a character
        IF tmpB1 = 0 THEN EXIT                      ' if 0, string complete
        TX_BYTE tmpB1                               ' send the byte
      LOOP
      ENDSUB
    

    Post Edited (JonnyMac) : 5/26/2008 2:24:07 AM GMT
Sign In or Register to comment.