Thanks Andrew and Mathias,
The problem is that I need to retrieve this string in the aSub Init routine, as it states here: field(INAM,"myfunctionInit"). At that point, the stringout record might not be processed yet. I suppose the PP key is to force the other record to be processed afterwards. Even when I set the stringout record PINI=1, and place it before my aSub record. This comes to another question, what is the order when the database records are read and initialised?
Jim
-----Original Message-----
From: Andrew Johnson [mailto:[email protected]]
Sent: 28 September 2012 16:15
To: [email protected]
Cc: Jim Chen
Subject: Re: problem passing string to aSub record parameter
Hi Jim,
On 2012-09-28 Jim Chen wrote:
> Can anybody help please -- passing STRING to aSub record parameter
> field doesn’t seem to work.
>
> My aSub record
>
> record(aSub,"TRANSMIT")
> {
> field(INAM,"myfunctionInit")
> ……
> field(INPA,"Test string")
> field(FTA,"STRING")
> field(NOA,"20")
> ……
> }
>
> myfunctionInit(aSubRecord * pSub)
> {
> ……
> char test[40];
> strcpy(test, (char *)subr->a);
>
> printf("Text: %s\n", test);
> ……
> }
>
> The printf statement doesn’ t print anything. When I check the length
> of the ‘test’ variable, it is always 0.
The problems here are mostly in the record definition rather than in your code.
First, these two settings
field(FTA,"STRING")
field(NOA,"20")
configure the record to be an array of 20 DBF_STRINGs. Effectively they cause the record initialization code to do this:
prec->a = calloc(20, MAX_STRING_SIZE);
I'm guessing that you probably only meant to request storage for a single string, so change the NOA setting to 1.
Second, this setting
field(INPA,"Test string")
configures INPA to be a link to some PV called "Test"; in the likely event that there is no record with this name it will result in a request to Channel Access for a . EPICS does not allow you to initialize a string field through an INP or DOL link using a constant string, because the IOC has no way to know that the string isn't a PV name. The only reason this works for numbers is because the IOC checks whether the initialization string is accepted without error by either strtod() or strtol().
The simplest way to do this is to create a separate stringin (or stringout) record and initialize its VAL field to the constant string you want. Then point the INPA link of your record to that new record (Mathias Steiner just posted that solution).
- Andrew
--
Never interrupt your enemy when he is making a mistake.
-- Napoleon Bonaparte
- Replies:
- RE: problem passing string to aSub record parameter Jim Chen
- Re: problem passing string to aSub record parameter Andrew Johnson
- References:
- problem passing string to aSub record parameter Jim Chen
- Re: problem passing string to aSub record parameter Andrew Johnson
- Navigate by Date:
- Prev:
Re: camon: multiple servers found? Andrew Johnson
- Next:
Re: Loading modbus waveform record from acalcout record (or caput) Tim Mooney
- 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: problem passing string to aSub record parameter Andrew Johnson
- Next:
RE: problem passing string to aSub record parameter Jim Chen
- 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
|