I'll see if I can beat Eric Norum in responding to this! He solved the
same problem and sent me a solution yesterday.
*****************************************************************
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.
#
# 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, "5")
}
--
Eric Norum
[email protected]
*****************************************************************
Eric suggested that I put this in the Modbus documentation, which I will
do.
Note that I don't support Float32 values directly in the driver because
they are not part of the Modbus spec. There is no guarantee about byte
order, floating point format, etc. Modbus guarantees to do the
byte-order on 16-bit values correctly, but for any larger data type it
does not guarantee whether the most-significant 16-bit word is the first
or last 16-bit register.
Mark
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Olivier Zimmermann
Sent: Wednesday, September 21, 2011 9:38 AM
To: [email protected]
Subject: Modbus data to float32 ?
Hello,
I'm starting with EPICS and trying to have a PV read a SGL/Float32 value
exposed by a modbus device (the value is stored on two 16bits-wide
holding registers).
To achieve this I'm using "Driver Support for Modbus Protocol under
EPICS".
http://cars9.uchicago.edu/software/epics/modbusDoc.html
Modbus data is retrieved as follows (i.e. using modbus function 4 to
retrieve two 16bit words at address 9) :
drvAsynIPPortConfigure("INSTR","192.168.##.##:502",0,1,1)
modbusInterposeConfig("INSTR",0,5000)
drvModbusAsynConfigure("INSTR:ReadFloat32","INSTR",1,4,9,2,0,50,
"InstrInterface")
What I just can't figure out is :
- How do I typecast this 32bit modbus data into a Float32 ?
- What "EPICS device support" should I use (asynFloat64, asynInt32...) ?
- Should my PV be an "ai" and where can I cast the right data type
within ?
Thanks for any help,
oz
- Replies:
- Re: Modbus data to float32 ? Eric Norum
- References:
- Modbus data to float32 ? Olivier Zimmermann
- Navigate by Date:
- Prev:
Epics C# Library problems Perrier Pierre
- Next:
Re: Modbus data to float32 ? Eric Norum
- 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:
Modbus data to float32 ? Olivier Zimmermann
- Next:
Re: Modbus data to float32 ? Eric Norum
- 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
|