Table of Contents Previous Chapter Chapter 4: ai - Analog Input

Chapter 4: ai - Analog Input

1. Introduction

The normal use for this record type is to obtain an analog value converted to engineering units. Most device support modules obtain values from hardware. Soft device modules are provided to obtain input via database or channel access links or via dbPutField or dbPutLink requests. The record supports alarm limits, conversion to engineering units, smoothing, and graphics and control limits.

Two soft device support modules are provided. One reads values directly into VAL. The other reads values into RVAL, which is then converted just like raw values obtained from hardware device support modules. If soft device support with a constant INP link is chosen, then the VAL field can be modified via dbPuts.

2. Field Summary

--------------------------------------------------------------
Field  Type       DCT  Initial  Access  Modify  Rec Proc   PP   
                                                Monitor         
--------------------------------------------------------------
VAL    DOUBLE     No   0        Yes     Yes     Yes        Yes  
INP    INLINK     Yes  0        No      No      N/A        No   
PREC   SHORT      Yes  0        Yes     Yes     No         No   
LINR   CVTCHOICE  Yes  0        Yes     Yes     No         Yes  
EGUF   FLOAT      Yes  0        Yes     Yes     No         Yes  
EGUL   FLOAT      Yes  0        Yes     Yes     No         Yes  
EGU    STRING     Yes  null     Yes     Yes     No         No   
HOPR   FLOAT      Yes  0        Yes     Yes     No         No   
LOPR   FLOAT      Yes  0        Yes     Yes     No         No   
AOFF   FLOAT      Yes  0        Yes     Yes     No         Yes  
ASLO   FLOAT      Yes  1        Yes     Yes     No         Yes  
SMOO   FLOAT      Yes  0        Yes     Yes     No         No   
HIHI   FLOAT      Yes  0        Yes     Yes     No         Yes  
LOLO   FLOAT      Yes  0        Yes     Yes     No         Yes  
HIGH   FLOAT      Yes  0        Yes     Yes     No         Yes  
LOW    FLOAT      Yes  0        Yes     Yes     No         Yes  
HHSV   GBLCHOICE  Yes  0        Yes     Yes     No         Yes  
LLSV   GBLCHOICE  Yes  0        Yes     Yes     No         Yes  
HSV    GBLCHOICE  Yes  0        Yes     Yes     No         Yes  
LSV    GBLCHOICE  Yes  0        Yes     Yes     No         Yes  
HYST   DOUBLE     Yes  0        Yes     Yes     No         No   
ADEL   DOUBLE     Yes  0        Yes     Yes     No         No   
MDEL   DOUBLE     Yes  0        Yes     Yes     No         No   
ROFF   LONG       No   0        Yes     Yes     No         Yes  
ESLO   DOUBLE     No   1        Yes     No      No         No   
LALM   DOUBLE     No   0        Yes     No      No         No   
ALST   DOUBLE     No   0        Yes     No      No         No   
MLST   DOUBLE     No   0        Yes     No      No         No   
PBRK   NOACCESS   No   4        No      No                 No   
INIT   SHORT      No   0        Yes     No      No         No   
LBRK   SHORT      No   0        Yes     No      No         No   
RVAL   LONG       No   0        Yes     Yes     Yes        Yes  
ORAW   LONG       No   0        Yes     No      No         No   
SIOL   INLINK     Yes  0        No      No      N/A        No   
SVAL   DOUBLE     No   0        Yes     Yes     No         No   
SIML   INLINK     Yes  0        No      No      N/A        No   
SIMM   GBLCHOICE  No   0        Yes     Yes     No         No   
SIMS   GBLCHOICE  Yes  0        Yes     Yes     No         No   
--------------------------------------------------------------

3. Field Descriptions

-----------------------------------------------------------------------------------------
Name  Summary               Description                                                    
-----------------------------------------------------------------------------------------
VAL   Value Field           Unless INP is a constant link and the device support           
                            module specifies no conversion, this is the value resulting    
                            from the record being processed. If INP is a constant, then    
                            VAL is initialized to the INP value but can be changed         
                            dynamically via dbPutField or dbPutLink.                       
INP   Input Link            This field is used by the device support routines to obtain    
                            input. For soft analog records it can be a constant, a         
                            database link, or a channel access link.                       
PREC  Display Precision     Precision with which to display VAL and OVAL.  This field      
                            is used by record support to supply a value when               
                            get_precision is called.                                       
LINR  Conversion Type       No conversion, linear and breakpoint table conversion are      
                            supported.                                                     
EGUF  Engineering Units     These fields are used to perform linear conversions. It is     
      Full                  the responsibility of the device support routines to use       
                            EGUF and EGUL to compute ESLO and ROFF.  EGUF and              
                            EGUL must be set by the user to the engineering units          
                            corresponding to the high and low ADC limits. For              
                            example if the ADC has a range of -10 to +10 Volts, then       
                            EGUF must be the engineering units value corresponding         
                            to 10 volts and EGUL to -10 volts. If a linear conversion is   
                            specified, recAi uses ESLO, ROFF,  and EGUL to convert         
                            the raw value to engineering units according to the            
                            formula:                                                       
                              VAL = (RVAL + ROFF)*ESLO + EGUL                              
EGUL  Engineering Units                                                                    
      Low                                                                                  
ROFF  Raw Value Offset                                                                     
ESLO  Slope for Linear                                                                     
      Conversions                                                                          
EGU   Engineering Units     An ASCII string of up to 16 characters describing the          
                            engineering units.  This field is used by record support to    
                            supply a units description string when get_units is            
                            called.                                                        
HOPR  High Operating        These fields determine the upper and lower display limits      
      Range                 for graphics displays and the upper and lower control          
                            limits for control displays. The fields are used by record     
                            support to honor calls to get_graphic_double or                
                            get_control_double.                                            
LOPR  Low Operating                                                                        
      Range                                                                                
AOFF  Adjustment Offset     These fields are adjustment parameters for the raw input       
                            values. They are applied to the raw data value returned by     
                            the device support routine before any other conversions        
                            are performed.                                                 
ASLO  Adjustment Slope                                                                     
SMOO  Smoothing Factor      The converted data value is subjected to the following         
                            algorithm:                                                     
                            val =  newvalue * (1 - smoo) + oldvalue * smoo                 
                            SMOO should have a value between 0 and 1, with 0               
                            meaning no smoothing and 1 meaning ultimate smoothing          
                            (in fact, the data value will never change).                   
HIHI  Hihi Alarm Limit      These fields specify the alarm limits and severities.          
HIGH  High Alarm Limit                                                                     
LOW   Low Alarm Limit                                                                      
LOLO  Lolo Alarm Limit                                                                     
HHSV  Hihi Alarm Severity                                                                  
HSV   High Alarm Severity                                                                  
LSV   Low Alarm Severity                                                                   
LLSV  Lolo Alarm Severity                                                                  
HYST  Alarm Deadband        These parameters specify hysteresis factors for triggering     
                            monitors by a call to db_post_event or monitor                 
                            callbacks, i.e. callbacks specified by calls to                
                            caAddEvent or dbAddEvent. A monitor will not be                
                            triggered until VAL changes by more than the specified         
                            amount.                                                        
ADEL  Archive Deadband                                                                     
MDEL  Monitor, i.e. value                                                                  
      change, Deadband                                                                     
LALM  Last Alarm Monitor    These fields are used to implement the hysteresis factors      
      Trigger Value         for monitor callbacks.                                         
ALST  Last  Archiver                                                                       
      Monitor Trigger                                                                      
      Value                                                                                
MLST  Last Value Change                                                                    
      Monitor Trigger                                                                      
      Value                                                                                
INIT  Initialize            This field is used by record support to perform                
                            initialization for LBRK and for smoothing.                     
LBRK  Last Breakpoint       Index of last breakpoint interval.  LBRK is used to perform    
                            conversions via breakpoint tables.                             
PBRK  Address of            PBRK is  used to perform conversions via breakpoint            
      Breakpoint Table      tables.                                                        
RVAL  Raw Value             RVAL is the raw data value obtained by the device support      
                            routine. Unless the device support routine returns value       
                            requests that no conversion should be performed, the           
                            record support routine converts this value to engineering      
                            units.                                                         
ORAW  Old Raw Value         ORAW is used to decide if monitors should be triggered for     
                            RVAL at the same time monitors are triggered for changes       
                            in VAL.                                                        
SIMM  Simulation Mode       Simulation mode process variables.  Refer to Chapter 3         
                            Section "Simulation Mode" on page 11 for more                  
                            information.                                                   
SIML  Simulation Mode                                                                      
      Location                                                                             
SVAL  Simulation Value                                                                     
SIOL  Simulation Value                                                                     
      Location                                                                             
SIMS  Simulation Mode                                                                      
      Alarm Severity                                                                       
-----------------------------------------------------------------------------------------

4. Record Support Routines

init_record

This routine initializes SIMM with the value of SIML if SIML type is CONSTANT link or creates a channel access link if SIML type is PV_LINK. SVAL is likewise initialized if SIOL is CONSTANT or PV_LINK.

This routine next checks to see that device support is available and a device support read_ai routine is defined. If either does not exist, an error message is issued and processing is terminated.

INIT is then set to TRUE.

If device support includes init_record, it is called.

process

See next section.

special

The only special processing for analog input records is SPC_LINCONV. which is invoked whenever any of the fields LINR, EGUF, EGUL or ROFF is changed.

If the device support routine special_linconv exists, it is called.

INIT is set TRUE. This causes PBRK, LBRK, and smoothing to be reinitialized.

get_value

Fills in the values of the structure valueDes so that they refer to VAL.

get_units

Retrieves EGU.

get_precision

Retrieves PREC.

get_graphic_double

Sets the upper display and lower display limits for a field. If the field is VAL, HIHI, HIGH, LOW, or LOLO, the limits are set to HOPR and LOPR, else if the field has upper and lower limits defined they will be used, else the upper and lower maximum values for the field type will be used.

get_control_double

Sets the upper control and the lower control limits for a field. If the field is VAL, HIHI, HIGH, LOW, or LOLO, the limits are set to HOPR and LOPR, else if the field has upper and lower limits defined they will be used, else the upper and lower maximum values for the field type will be used.

get_alarm_double

Sets the following values:

  upper_alarm_limit = HIHI
  upper_warning_limit = HIGH
  lower_warning_limit = LOW
  lower_alarm_limit = LOLO

5. Record Processing

Routine process implements the following algorithm:

  1. Check to see that the appropriate device support module exists. If it doesn't, an error message is issued and processing is terminated with the PACT field set to TRUE. This ensures that processes will no longer be called for this record. Thus error storms will not occur.
  2. readValue is called. See Chapter 3 Section "Simulation Mode" on page 11 for details.
  3. If PACT has been changed to TRUE, the device support read routine has started but has not completed writing the new value. In this case, the processing routine merely returns, leaving PACT TRUE.
  4. PACT is then set to TRUE, TIME is set to tslocaltime and the return status value of readValue is checked. convert is called only if status is 0. If status is 2, then convert is not called, but status is reset to 0.
  5. convert (if necessary): The new raw data value is expected to be in field RVAL. The first step is to set val equal to RVAL + ROFF. The next step is to adjust the raw value via the equation:
        val = val* ASLO + AOFF
    
    If the conversion algorithm is linear, the raw value is converted via the equation:
        val = val * ESLO + EGUL
    
    If the conversion is via a breakpoint table, the new value is obtained.
    The next step is to apply the following smoothing algorithm:
        if SMOO  equal to 0. or  INIT is True, VAL = val 
        else VAL = val * (1 - SMOO) + Previous_value * SMOO 
    
    Since VAL is now defined, the last step is to set UDF to FALSE.
  6. Check alarms: This routine checks to see if the new VAL causes the alarm status and severity to change. If so, NSEV, NSTA and LALM are set. It also honors the alarm hysteresis factor (HYST). Thus the value must change by more than HYST before the alarm status and severity is lowered.
  7. Check to see if monitors should be invoked:
  8. Scan forward link if necessary, set PACT and INIT to FALSE, and return.

6. Device Support

Fields Of Interest To Device Support

Each analog input record must have an associated set of device support routines. The primary responsibility of the device support routines is to obtain a new raw analog input value whenever read_ai is called. The device support routines are primarily interested in the following fields:

---------------------------------------------------------------------------------------------
Name  Summary                 Description                                                      
---------------------------------------------------------------------------------------------
PACT  Processing Active       See Chapter 2 Section "Database Common: Field                    
                              Descriptions" on page 4 for descriptions.                        
DPVT  Device Private                                                                           
UDF   VAL Undefined                                                                            
NSEV  New Alarm Severity                                                                       
NSTA  New Alarm Status                                                                         
VAL   Value                   This field is used by device support only if it obtains a        
                              value already converted to engineering units. See RVAL           
                              below.                                                           
INP   Input Link              This field is used by the device support routines to locate      
                              its input.                                                       
EGUF  Engineering Units Full  These fields are used to calculate ESLO. Note that these         
                              fields correspond to the high and low hardware limits.           
EGUL  Engineering Unit Low                                                                     
ESLO  Slope                   These fields are used  for linear conversions from raw to        
                              engineering units. The device support routines must              
                              calculate these fields unless they obtain values already in      
                              engineering units.                                               
ROFF  Raw Offset                                                                               
RVAL  Raw Value               It is the responsibility of the device support routine to give   
                              this field a value. If the device support routine obtains a      
                              value already in engineering units, it should place the          
                              value in VAL and return a value of 2.                            
---------------------------------------------------------------------------------------------

Device Support Routines

Device support consists of the following routines:

report

  report (FILE fp, paddr)
Not currently used.

init

  init()
This routine is called once during IOC initialization.

init_record

  init_record (precord)
This routine is optional. If provided, it is called by the record support init_record routine.

get_ioint_info

  get_ioint_info (int cmd,struct dbCommon *precord,IOSCANPVT *ppvt)
This routine is called by the ioEventScan system each time the record is added or deleted from an I/O event scan list. cmd has the value (0,1) if the record is being (added to, deleted from) an I/O event list. It must be provided for any device type that can use the ioEvent scanner.

read_ai

  read_ai(precord)
This routine must provide a new input value. Asynchronous device support routines will return with PACT set to TRUE. If PACT is TRUE, the process routine will just return and not continue processing. When the asynchronous routine completes, it can call process which will again call read_ai. Because PACT is still TRUE read_ai knows that this is a request to retrieve the data obtained by the previous call. When finished, read_ai should set PACT to FALSE and return one the following values:

special_linconv

  special_linconv(precord,after) 
This routine is called whenever any of the fields LINR, EGUF, EGUL or ROFF is modified.

7. Device Support For Soft Records

Two soft device support modules Soft Channel and Raw Soft Channel are provided for input records not related to actual hardware devices. The INP link type must be either CONSTANT, DB_LINK or CA_LINK.

Soft Channel

This module places a value directly in VAL. read_ai always returns a value of 2, which means that no conversion will ever be attempted.

If the INP link type is constant, then the constant value is stored into VAL by init_record, and UDF is set to FALSE. If the INP link type is PV_LINK, then dbCaAddInlink is called by init_record.

read_ai calls recGblGetLinkValue to read the current value of VAL. See Chapter 3 Section "Soft Input" on page 10 for details.

If the return status of recGblGetLinkValue is zero, then read_ai sets UDF to FALSE. The status of recGblGetLinkValue is returned.

If soft support is chosen, the following fields become meaningless: LINR, EGUF, EGUL, ESLO, ROFF, AOFF, ASLO, and SMOO. The read_ai routine always returns a value of 2 which means don't convert.

Raw Soft Channel

This module is like the previous except that it places its value in RVAL and read_ai returns a value of 0. Thus the record processing routine will convert the raw value in the normal way.

If raw soft support is chosen, the fields EGUF and EGUL become meaningless. ESLO and ROFF always have their default values of 1 and 0.

 
Table of Contents Next Chapter