EPICS Component Reference Manual


EPICS Reference: Array Subroutine Record (aSub) §

The aSub record is an advanced variant of the 'sub' (subroutine) record which has a number of additional features:

This record type was included in base.dbd beginning with epics-base 3.14.10 .

Record-specific Menus §

The LFLG menu field controls whether the SUBL link will be read to update the name of the subroutine to be called when the record processes.

IndexIdentifierChoice String
0 aSubLFLG_IGNORE IGNORE
1 aSubLFLG_READ READ

The EFLG menu field indicates whether monitor events should be posted for the VALA..VALU output value fields.

IndexIdentifierChoice String
0 aSubEFLG_NEVER NEVER
1 aSubEFLG_ON_CHANGE ON CHANGE
2 aSubEFLG_ALWAYS ALWAYS

Parameter Fields §

The record-specific fields are described below.

Subroutine Fields §

The VAL field is set to the value returned by the user subroutine. The value is treated as an error status value where zero mean success. The output links OUTA ... OUTU will only be used to forward the associated output value fields when the subroutine has returned a zero status. If the return status was less than zero, the record will be put into SOFT_ALARM state with severity given by the BRSV field.

The INAM field may be used to name a subroutine that will be called once at IOC initialization time.

LFLG tells the record whether to read or ignore the SUBL link. If the value is READ, then the name of the subroutine to be called at process time is read from SUBL. If the value is IGNORE, the name of the subroutine is that currently held in SNAM.

A string is read from the SUBL link to fetch the name of the subroutine to be run during record processing.

SNAM holds the name of the subroutine to be called when the record processes. The value in this field can be overwritten by the SUBL link if LFLG is set to READ.

The SADR field is only accessible from C code; it points to the subroutine to be called.

The CADR field may be set by the user subroutine to point to another function that will be called immediately before setting the SADR field to some other routine. This allows the main user subroutine to allocate resources when it is first called and be able to release them again when they are no longer needed.

FieldSummaryTypeDCT DefaultReadWriteCA PP
VALSubr. return valueLONGNo YesYesNo
OVALOld return valueLONGNo YesNoNo
INAMInitialize Subr. NameSTRING [41]Yes YesNoNo
LFLGSubr. Input EnableMENU (aSubLFLG)Yes YesYesNo
SUBLSubroutine Name LinkINLINKYes YesNoNo
SNAMProcess Subr. NameSTRING [41]Yes YesYesNo
ONAMOld Subr. NameSTRING [41]Yes YesNoNo
SADRSubroutine AddressNOACCESSNo NoNoNo
CADRSubroutine Cleanup AddressNOACCESSNo NoNoNo
BRSVBad Return SeverityMENU (menuAlarmSevr)Yes YesYesYes

Operator Display Parameters §

The PREC field specifies the number of decimal places with which to display the values of the value fields A ... U and VALA ... VALU. Except when it doesn't.

Output Event Flag §

This field tells the record when to post change events on the output fields VALA ... VALU. If the value is NEVER, events are never posted. If the value is ALWAYS, events are posted every time the record processes. If the value is ON CHANGE, events are posted when any element of an array changes value. This flag controls value, log (archive) and alarm change events.

FieldSummaryTypeDCT DefaultReadWriteCA PP
EFLGOutput Event FlagMENU (aSubEFLG)Yes1YesYesNo

The input links from where the values of A,...,U are fetched during record processing.

FieldSummaryTypeDCT DefaultReadWriteCA PP
INPAInput Link AINLINKYes YesYesNo
INPUInput Link UINLINKYes YesYesNo

Input Value Fields §

These fields hold the scalar or array values fetched through the input links INPA,...,INPU.

FieldSummaryTypeDCT DefaultReadWriteCA PP
AInput value ASet by FTA[NOA]No YesYesNo
UInput value USet by FTU[NOU]No YesYesNo

Input Value Data Types §

Field types of the input value fields. The choices can be found by following the link to the menuFtype definition.

FieldSummaryTypeDCT DefaultReadWriteCA PP
FTAType of AMENU (menuFtype)YesDOUBLEYesNoNo
FTUType of UMENU (menuFtype)YesDOUBLEYesNoNo

Input Value Array Capacity §

These fields specify how many array elements the input value fields may hold.

Note that access to the NOT field from C code must use the field name in upper case, e.g. prec->NOT since the lower-case not is a reserved word in C++ and cannot be used as an identifier.

FieldSummaryTypeDCT DefaultReadWriteCA PP
NOAMax. elements in AULONGYes1YesNoNo
NOUMax. elements in UULONGYes1YesNoNo

Input Value Array Size §

These fields specify how many array elements the input value fields currently contain.

FieldSummaryTypeDCT DefaultReadWriteCA PP
NEANum. elements in AULONGNo1YesNoNo
NEUNum. elements in UULONGNo1YesNoNo

The output links through which the VALA ... VALU field values are sent during record processing, provided the subroutine returned 0.

FieldSummaryTypeDCT DefaultReadWriteCA PP
OUTAOutput Link AOUTLINKYes YesYesNo
OUTUOutput Link UOUTLINKYes YesYesNo

Output Value Fields §

These fields hold scalar or array data generated by the subroutine which will be sent through the OUTA ... OUTU links during record processing.

FieldSummaryTypeDCT DefaultReadWriteCA PP
VALAOutput value ASet by FTVA[NOVA]No YesYesNo
VALUOutput value USet by FTVU[NOVU]No YesYesNo

Old Value Fields §

The previous values of the output fields. These are used to determine when to post events if EFLG is set to ON CHANGE.

FieldSummaryTypeDCT DefaultReadWriteCA PP
OVLAOld Output ANOACCESSNo NoNoNo
OVLUOld Output UNOACCESSNo NoNoNo

Output Value Data Types §

Field types of the output value fields. The choices can be found by following a link to the menuFtype definition.

FieldSummaryTypeDCT DefaultReadWriteCA PP
FTVAType of VALAMENU (menuFtype)YesDOUBLEYesNoNo
FTVUType of VALUMENU (menuFtype)YesDOUBLEYesNoNo

Output Value Array Capacity §

These fields specify how many array elements the output value fields may hold.

FieldSummaryTypeDCT DefaultReadWriteCA PP
NOVAMax. elements in VALAULONGYes1YesNoNo
NOVUMax. elements in VALUULONGYes1YesNoNo

Output Value Array Size §

These fields specify how many array elements the output value fields currently contain.

FieldSummaryTypeDCT DefaultReadWriteCA PP
NEVANum. elements in VALAULONGNo1YesNoNo
NEVUNum. elements in VALUULONGNo1YesNoNo

Old Value Array Size §

These fields specify how many array elements the old value fields currently contain.

FieldSummaryTypeDCT DefaultReadWriteCA PP
ONVANum. elements in OVLAULONGNo1YesNoNo
ONVUNum. elements in OVLUULONGNo1YesNoNo



Record Support Routines §

init_record §

  long (*init_record)(struct dbCommon *precord, int pass)

This routine is called twice at iocInit. On the first call it does the following:

On the second call, it does the following:

process §

  long (*process)(struct dbCommon *precord)

This routine implements the following algorithm:

Normal processing:

Asynchronous-completion processing:




Use of the aSub Record §

The aSub record has input-value fields (A-U) and output-value fields (VALA-VALU), which are completely independent. The input-value fields have associated input links (INPA-INPU), and the output-value fields have associated output links (OUTA-OUTU). Both inputs and outputs have type fields (FTA-FTU, FTVA-FTVU, which default to 'DOUBLE') and number-of-element fields (NOA-NOU, NOVA-NOVU, which default to '1'). The output links OUTA-OUTU will only be processed if the subroutine returns a zero (OK) status value.

Example database fragment §

To use the A field to read an array from some other record, then, you would need a database fragment that might look something like this:

    record(aSub,"my_asub_record") {
        field(SNAM,"my_asub_routine")
        ...
        field(FTA, "LONG")
        field(NOA, "100")
        field(INPA, "myWaveform_1 NPP NMS")
        ...
    }

If you wanted some other record to be able to write to the A field, then you would delete the input link above. If you wanted the A field to hold a scalar value, you would either delete the NOA specification, or specify it as "1".

Example subroutine fragment §

The associated subroutine code that uses the A field might look like this:

    static long my_asub_routine(aSubRecord *prec) {
        long i;
        epicsInt32 *a;

        double sum=0;
        ...
        a = (epicsInt32 *)prec->a;
        for (i=0; i<prec->noa; i++) {
            sum += a[i];
        }
        ...
        return 0; /* process output links */
    }

Note that the subroutine code must always handle the value fields (A-U, VALA-VALU) as arrays, even if they contain only a single element.

Required export code §

Aside from your own code, you must export and register your subroutines so the record can locate them. The simplest way is as follows:

    #include <registryFunction.h>
    #include <epicsExport.h>

    static long my_asub_routine(aSubRecord *prec) {
        ...
    }
    epicsRegisterFunction(my_asub_routine);

Required database-definition code §

The .dbd file loaded by the ioc must then contain the following line, which tells the linker to include your object file in the IOC binary:

    function(my_asub_routine)

Device support, writing to hardware §

The aSub record does not call any device support routines. If you want to write to hardware, you might use your output fields and links to write to some other record that can write to hardware.

Dynamically Changing the User Routine called during Record Processing §

The aSub record allows the user to dynamically change which routine is called when the record processes. This can be done in two ways:


EPICS Component Reference Manual