That worked perfectly, Jeff!  Thank you very much.

To summarize for future readers, process the comp
file Jeff wrote like this:

halcompile --install toieee.comp

Then add to the HAL file:

loadrt toieee
addf toieee.0 servo-thread

setp toieee.0.update 1
net low mb2hal.00.00.int toieee.0.in-high
net high mb2hal.00.01.int toieee.0.in-low
net ain-00 motion.analog-in-00 toieee.0.out

This will properly convert analog input registers read from
a LabJack UE9-Pro over Modbus TCP into a floating point
value readable by an M66 E0 L0.

Thanks again!
-- Ralph
________________________________________
From: Jeff Epler [jep...@unpythonic.net]
Sent: Friday, December 04, 2015 2:46 PM
To: Enhanced Machine Controller (EMC)
Subject: Re: [Emc-users] mb2hal and floating point conversions

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

------------------------------------------------------------------------------
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