EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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

Subject: Re: "Exploding" a waveform into individual values
From: Marty Kraimer <[email protected]>
Date: Thu, 03 Jun 1999 08:24:33 -0500
Ron Chestnut wrote:
> 
> Hello All,
> 
> I think I've seen the answer to this, I may have even asked the question before.
> 
> I have a 10 element waveform (type float) from which I wish to extract each
> element into an individual AI.
> 
> I could code 10 individual subArray records, each mapped to another element, but
> a subroutine record seems easier. If my 10 element waveform VAL is linked to A
> of the subroutine record, is the code simply:
> 
> psub->b=psub->a[0]
> psub->c=psub->a[1], etc.?
> 
> That seems much too easy, and "a" is not an array, right?
> 
> /Ron Chestnut


The safe way to do this is

#include "dbAccess.h"
...


DBADDR *pdbAddr
...
pdbAddr = dbGetPdbAddrFromLink(&psub->inpa);
if(!pdbAddr) { /*ERROR DO SOMETHING*/}
...

The DBADDR structure contains all the info you need, i.e.

typedef struct dbAddr{
        struct dbCommon *precord;/* address of record                   */
        void    *pfield;        /* address of field                     */
        void    *pfldDes;       /* address of struct fldDes             */
        void    *asPvt;         /* Access Security Private              */
        long    no_elements;    /* number of elements (arrays)          */
        short   field_type;     /* type of database field               */
        short   field_size;     /* size (bytes) of the field being accessed */
        short   special;        /* special processing                   */
        short   dbr_field_type; /* field type as seen by database request*/
                                /*DBR_STRING,...,DBR_ENUM,DBR_NOACCESS*/
}DBADDR;


In particular

pfield is the addresss of actual data
no_elements is actual size of the array
field_type is the data type, i.e. DBF_xxx

You should check that the data type is what you expect, for example

if(pdbAddr->field_type != DBF_DOUBLE|| pdbAddr->no_elements<=myindex) {
    /*error */
} else {
   double mydata;
   double *subdata = (double *)pdbAddr->pfield;
   mydata = subdata[myindex]
}

If the array varies in size you should also call the subroutine RSET
get_array_info routine to get the current size (note that no_elements is the
maximum size). This can be done by

struct rset     *prset;
prset=dbGetRset(pdbAddr);
...
long *no_elements = 0;
long *offset = 0;

if(prset && (prset->get_array_info)) {
    status = (*prset->get_array_info)(pdbAddr,&no_elements,&offset)
   ...

}


Marty Kraimer


Navigate by Date:
Prev: subscribe Mathias
Next: Controlling Beamline Magnets Mathias
Index: 1994  1995  1996  1997  1998  <19992000  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: "Exploding" a waveform into individual values Noboru Yamamoto
Next: Controlling Beamline Magnets Mathias
Index: 1994  1995  1996  1997  1998  <19992000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 10 Aug 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·