Shop OBEX P1 Docs P2 Docs Learn Events
New version of PropBasic supports strings — Parallax Forums

New version of PropBasic supports strings

BeanBean Posts: 8,129
edited 2011-11-18 12:32 in Propeller 1
Release 00.00.96 of PropBasic will have the following string support:

temp·· VAR LONG
name1 HUB STRING(80) ' This allocates 81 bytes in the hub
name2 HUB STRING(80)

name1 = "Ascii"
name1 = name2 + "ascii"
name1 = RIGHT name2, count
name1 = LEFT name2, count
name1 = MID name2, start, count

SEROUT pin, baud, name1
SERIN pin, baud, name1
VAL name1, temp
STR name1, temp
LEN·name1, temp

I have attached a small demo program. I hope to finish testing tomorrow, then it's off to BradC to get compiled. Then it will be available.

Strings are z-strings (terminated with a zero byte).

Bean

P.S....

Should I change·VAL, STR and LEN so they·are:
· temp·= VAL name1
· temp = LEN name1
· name1·= STR temp

Let me know what you think.


·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]

Post Edited (Bean) : 5/7/2010 1:46:29 AM GMT

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-05-05 23:23
    /me lifts an eyebrow....

    Very cool!

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Are you Propeller Powered? PropellerPowered.com
    Visit the: PROPELLERPOWERED SIG forum kindly hosted by Savage Circuits.
  • Gerry KeelyGerry Keely Posts: 75
    edited 2010-05-06 10:27
    Bean
     
    Should I change VAL, STR and LEN so they are:
      temp = VAL name1
      temp = LEN name1
      name1 = STR temp
    
    


    Yes I think this would be a good idea.

    Gerry
  • VonSzarvasVonSzarvas Posts: 3,510
    edited 2010-05-06 11:07
    @Bean, "Should I change VAL, STR and LEN..."

    Yes please; gets my vote too!
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-05-06 11:30
    Woot! All my wishes come true. Thanks Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • BeanBean Posts: 8,129
    edited 2010-05-06 12:41
    Yeah, I guess it does make sense since they are really functions.

    I'll change those commands, this will break existing code that uses STR.

    STR will be a function, and will no longer support a VAR array as the destination. It's not smart to use a VAR array anyway because it uses 4 bytes of COG ram for every character. That uses up valuble code space.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • nohabnohab Posts: 96
    edited 2010-05-06 15:55
    Bean, it's great that you continue to develop PropBasic!

    What I've been locking for is to use PropBasic to generate fast code e.g. for a driver in one cog, but continue to use Spin in the main cog.
    Are there any tricks to do this?
  • Brian RileyBrian Riley Posts: 626
    edited 2010-05-06 18:40
    Bean said...
    Should I change VAL, STR and LEN so they are:

    temp = VAL name1

    temp = LEN name1

    name1 = STR temp

    Bean,

    I have been off doing a lot of PCB stuff and not playing too much with PB ... I want to make sure I understand these functions ... LEN , that is clear, but is VAL like atoi() and STR like itoa() ????

    Keep up the great work

    cheers ... BBR

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cheers ... brian riley, n1bq, underhill center, vermont
    The Shoppe at Wulfden
    www.wulfden.org/TheShoppe/
    www.wulfden.org/TheShoppe/prop/ - Propeller Products
    www.wulfden.org/TheShoppe/k107/ - Serial LCD Display Gear
  • BeanBean Posts: 8,129
    edited 2010-05-06 19:02
    LEN returns the length of the string (how many characters before the zero terminator)
    VAL converts a string to a value (Minus sign must be first character for negative value, leading spaces are ignored)
    STR converts a value to a string

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • BeanBean Posts: 8,129
    edited 2010-05-07 01:40
    Just a note that BradC has posted the new version.
    Here is a link to the thread with the link http://forums.parallax.com/showthread.php?p=867134

    I will update the documentation as soon as I can. Maybe this weekend. Alot has changed so it will take some time.

    If you have ANY questions about the new stuff please ask. I'll be more than happy to answer them.
    · Fixed: PINS = Array(const)

    · Fixed: Allow indexed hub variables for SUB and FUNC parameters
    ··· myStr HUB BYTE(81)
    ··· ASSIGN myStr(5), "Hello" ' ASSIGN is a SUB

    · Fixed: "" evaluates to zero, "A" evaluates to 65, "AB" evaluates to a string

    · Added:
    ··· name HUB STRING (60)
    ··· SERIN pin, baud, string
    ··· string = string
    ··· string = RIGHT string, count
    ··· string = LEFT string, count
    ··· string = MID string, start, count
    ··· longVar = LEN string
    ··· longVar = VAL string
    ··· string = STR longVar, digit[noparse][[/noparse], option]
    ····· Option:
    ······· 0 - Unsigned leading zeros, z-string
    ······· 1 - (default) Unsigned leading spaces, z-string
    ······· 2 - Signed leading zeros, z-string
    ······· 3 - Signed leading spaces, z-string
    ······· 4 - Unsigned leading zeros, no terminating zero
    ······· 5 - (default) Unsigned leading spaces, no terminating zero
    ······· 6 - Signed leading zeros, no terminating zero
    ······· 7 - Signed leading spaces, no terminating zero

    Bean

    P.S. Just a note, you cannot do:

    · Str1 = "Ascii" + Str1

    Since the text will get stored at the start of "Str1", so when it appends Str1 you will get the "Ascii" text again. So this type of command will throw an error.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]

    Post Edited (Bean) : 5/7/2010 1:49:23 AM GMT
  • ColeyColey Posts: 1,110
    edited 2010-05-07 07:33
    A great addition to an already fantastic compiler, many thanks Bean....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PropGFX - The home of the Hybrid Development System and PropGFX Lite
  • VonSzarvasVonSzarvas Posts: 3,510
    edited 2010-05-07 08:48
    Bean... may I ask about the serin function.

    bufs HUB String(80)
    serin rxpin, baud, bufs

    1. Is there a timeout option?
    2. When does serin return? (Ie. when it detects a CR or when 80 chars are received)
    3. If it returns on CR, can we have an option to specify the return detection character ?

    it might be like..

    serin pin, baud, stringbuffer, { optional stringreturnchar/s, optional timeout millis }

    I could use:

    serin pin, baud, bufs, CR, 5000

    or

    serin pin, baud, bufs, "OK", 5000

    or just:

    serin pin, baud, bufs, 5000
  • BeanBean Posts: 8,129
    edited 2010-05-07 10:36
    Maxwin,
    You may still use the timeout option with string input.
    Yes, it terminates on a CR (13).

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • BeanBean Posts: 8,129
    edited 2010-05-07 10:59
    Note that STR will add the termination zero for options 0 thru 3, options 4 thru 7 are the same but WITHOUT the termination zero.

    This is so you can do this:

    Message DATA "The value is" 
    valueStr DATA "12345 units.", 13, 0 
    
    valueStr = STR value, 5, 5 ' unsigned, leading spaces, no zero terminator
    SEROUT TX, Baud, Message
    

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • VonSzarvasVonSzarvas Posts: 3,510
    edited 2010-05-07 11:16
    1. I did not realise timeout was already included (sorry!).
    So is this the correct syntax: serin pin,baud,value, [noparse][[/noparse]optional timeout] ?
    And is timeout in milliseconds?


    2. Is there a chance to assign the termination character instead of the default CR ?
    I want to read a string which terminates with "OK", but which contains a couple of CR bytes within itself. At the moment it would be required to call SERIN 2 or 3 times, which (even with a sub_serin) generates lots of code.

    Thanks again !


    Edited to add after-thought:

    .. of course, I could create my own sub to deal with no.2 - that would probably make more sense if no-one else needs such functionality.

    .. of course, I could always read the manual to answer no.1 myself! Yes its the correct syntax and milliseconds! Doh!

    Post Edited (Maxwin) : 5/7/2010 11:32:08 AM GMT
  • VonSzarvasVonSzarvas Posts: 3,510
    edited 2010-05-07 11:37
    Bean, just for your info in case it helps - The reason for my "missing" the timeout param was that it is NOT mentioned in the user guide, but IS mentioned in the quick reference guide.
  • SonarSonar Posts: 2
    edited 2011-11-18 05:43
    I'd like to put SEROUT in a SUB similar to below. It does not work. What do I need to do to make it work?


    Message DATA "The value is"
    valueStr DATA "12345 units.", 13, 0

    valueStr = STR value, 5, 5 ' unsigned, leading spaces, no zero terminator
    SendString Message

    SUB SendString
    SEROUT TX, Baud, __PARAM1
    ENDSUB

    Sonar
    Bean wrote: »
    Note that STR will add the termination zero for options 0 thru 3, options 4 thru 7 are the same but WITHOUT the termination zero.

    This is so you can do this:

    Message DATA "The value is" 
    valueStr DATA "12345 units.", 13, 0 
    
    valueStr = STR value, 5, 5 ' unsigned, leading spaces, no zero terminator
    SEROUT TX, Baud, Message
    

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • BeanBean Posts: 8,129
    edited 2011-11-18 12:32
    Sonar,
    Use

    SEROUT TX, Baud, __STRING(__PARAM1)

    otherwise SEROUT will assume __param1 is the value to send instead of a string to send.

    Bean
Sign In or Register to comment.