This chapter describes database definitions. The following definitions are described:
Record Instances are fundamentally different from the other definitions. A file containing record instances should never contain any of the other definitions and vice-versa. Thus the following convention is followed:
This chapter also describes utility programs which operate on these definitions.
Any combination of definitions can appear in a single file or in a set of files related to each other via include statements.
The following summarizes the Database Definition syntax:
The Following defines a Record Instance
The following are keywords, i.e. they may not be used as values unless they are enclosed in quotes:
In the summary section, some values are shown as quoted strings and some unquoted. The actual rule is that any string consisting of only the following characters does not need to be quoted unless it contains one of the above keywords:
These are all legal characters for process variable names, although . is not allowed in a record name since it separates the record from the field name in a PV name. Thus in many cases quotes are not needed around record or field names in database files. Any string containing a macro does need to be quoted though.
A quoted string can contain any ascii character except the quote character ". The quote character itself can given by using a back-slash (\) as an escape character. For example "\"" is a quoted string containing a single double-quote character.
Macro substitutions are permitted inside quoted strings. Macro instances take the form:
or
There is no distinction between the use of parentheses or braces for delimiters, although the opening and closing characters must match for each macro instance. A macro name can be constructed using other macros, for example:
A macro instance can also provide a default value that is used when no macro with the given name has been defined. The default value can itself be defined in terms of other macros if desired, but may not contain any unescaped comma characters. The syntax for specifying a default value is as follows:
Finally macro instances can also set the values of other macros which may (temporarily) override any existing values for those macros, but the new values are in scope only for the duration of the expansion of this particular macro instance. These definitions consist of name=value sequences separated by commas, for example:
The database routines translate standard C escape sequences inside database field value strings only. The standard C escape sequences supported are:
\ooo represents an octal number with 1, 2, or 3 digits. \xhh represents a hexadecimal number which may have any number of hex digits, although only the last 2 will be represented in the character generated.
The comment symbol is “#”. Whenever the comment symbol appears outside of a quoted string, it and all subsequent characters through the end of the line will be ignored.
In general items cannot be referenced until they have been defined. For example a device definition cannot appear until the recordtype that it references has been defined or at least declared. Another example is that a record instance cannot appear until its associated record type has been defined.
One notable exception to this rule is that within a recordtype definition a menu field may reference a menu that has not been included directly by the record’s .dbd file.
If a menu, device, driver, or breakpoint table is defined more than once, then only the first instance will be used. Subsequent definitions may be compared to the first one and an error reported if they are different (the dbdExpand.pl program does this, the IOC currently does not). Record type definitions may only be loaded once; duplicates will cause an error even if the later definitions are identical to the first. However a record type declaration may be used in place of the record type definition in .dbd files that define device support for that type.
Record instance definitions are (normally) cumulative, so multiple instances of the same record may be loaded and each time a field value is encountered it replaces the previous value.
By convention:
The path string follows the standard convention for the operating system, i.e. directory names are separated by a colon “:” on Unix and a semicolon “;” on Windows.
The path statement specifies the current search path for use when loading database and database definition files. The addpath statement appends directories to the current path. The path is used to locate the initial database file and included files. An empty path component at the beginning, middle, or end of a non-empty path string means search the current directory. For example:
Utilities which load database files (dbExpand, dbLoadDatabase, etc.) allow the user to specify an initial path. The path and addpath commands can be used to change or extend that initial path.
The initial path is determined as follows:
The search path is not used at all if the filename being searched for contains a / or \ character. The first instance of the specified filename is used.
An include statement can appear at any place shown in the summary. It uses the search path as described above to locate the named file.
A record type statement that provides no field descriptions is a declaration, analagous to a function declaration (prototype) or forward definition in C. It allows the given record type name to be used in circumstances where the full record type definition is not needed.
Fields which operators normally change are assigned ASL0. Other fields are assigned ASL1. For example, the VAL field of an analog output record is assigned ASL0 and all other fields ASL1. This is because only the VAL field should be modified during normal operations.
A promptgroup should only be set for fields that can sensibly be configured in a record instance file.
The set of group names is no longer fixed. In earlier versions of Base the predefined set of choices beginning GUI_ were the only group names permitted. Now the group name strings found in the database definition file are collected and stored in a global list. The strings given for group names must match exactly for fields to be grouped together.
To support sorting and handling of groups, the names used in Base have the following conventions:
Record types may define their own group names. However, to improve consistency, records should use the following names from Base where possible. (This set also demonstrates that the group names used in different record types may share the same number.)
NOTE: Older versions of Base contained a header file guigroup.h defining a fixed set of group names and their matching index numbers. That header file has been removed. The static database access library now provides functions to convert between group index keys and the associated group name strings. See 14.7.6 for details.
The following values are for database common fields. They must not be used for record specific fields:
The following values are deprecated, use SPC_MOD instead:
The following is the definition of the event record type:
This can be used to register functions for use by subroutine records or that can be invoked from iocsh. The example application described in Section 2.2, “Example IOC Application” gives an example of how to register functions for subroutine records.
This registers a diagnostic/configuration variable for device or driver support or a subroutine record subroutine. This variable can be read and set with the iocsh var command (see Section 18.2.5. The example application described in Section 2.2 shows how to register a debug variable for use in a subroutine record.
In an application C source file:
In an application database definition file:
This registers a function so that it can be found in the function registry for use by record types such as sub or aSub which refer to the function by name. The example application described in Section 2.2 shows how to register functions for a subroutine record.
In an application C source file:
In an application database definition file:
NOTE: If macro substitutions are used the name must be quoted.
Duplicate definitions are normally allowed for a record as long as the record type is the same. The last value given for each field is the value used. If the duplicate definitions are being used and the record has already been loaded, subsequent definitions may use "⋆" in place of the record type in the record instance.
The variable dbRecordsOnceOnly can be set to any non-zero value using the iocsh var command to make loading duplicate record definitions into the IOC illegal.
The allowed values for the field depend on the device support’s link type as follows:
record is the name of a record that exists in this or another IOC.
The .field, process, and maximize parts are all optional.
The default value for .field is .VAL.
process can have one of the following values:
NOTES:
CP and CPP are valid only for DBF_INLINK fields.
DBF_FWDLINK fields can use PP or CA. If a DBF_FWDLINK is a channel access link it must reference the target record’s PROC field.
maximize can have one of the following values:
card – the card number of associated hardware module
signal – signal on card
parm – An arbitrary character string of up to 31 characters. This field is optional and is device
specific.
branch, crate, station, subaddress, and function should be obvious to camac users. subaddress and function are optional (0 if not given). parm is also optional and is device specific (25 characters max).
link – Scanner, i.e. vme scanner number
adapter – Adapter. Allen Bradley also calls this rack
card – Card within Allen Bradley Chassis
signal – signal on card
parm – optional device-specific character string (27 char max)
link – gpib link, i.e. interface
addr – GPIB address
parm – device-specific character string (31 char max)
link – link, i.e. vme bitbus interface
node – bitbus node
port – port on the node
signal – signal on port
parm – device specific-character string (31 char max)
parm – Device dependent character string
link – link, i.e. vme bitbus interface
bbadddr – bitbus address
gpibaddr – gpib address
parm – optional device-specific character string (31 char max)
frame – VXI frame number
slot – Slot within VXI frame
la – Logical Address
signal – Signal Number
parm – device specific character string(25 char max)
Information items provide a way to attach named string values to individual record instances that are loaded at the same time as the record definition. They can be attached to any record without having to modify the record type, and can be retrieved by programs running on the IOC (they are not visible via Channel Access at all). Each item attached to a single record must have a unique name by which it is addressed, and database access provides routines to allow a record’s info items to be scanned, searched for, retrieved and set. At runtime a void⋆pointer can also be associated with each item, although only the string value can be initialized from the record definition when the database is loaded.
Each record type can have any number of record attributes. Each attribute is a psuedo field that can be accessed via database and channel access. Each attribute has a name that acts like a field name but returns the same value for all instances of the record type. Two attributes are generated automatically for each record type: RTYP and VERS. The value for RTYP is the record type name. The default value for VERS is “none specified”, which can be changed by record support. Record support can call the following routine to create new attributes or change existing attributes:
The arguments are:
The menu menuConvert is used for field LINR of the ai and ao records. These records allow raw data to be converted to/from engineering units via one of the following:
Other record types can also use this feature. The first choice specifies no conversion; the second and third are both linear conversions, the difference being that for Slope conversion the user specifies the conversion slope and offset values directly, whereas for Linear conversions these are calculated by the device support from the requested Engineering Units range and the device support’s knowledge of the hardware conversion range. The remaining choices are assumed to be the names of breakpoint tables. If a breakpoint table is chosen, the record support modules calls cvtRawToEngBpt or cvtEngToRawBpt. You can look at the ai and ao record support modules for details.
If a user wants to add additional breakpoint tables, then the following should be done:
It is only necessary to load a breakpoint file if a record instance actually chooses it. It should also be mentioned that the Allen Bradley IXE device support misuses the LINR field. If you use this module, it is very important that you do not change any of the EPICS supplied definitions in menuConvert.dbd. Just add your definitions at the end.
If a breakpoint table is chosen, then the corresponding breakpoint file must be loaded into the IOC before iocInit is called.
Normally, it is desirable to directly create the breakpoint tables. However, sometimes it is desirable to create a breakpoint table from a table of raw values representing equally spaced engineering units. A good example is the Thermocouple tables in the OMEGA Engineering, INC Temperature Measurement Handbook. A tool makeBpt is provided to convert such data to a breakpoint table.
The format for generating a breakpoint table from a data table of raw values corresponding to equally spaced engineering values is:
The header line contains the following information:
An example definition is:
The breakpoint table can be generated by executing
The input file must have the extension of data. The output filename is the same as the input filename with the extension of .dbd.
Another way to create the breakpoint table is to include the following definition in a Makefile:
NOTE: This requires the naming convention that all data tables are of the form bpt<name>.data and a breakpoint table bpt<name>.dbd.
Given a file containing menu definitions, the program dbdToMenuH.pl generates a C/C++ header file for use by code which needs those menus. Given a file containing any combination of menu definitions and record type definitions, the program dbdToRecordtypeH.pl generates a C/C++ header file for use by any code which needs those menus and record type.
EPICS Base uses the following conventions for managing menu and recordtype definitions. Users generating local record types are encouraged to follow these.
Note that developers don’t normally execute the dbdToMenuH.pl or dbdToRecordtypeH.pl programs manually. If the proper naming conventions are used, it is only necessary to add definitions to the appropriate Makefile. Consult the chapter on the EPICS Build Facility for details.
This tool is executed as follows:
It reads in the input file menu.dbd and generates a C/C++ header file containing enumerated type definitions for the menus found in the input file.
Multiple -I options can be provided to specify directories that must be searched when looking for included files. If no output filename is specified with the -o menu.h option or as a final command-line parameter, then the output filename will be constructed from the input filename, replacing .dbd with .h.
The -D option causes the program to output Makefile dependency information for the output file to standard output, instead of actually performing the functions describe above.
For example menuPriority.dbd, which contains the definitions for processing priority contains:
The include file menuPriority.h that is generated contains:
Any code that needs the priority menu values should include this file and make use of these definitions.
This tool is executed as follows:
It reads in the input file xRecord.dhd and generates a C/C++ header file which defines the in-memory structure of the given record type and provides other associated information for the compiler. If the input file contains any menu definitions, they will also be converted into enumerated type definitions in the output file.
Multiple -I options can be provided to specify directories that must be searched when looking for included files. If no output filename is specified with the -o xRecord.h option or as a final command-line parameter then the output filename will be constructed from the input filename, replacing .dbd with .h.
The -D option causes the program to output Makefile dependency information for the output file to standard output, instead of actually performing the functions describe above.
For example aoRecord.dbd, which contains the definitions for the analog output record contains:
The include file aoRecord.h that is generated contains:
The analog output record support module and all associated device support modules should include this file. No other code should use it.
Let’s discuss the various parts of the file:
The generated routine aoRecordSizeOffset is executed when the record type gets registered with an IOC. The routine is compiled with the record type code, and is marked static so it will not be visible outside of that file. The associate record support source code MUST include the generated header file only after defining the GEN_SIZE_OFFSET macro like this:
This convention ensures that the routine is defined exactly once. The epicsExportRegistrar statement ensures that the record registration code can find and call the routine.
This program reads and combines the database definition from all the input files, then writes a single output file containing all information from the input files. The output content differs from the input in that comment lines are removed, and all defined macros and include files are expanded. Unlike the previous dbExpand program, this program does not understand database instances and cannot be used with .db or .vdb files.
Multiple -I options can be provided to specify directories that must be searched when looking for included files. Multiple -S options are allowed for macro substitution, or multiple macros can be specified within a single option. If no output filename is specified with the -o out.dbd option then the output will go to stdout.
The -D option causes the program to output Makefile dependency information for the output file to standard output, instead of actually performing the functions describe above.
This IOC command loads a database file which may contain any of the Database Definitions described in this chapter. The dbdfile string may contain environment variable macros of the form ${MOTOR} which will be expanded before the file is opened. Both the path and substitutions parameters can be null or empty, and are usually ommitted. Note that dbLoadDatabase should only used to load Database Definition (.dbd) files, although it is currently possible to use it for loading Record Instance (.db) files as well.
As each line of the file is read, the substitutions specified in substitutions are performed. Substitutions are specified as follows:
Variables are used in the file with the syntax $(var) or ${var}. If the substitution string
were used, any variables $(a), $(b), $(c) in the database file would have the appropriate values substituted during parsing.
This IOC command loads a file containing record instances, record aliases and/or breakpoint tables. The dbfile string may contain environment variable macros of the form ${MOTOR} which will be expanded before the file is opened. The substitutions parameter can be null or empty, and is often ommitted. Note that dbLoadRecords should only used to load Record Instance (.db) files, although it is currently possible to use it for loading Database Definition (.dbd) files as well.
For example, let the file test.db contain:
Then issuing the command:
gives the same results as loading:
This IOC command reads a template substitutions file which provides instructions for loading database instance files and gives values for the $(xxx) macros they may contain. This command performs those substitutions while loading the database instances requested.
The subfile parameter gives the name of the template substitution file to be used. The optional substitutions parameter may contain additional global macro values, which can be overridden by values given within the substitution file.
The MSI program can be used to expand templates at build-time instead of using this command at run-time; both understand the same substitution file syntax.
The template substitution file syntax is described in the following Extended Backus-Naur Form grammar:
Note that the current implementation may accept a wider range of characters for the last three definitions than those listed here, but future releases may restrict the characters to those given above.
Any record instance file names must appear inside quotation marks if the name contains any environment variable macros of the form ${ENV_VAR_NAME}, which will be expanded before the named file is opened.
Two different template formats are supported by the syntax rules given above. The format is either:
or:
The first line (file name.template) specifies the record instance input file. The file name may appear inside double quotation marks; these are required if the name contains any characters that are not in the following set, or if it contains environment variable macros of the form ${VAR_NAME} which must be expanded to generate the file name:
Each set of definitions enclosed in {} is variable substitution for the input file. The input file has each set applied to it to produce one composite file with all the completed substitutions in it. Version 1 should be obvious. In version 2, the variables are listed in the pattern{} line, which must precede the braced substitution lines. The braced substitution lines contains sets which match up with the pattern{} line.
Two simple template file examples are shown below. The examples specify the same substitutions to perform: this=sub1 and that=sub2 for a first set, and this=sub3 and that=sub4 for a second set.
Assume that the file test.template contains:
Using dbLoadTemplate with either input is the same as defining the records: