Shop OBEX P1 Docs P2 Docs Learn Events
Storing FloatToFormat String result into a byte array — Parallax Forums

Storing FloatToFormat String result into a byte array

4Alex4Alex Posts: 119
edited 2008-06-17 16:42 in Propeller 1
Hi there!

I am trying to transfer each individual characters resulting from the FloatToFormat function into a byte array without success. The function works perfectly when its output is directed toward Hyperterminal. Now, I· want the byte array to be the recipient of the characters instead of Hyperterminal. I have attempted several different approaches and couldn't find something working. I am quite 'green' on the PPL (just a few months hand-on), love the device, but I find the logic somewhat different from other microprocessors I used so I must miss something evident. My searching of the previous posts was also inconclusive. Could a compassionate soul point me in the proper direction, please.

Here's what I try to do (kind of pseudo-code):

var ...
byte buffer [noparse][[/noparse] 20 ]
.
pub...
.
cptr := 11
inc := 0
repeat 6
· buffer [noparse][[/noparse] cptr++ ]· := floatStr.FloatToFormat(temperature, 6, 1) scool.gif
.

Thanks for your help.
Alex

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-17 16:21
    Most of these conversion routines return the address of a temporary buffer within the "floatStr" object that contains the result including a zero byte terminator. The easiest way to handle this is to use BYTEMOVE to copy the result to your buffer like this:
    bytemove(@buffer,floatStr.FloatToFormat(temperature,6,1),20)
    

    This copies 20 bytes regardless of the actual length of the string, but the copy is very fast and it doesn't matter that extra bytes (beyond the zero terminator) are copied as well.
  • 4Alex4Alex Posts: 119
    edited 2008-06-17 16:42
    @Mike:

    Thank you very much for your kind reply. I am soooo embarassed: I did try something similar but I stupidly put the @ sign in front of the floatStr.FloatToFormat !!! I even tried @@... (which obviously I still don't get, but that's another story). I thought it was the only way to indicate that I wanted to start at the beginning of the string result.

    Thank you again for your help.
Sign In or Register to comment.