Help with strings/hex? [solved]
So, what I have is the date in the format MMDDYY in string format. I want to print it as MM/DD/YY to the serial terminal. I have tried string and string2 with horrible amounts of fail. If I have the date in a variable called "date" how can I format this? Using some code...
but, if I try to use the terminal and...
I get crazy characters on the screen
I tried to create a temp string. from what I see in memory date is preceded and superseded with 00 or EOT. so, if I...
I get all 0's when I print it out to the terminal and crazyness if I tried to print the string. What am I doing wrong here? Why am I having such a hard time with something so simple? Thanks in advance anyone.
Post Edited (teddyp) : 4/19/2010 10:04:42 PM GMT
pst.str(date) 'prints out the date 041910 for today
pst.str(string(13)) 'CR
pst.dec(strsize(date)) 'prints out decimal 6 (length of the date string)
pst.str(string(13)) 'CR
repeat k from 0 to strsize(date) - 1 'from 0 to 5
pst.hex(byte[noparse][[/noparse]date][noparse][[/noparse]k],2) 'I get 30 34 31 39 31 30 all hex good.
pst.str(string(13))
but, if I try to use the terminal and...
pst.str(byte[noparse][[/noparse]date][noparse][[/noparse]0])
pst.str(byte[noparse][[/noparse]date][noparse][[/noparse] 1 ])
I get crazy characters on the screen
I tried to create a temp string. from what I see in memory date is preceded and superseded with 00 or EOT. so, if I...
byte[noparse][[/noparse]@MyDate][noparse][[/noparse]0] :=$00
byte[noparse][[/noparse]@MyDate][noparse][[/noparse] 1 ] := byte[noparse][[/noparse]date][noparse][[/noparse]0]
byte[noparse][[/noparse]@MyDate][noparse][[/noparse] 2 ] := byte[noparse][[/noparse]date]
byte[noparse][[/noparse]@MyDate][noparse][[/noparse] 3 ] := $00
pst.hex(MyDate,8)
I get all 0's when I print it out to the terminal and crazyness if I tried to print the string. What am I doing wrong here? Why am I having such a hard time with something so simple? Thanks in advance anyone.
Post Edited (teddyp) : 4/19/2010 10:04:42 PM GMT

Comments
repeat i from 0 to 5 pst.tx( byte[noparse][[/noparse] @date ][noparse][[/noparse] i ] ) if i&1 pst.tx( "/" )The problem with your code is that you call pst.str without giving an address. str function want's an address and not values. And the address must point to a byte array which has a $00 as a string-end character.
The tx-function is fine with the character value, so you can use this to print exactly one character.
Post Edited (MagIO2) : 4/19/2010 9:40:06 PM GMT
MyDate := string("ABC") repeat 'Repeat forever pst.str(date) 'gives me 041910 for today pst.str(string(13)) 'CR pst.dec(strsize(date)) 'print size of string (is 6 for this) pst.str(string(13)) 'CR repeat k from 0 to strsize(date) - 1 'Repeat from 0 to 5 pst.hex(byte[noparse][[/noparse]date][noparse][[/noparse]k],2) 'Print hex value for each char pst.str(string(13)) 'CR pst.str(MyDate) 'print MyDate (is still ABC from above) pst.str(string(13)) 'CR bytemove(MyDate, date, 2) 'Move first two bytes of date into MyDate pst.str(MyDate) 'print MyDate (is now 04C in the terminal) pst.str(string(13)) 'CR bytemove(MyDate, date+2, 2) 'took me a minute to figure this one out. It's not the location with an offset as 'in date it's the ADDRESS + 2. pst.str(MyDate) 'Prints 19C to term pst.str(string(13)) 'CR bytemove(MyDate, date+4, 2) 'You get the picture pst.str(MyDate) pst.str(string(13))Thanks again for the help! I wish I would've found that wiki earlier
Simple_Serial and FullDuplexSerial both have the function tx and I'm pretty sure that any serial interface has something similar. What exactly is PST?