Shop OBEX P1 Docs P2 Docs Learn Events
The ID directive — Parallax Forums

The ID directive

John CoutureJohn Couture Posts: 370
edited 2007-06-28 18:50 in General Discussion
In many programs (and the docs) there is a directive called ID.

I understand how to SET it but how do you display it?· Using the example from the docs:

ID··· "GPXv2.1"

and put it directly under the FREQ statement and limit it to 8 chars or less.

When I try to use Jon's TX_OUT subroutine (for example):

TX_OUT·· ID

it says the ID is a reserved word.·

TX_OUT allows a string or byte to be sent to your output device (in my case an LCD panel).


'
TX_Out:
' Use: TX_OUT [noparse][[/noparse] byte | string | label ]
' -- "aByte" is variable or constant byte value
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String
' --· Written by Jon Williams (Parallax)
· TX_temp3 = __PARAM1····················· ' get byte or string offset
· IF __PARAMCNT = 2 THEN
··· TX_temp4 = __PARAM2··················· ' get string base
··· DO
····· READ TX_temp4 + TX_temp3, TX_temp5·· ' read a character
····· IF TX_temp5 = 0 THEN EXIT··········· ' if 0, string complete
····· TX_BYTE TX_temp5···················· ' send the byte
····· INC TX_temp3························ ' point to next character
····· TX_temp4 = TX_temp4 + Z············· ' update base on overflow
··· LOOP
· ELSE
··· TX_BYTE TX_temp3······················ 'transmit the byte value
· ENDIF
· RETURN

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture

San Diego Miramar College

Comments

  • JonnyMacJonnyMac Posts: 9,215
    edited 2007-06-21 23:43
    The device ID is not available to our programs at run time; you'll have to create a duplicate z-string in a DATA statement for use in TX_OUT as above (by the way, that's an outdated subroutine -- see below).

    The ID is included in the assembled code and can be read by using the IDE's Run\Device menu. This allows us to create a hex file of a program (to protect the source from others) and still have it be identified (once the hex file is loaded into the that dialog).

    To keep things trimmer and less complicated I use TX_BYTE and TX_STR in my programs; here are the latest:

    ' Use: TX_BYTE byteVal 
    ' -- transmit "byteVal" at "BaudMode" on pin "TX"
    
    SUB TX_BYTE
      SEROUT TX, BaudMode, __PARAM1
      ENDSUB
    
    ' -------------------------------------------------------------------------
    
    ' Use: TX_STR [noparse][[/noparse]string | label]
    ' -- "string" is an embedded string constant
    ' -- "label" is DATA statement label for stored z-String
    
    SUB TX_STR
      tmpW1 = __WPARAM12                            ' get address of string
      DO
        READINC tmpW1, tmpB1                        ' read a character
        IF tmpB1 = 0 THEN EXIT                      ' if 0, string complete
        TX_BYTE tmpB1                               ' send character
      LOOP
      ENDSUB
    



    And in the event you really like the TX_OUT subroutine here's a better version of it:

    ' Use: TX_OUT [noparse][[/noparse]byte | string | label]
    ' -- "byte" is a byte variable or constant value
    ' -- "string" is an embedded string constant
    ' -- "label" is DATA statement label for stored z-String
    
    SUB TX_OUT
      IF __PARAMCNT = 1 THEN
        TX_BYTE __PARAM1
      ELSE
        tmpW1 = __WPARAM12                          ' get address of string
        DO
          READINC tmpW1, tmpB1                      ' read a character
          IF tmpB1 = 0 THEN EXIT                    ' if 0, string complete
          TX_BYTE tmpB1                             ' send character
        LOOP
      ENDIF
      ENDSUB
    

    Post Edited (JonnyMac) : 6/21/2007 11:56:05 PM GMT
  • BeanBean Posts: 8,129
    edited 2007-06-22 11:20
    John,
    · The ID is useful when you protect your code in the SX. Everything read back from the SX will be scrambled EXCEPT the ID string.

    · In the IDE if you use Run->Device then click the "Read" button, the ID will be displayed in the ID box (just below the options check boxes).

    · This way you can see what version of your code a device has, even it is has code protection turned on.
    · But there is no way for your SX code to read the ID string. (That I know of)

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • djmullendjmullen Posts: 10
    edited 2007-06-28 16:04
    Can I ask what a couple of these instructions do?

    First of all, what is the advantage of putting sub before the name of a subroutine, as in "SUB TX_STR"?

    Second what does this instruction, "READINC" do?

    Is there an SX/B manual I haven't read?

    Thanks,
    Dave
  • JonnyMacJonnyMac Posts: 9,215
    edited 2007-06-28 16:30
    By using the SUB - ENDSUB (FUNC - ENDFUNC) form your code is future-compatible with the proposed design of SX/B 2.0.

    READINC READs from an address and then INCrements the address pointer variable -- this is in the SX/B help file (also available as a PDF) that you apparently haven't read....
  • djmullendjmullen Posts: 10
    edited 2007-06-28 18:35
    Thanks! READINC is especially handy for the program I'm reading right now. It will replace several instructions.

    I've read the original help file, version 1.50.01 -- 05 JUL 2006 , many times, but I can't get the latest version to run. It errors out on three different computers when I either click on it or try to run it from the IDE. I'll look for that .pdf file.
  • djmullendjmullen Posts: 10
    edited 2007-06-28 18:50
    Found "sxb.pdf". Reading.
Sign In or Register to comment.