No existing component will take a 32-bit floating point number encoded
as 2 16-bit "s32" values and output it as a HAL float.

I wrote and gave a very small amount of testing to a component that does.

component toieee
"""Interpret two 16-bit integers or one 32-bit integer as a 32-bit IEEE
floating-point value"""; 

pin in s32 in-low "Low 16 bits OR full 32-bit floating point value";
pin in s32 in-high "High 16 bits OR zero";
pin in bit update "TRUE to update output, FALSE to hold current value";

pin out float out "Result of conversion";

license "GPL";
function _
"""If update is TRUE, compute a new output value from the input values."""
;   
;;
FUNCTION(_) {
    if(!update) return;
    
    union { uint32_t i; float f; } u;

    u.i = ((uint32_t) in_low) | (((uint32_t) in_high) << 16);
    out = u.f; // (automatically promoted from 32-bit float to 64-bit double)
}

For instance, treating the hex value 3EAAAAAB as a 32-bit IEEE float, it
obtains a value close to 1/3:
    halcmd: setp toieee.0.update 1
    halcmd: setp toieee.0.in-high 0x3eaa
    halcmd: setp toieee.0.in-low 0xaaab
    halcmd: getp toieee.0.out
    0.3333333

However, if this is considered a "standard enough" modbus encoding then perhaps
this decoding should be added directly into mb2hal.

Jeff

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to