I need to learn how to make a string
Brian Carpenter
Posts: 728
i have several variables that i need to make into a string with commas separating the values. eed to then count the length of the string and send the sting out serially. I can send the data but i am not sure how to create the string. See below
Any ideas or threads to read would be great.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Digi.str(string("$THERM,")) Digi.hex(mach_ID,4) Digi.str(string(",")) Digi.dec(Therm1H) Digi.str(string(",")) Digi.dec(Therm2H) Digi.str(string(",")) Digi.dec(Therm3H) Digi.str(string(",")) Digi.dec(Therm4H) Digi.str(string(",")) Digi.dec(CSP1) Digi.str(string(",")) Digi.dec(CSP2) Digi.str(string(",")) Digi.dec( Amps1) Digi.str(string(",")) Digi.dec(Amps2) Digi.str(string(",")) Digi.dec(contact1) Digi.str(string(",")) Digi.dec(contact2) Digi.str(string(",")) Digi.dec(contact3)
Any ideas or threads to read would be great.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Comments
So i would run this routine for each dec value and then add it all together with the known number of other characters?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
You could simply define one "LineEnd" character. For direct terminal-output this could be the 13 (Carriage Return).
The receiver has a buffer which is long enough to carry the max. number of characters you expect and receives until the buffer-length has been reached or it receives the line-end character. If the receiver reached the buffer-end it continues with reading until line-end, but does not store the characters anywhere. This should never happen in normal operation, but this way your receiver is failsafe and should not have buffer overflow bugs.
If the string is not for direct output, you could transmit binary values instead. Then you have a fixed size for each transmission. Say your values have word size, then you have to transmit 12*2 bytes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230