data LSB first. Our PC's are "Big Endian" which is the other way around
and also the way we think and write. Sadly your only choice is to
simple do a byte swap AFTER you convert the binary number. One simple
way is to have a two byte array and fill it in reverse. You can use
math or simple bit shifts, but you'll just have to do it the obvious way.
DLC
Mike Smith wrote:
> Hi everyone -
>
> I am using SCP as a means for one OOPIC to read/write information to
> another OOPIC. Most of the values I'm interested in are two-byte
> oVar16 objects stored in variable memory, so my SCP command to
> retrieve a value looks something like:
>
> \1366J145HM
>
> (breaks down as Serial node1, Memory address 366, two-byte read)
>
> Assuming the variable object has the number 750 stored, this command
> returns:
>
> EE02m
>
> (two hexadecimal numbers EE and 02, followed by the "M" command
> confirmation of "m")
>
> I scratched my head for a little while trying to figure out how EE02
> in hexadecimal could equal the decimal number 750, but then realized
> that the bytes come through in last-byte-first order - (02EE does
> equal 750).
>
> Now I realize that if I were using oWord objects instead of oVar16's,
> I could use the default address of the object and get back a decimal
> string. However, by using oVar16's I get to use all that variable
> memory and conserve object memory for other things I need.
>
> I would like to know if anyone has suggestions for the most efficient
> way to take this "EE02m" value received from an oSerialPort object
> and properly convert so as to be used for displaying on an LCD(SET)?
> Perhaps some way to swap those two bytes?
>
> I know that there is no problem converting a hexadecimal number to a
> decimal string - I tested this by defining an oVar16 as equal
> to "0x02EE" and then using LCD.string=str$(var_name) and it
> successfully displayed 00750 on the LCD. However, I'm assuming there
> is going to have to be some magic in order for the text "EE02m"
> received by the serial port to be interpretted as the hex
> number "0x02EE" prior to such a conversion.
>
> Likewise, if I'm going to be sending values via SCP as well as
> reading them, I could use some pointers coding the OOPIC to
> convert numbers such as "750" to the appropriate two-hex number
> sequence required when sending data via SCP for storing to RAM.
>
> Thanks for any assistance,
>
> Mike
>
>
>
>
> Yahoo! Groups Links
>
>
>
--
------------------------------------------------------
Dennis Clark ooPIC Tech Support
www.oopic.com
------------------------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/oopic/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/oopic/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
No comments:
Post a Comment