Hi Dehong,
On 2012-12-13 Zhang, Dehong wrote:
>
> I am writing a custom record to deal with a particular hardware. This
> hardware has a few different operation modes, which are represented
> with a set of name strings, not numbers. We can talk to it to get or set
> this mode, with strings.
>
> The problem is, when a choice is made, we get a menu choice number.
> Then I will need to find the corresponding name string, to write to the
> hardware; on the other direction, when I query the hardware to find its
> current mode, I get back a string. Then I need to find the corresponding
> choice number to set the button properly.
>
> All these name strings are defined in the menu definition. How can I
> access them inside the record support? Without having to declare
> an array of strings, beside the menu definition?
dbStaticLib.h defines the function
dbMenu* dbFindMenu(DBBASE *pdbbase, const char *name);
The dbMenu structure is defined in dbBase.h which gets included by
dbStaticLib.h anyway.
So to access the choice strings you could use a function like this:
const char * menuChoice(const char *menuName, epicsEnum16 index)
{
dbMenu pMenu = dbFindMenu(pdbbase, menuName);
if (!pMenu || index >= pMenu->nChoice)
return NULL;
return pMenu->papChoiceName[index];
}
Note that dbFindMenu() uses a hash table which is reasonably fast, but you
might still want to do the lookup just once at initialization and save the
dbMenu pointers for all your menus.
The disadvantage of making your menu choices identical to the strings that you
use to communicate with the device is that you can't change their wording to
make them easier for your users to understand. I would think carefully about
that before using the above code, although there's nothing inherently wrong
with using this approach if that's acceptable.
HTH,
- Andrew
--
Computer science is as much about computers as astronomy is about
telescopes. -- Edsger Dijkstra
- References:
- How to access menu choice strings inside record support Zhang, Dehong
- Navigate by Date:
- Prev:
Re: How to access menu choice strings inside record support Till Straumann
- Next:
EPICS 3.14.12.2 on VirtualBox Jiro Fujita
- 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: How to access menu choice strings inside record support Till Straumann
- Next:
EPICS 3.14.12.2 on VirtualBox Jiro Fujita
- 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
|