PDA

View Full Version : problem in sending floating point variable over serial comm


ironhide
01-23-05, 10:53 PM
hi,
i cud not figure out how to send floating point variable (which i will be getting from code written in isomax which will be in 2 bytes) to a system running on linux which has 4 byte representation for floating points.
I cud transfer integer values by converting them into two bytes and again merging them on receiving on other side.

abhishek

RMDumse
01-24-05, 07:45 AM
Yes, we've done this to send values over CAN.

However, on the 'Pod the float is not in 2-bytes. It is in 4-bytes, but that's only 2-words there.

Here's an example of the CAN version that transmits two floating point numbers by bytes:

: SEND2FP
D86 @ 1 AND
IF
5 DD0 !
CMDDISTANCE 2@
DUP >< FF AND DD7 ! FF AND DD6 !
DUP >< FF AND DD5 ! FF AND DD4 !
CMDDISTANCE 2@
DUP >< FF AND DDB ! FF AND DDA !
DUP >< FF AND DD9 ! FF AND DD8 !
8 DDC ! 1 D86 !
THEN
; EEWORD

and here is the routine that rcv's it:

: RCV2FP
D84 @ 1 AND
IF
DCC @ 4 =
IF
DC4 @ DC5 @ >< OR DC6 @ DC7 @ >< OR
VMSG1 2!
DC8 @ DC9 @ >< OR DCA @ DCB @ >< OR
VMSG2 2!
THEN
1 D84 !
THEN
; EEWORD

Now the thing is, the native serial channel will send all 8 bits, but on the linux side, it may object to having values through out the entire 8-bit spectrum. For instance, it may process an 08 byte as a back space, and then your value would be corrupted.

However, if you do get the bits over intact, and reassembled there's a fair chance the value will work, as it should be a common IEEE format.