Now that I read my solution in the cold light of dawn I think that I should have included how to read the two 16-bit values in a way that should minimize the possibility of mixing old/new data.
*****************************************************************
Q. My PLC returns floating point values as two 16 bit integers. How can
I convert these to a floating point value?
A. Here's a CALC record that can do this. The expression is longer
than 40 characters but that's a problem only if a client tries to read
the expression as an EPICS string.
#
# Assume that the registers are processsed in order
# so the low word (offset N) value is ready by the time
# that the high word (offset N+1) forward link is processed.
#
record(longin,"$(P)vacuumHiWord") {
field(DESC, "R2089")
field(DTYP, "asynInt32")
field(INP, "@asyn(rfDrive_r0i, 92, 1)")
field(SCAN, "I/O Intr")
field(FLNK, "$(P)vacuumLoWord")
}
record(longin,"$(P)vacuumLoWord") {
field(DESC, "R2088")
field(DTYP, "asynInt32")
field(INP, "@asyn(rfDrive_r0i, 91, 1)")
field(FLNK, "$(P)vacuum")
}
#
# Convert to IEEE-754 32-bit float.
# No INF/NAN, no denormalized numbers.
#
record(calc,"$(P)vacuum") {
field(INPA, "$(P)vacuumHiWord")
field(INPB, "$(P)vacuumLoWord")
field(INPC, "0x8000") # Hi word, sign bit
field(INPD, "0x7F80") # Hi word, exponent mask
field(INPE, "0x00FF") # Hi word, mantissa mask (incl hidden bit)
field(INPF, "150") # Exponent offset plus 23-bit mantissa shift
field(INPG, "0x0080") # Mantissa hidden bit
field(INPJ, "65536") # Hi/Lo mantissa ratio
field(CALC, "(A&D?(A&C?-1:1):0)*((G|A&E)*J+B)*2^((A&D)/G-F)")
field(PREC, "4")
}
On Sep 21, 2011, at 7:43 AM, Mark Rivers wrote:
> I'll see if I can beat Eric Norum in responding to this! He solved the
> same problem and sent me a solution yesterday.
>
--
Eric Norum
[email protected]
- References:
- Modbus data to float32 ? Olivier Zimmermann
- RE: Modbus data to float32 ? Mark Rivers
- Navigate by Date:
- Prev:
RE: Modbus data to float32 ? Mark Rivers
- Next:
Fwd: Time, technology and leaping seconds Andrew Johnson
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
<2011>
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
RE: Modbus data to float32 ? Mark Rivers
- Next:
Epics C# Library problems Perrier Pierre
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
<2011>
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|