New version of PropBasic supports strings
Bean
Posts: 8,129
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
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
Very cool!
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Are you Propeller Powered? PropellerPowered.com
Visit the: PROPELLERPOWERED SIG forum kindly hosted by Savage Circuits.
Yes I think this would be a good idea.
Gerry
Yes please; gets my vote too!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
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]
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?
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
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]
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PropGFX - The home of the Hybrid Development System and PropGFX Lite
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
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]
This is so you can do this:
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]
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
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
Use
SEROUT TX, Baud, __STRING(__PARAM1)
otherwise SEROUT will assume __param1 is the value to send instead of a string to send.
Bean