Sending Word Variable from PICAXE to PC via RS232

superworm

New Member
Hey Guys!

I have some word variables that I'd like to send from PICAXE to PC via RS232.
I have to use word variables because im working with relatively large numbers, but a look in the PICAXE manual and a quick scout around here reveals that only bytes can be send via serial eg: b0 or b4 etc

Is there any way to send words serially to the PC via RS232? If I convert them to ASCII by including a # will the PC be able to read it? If so can anyone recommend a program?

Sorry to bother you guys again!

Matt
 

SilentScreamer

Senior Member
Each word variable is made up of two bite variables (i.e. w0 = b1:b0 w1 = b3:b2 w2 = b5:b4) so you can just send the byte variables individually.
 

Technical

Technical Support
Staff member
As already stated you could send the two bytes separately, RS232 only works with bytes not words.

However if you use the # conversion to ASCII byte characters a word can be used directly to output a text stream like "65432".
 

kewakl

Senior Member
@Technical...

does this mean that if I want to send the value of 254 to a serially connected device, then I can
Code:
Let B1=254
Serout 0, N4800_4, (#B1)
or am I missing something.

I am sending string representations of values to an AB PLC (micrologix 1100 on channel 0 -- if anyone cares)
I have a way to convert a value of 254 to string "254" , so the PLC sees 2 5 4 as a string "254",
but does #B1 do the same?


EDIT Just read Section 2 Pg. 173. -- looks like the answer to this Q!
 
Last edited:

hippy

Ex-Staff (retired)
Yes, #b1 with b1=254 will send "2", "5" then "4". The only thing to be aware of is that using # doesn't send any leading zeroes; #b1 with b1=12 sends "1" then "2".
 

Technical

Technical Support
Staff member
Check out the bintoascii command instead then.
Code:
let b1=254
bintoascii b1,b2,b3,b4
Serout 0, N4800_4, (b2,b3,b4)
Also works for words.
 

kewakl

Senior Member
@technical
looks promising

when I looked in the manual at
Convert a binary value into separate ASCII bytes.
it never occurred to me that it would provide LEADING zeroes
that should remove about 150 bytes from the code!

thanks
 

hippy

Ex-Staff (retired)
If savings are not in the region you expect or desire ( BINTOASCII simplifies coding, not necessarily program space ), consider putting it in a subroutine which you call when you need to output such a number. Savings will depend upon exactly what code you were using,
 
Top