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: Get the type of a PV in C++ API |
From: | Michael Davidsaver via Tech-talk <tech-talk at aps.anl.gov> |
To: | Eusebio Naif Al-Soliman Fuentes <eunaif at correo.ugr.es> |
Cc: | Tech Talk <tech-talk at aps.anl.gov> |
Date: | Fri, 3 Nov 2023 11:14:42 -0700 |
Hello everybody.I have a small question. In the pvaClient library for C++ (https://docs.epics-controls.org/projects/pvaclient-cpp/en/latest/) there are many examples to get the value and other fields of a PV.However, in order to get the value as a double, like in this example https://github.com/epics-rip/exampleCPP/blob/master/exampleClient/src/examplePvaClientGet.cpp,
Is should point out that this URL is in the "epics-rip"
organization, which we use as a final resting place for abandoned
code. Not something I would recommend as a starting point for a
new development.
you have to previously know that the PV value is a double. Is there any method to get the type (int, long, double...) of the value field? Something like ->getType().
This was a common pain point in early versions of pvDataCPP API.
Certainly for me, which I why I extended the "intermediate"
interface classes PVScalar and PVScalarArray with the getAs() and
putFrom() methods to attempt some conversion. Of course to use
these, you will still need to check if a field as a scalar or
array of scalars. (as opposed to a union, sub-structure, variant,
or arrays of these same)
Another common "gotcha" to watch out when looking through these obsolete examples are calls to getSubField() which do not check for a returned NULL An alternate form getSubFieldT() exists which throws an exception instead.
With PVXS, I tried to design the API to avoid these common mistakes and others.
For a longer discussion, see:
https://mdavidsaver.github.io/pvxs/overview.html#comparison-with-pvdatacpp
Thanks in advance.--
Saludos/Best regards
University of Granada
Eusebio Naif Al-Soliman Fuentes
MSc. Data Science and Computer Engineering