EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: problem passing string to aSub record parameter
From: Andrew Johnson <[email protected]>
To: [email protected]
Date: Fri, 28 Sep 2012 10:14:50 -0500
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
References:
problem passing string to aSub record parameter Jim Chen

Navigate by Date:
Prev: RE: problem passing string to aSub record parameter Steiner, Mathias
Next: Re: camon: multiple servers found? Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: problem passing string to aSub record parameter Steiner, Mathias
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  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·