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 2025 | 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 2025 |
<== Date ==> | <== Thread ==> |
---|
Subject: | Re: stream protocol question: ASCII hex to 32-bit float |
From: | Florian Feldbauer <[email protected]> |
To: | Kevin Peterson <[email protected]>, EPICS tech talk <[email protected]> |
Date: | Thu, 10 Mar 2016 17:39:03 +0100 |
Hey Kevin, I had the same problem once with a HV power supply. I solved the problem this way: - Read the value via StreamDevice into a longin record - Use a sub-record to convert 32bit-int to 32bit-float The subroutine is quiet easy: union ficonv{ float float_val; unsigned int int_val; }; static long intToFloat(subRecord *prec) { union ficonv myconf; myconf.int_val = prec->a; prec->b = myconf.float_val; return 0; } I hope this helps! Cheers Florian On 03/10/2016 05:28 PM, Kevin Peterson wrote:
I have a helium sensor that responds to a query with this reply: :80gv<VVVVVVVV><FFFFFFFF><CCCC><cr> Where the non-constant parts of the response are ASCII hex characters representing the following values: <VVVVVVVV> = (32 bit floating point) The current gas value <FFFFFFFF> = (32 bit unsigned integer) The sensor status <CCCC> = (16 bit unsigned integer) The message checksum Is there a straightforward way to parse the floating point value using StreamDevice format converters? The raw double converter %R doesn't work, presumably because it is interpreting the ASCII chars as bytes, rather than hex values. The value can be read as an int with %08X, but it isn't obvious how to then cast that value as a float. Thanks, Kevin
-- ---------------------------------------- | Dr. Florian Feldbauer | | | | Helmholtz-Institut Mainz / | | Johannes Gutenberg-Universität Mainz | | Johann-Joachim-Becher-Weg 36 | | D-55128 Mainz | | | | Office: SB1 / 00-213 | | Phone: (+49)6131 / 39-29608 | ----------------------------------------