esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

dc.mac
See other macros in category: Tools
Description:
    Data collector macros
Documentation:
    DESCRIPTION
    This macro set is intended to transfer information between SPEC and the data collector (DC). Data can be a single scalar or a vector. It is sent to and read from DC devices, identified by names. For reading or creating a DC device a command name must be specified.

    A first interface is provided through the macro dcsetup, which hooks into prompt_mac a command that puts on the specified DC device a fixed number of parameters.

    The other group of macros link motors and counters to DC devices. Macro sets cnt2dc and mot2dc store counter counts and motor positions on the DC, respectively. On the other hand, macro set dc2mot move motors to positions read from the DC, while reading from the DC to pseudo counters is made through the multim macros. The xx2yy macro sets share the same user interface: a setup macro and an add macro. All the macros allow the data on the DC be stored as scalars or vectors. In the case of vectors, different counters or motors can be linked to the same device by specifying different array positions.

    In the setup macros the DC device name is specified, as well as its size (1 for scalars) and command. In the case of cnt2dcsetup and mot2dcsetup, which are supposed to create the DC device, the variable type can also be specified; D_FLOAT_TYPE and D_VAR_FLOTARARR are used by default for scalar and vector devices, respectively. If counters or motors are specified at the end of the setup macros, they will be passed to the corresponding add macros, where they are associated to a position in the DC vector (0 for scalars).

    Reading from DC to counters is implemented thorugh multimsetup type=dc. Supported parameters are:
    • device: DC device name (mandatory)
    • cmd: device read command (mandatory)
    • arrsize: DC data size (optional, default: 0=scalar)
    • channel: index in vector (optional, default: scalar -> 0, vector -> config "channel" par.)
    If channel parameter is not specified, it will be set to 0 for scalar devices, or it will be taken from the "channel" counter parameter in the config file for vector devices. All the pseudo counters defined in the same multimsetup line will share the same device, so channel could not be speficified explicitely but stored in the config file. The cmd and arrsize parameters for a device can be omitted if another multimsetup type=dc with the same device specified those parameters before.

    EXAMPLE
    dcsetup ID00/Counters/1 blcounters S[det] S[mon] A[energy] MYSECRETNR
    Hooks into promt_mac a command that writes in ID00/Counters/1 the counts of det and mon, the position of motor energy and the value of the global variable MYSECRETNR
    cnt2dcsetup ID00/Counters/2 DevReadAll 5 D_VAR_FLOTARARR det 0 mon 1
    Initializes DC device ID00/Counters/2 with read command DevReadAll as vector of size 5 and links counters det and mon to its first 2 elements. Counter counts will be written on the DC after each count (user_getcounts).
    cnt2dcadd ID00/Counters/2 cnt1 2 cnt2 3 cnt3 4
    Links counters cnt1, cnt2 and cnt3 to the last 3 elements of the same device
    mot2dcsetup ID00/Energy/1 DevReadAll 3
    Initializes DC device ID00/Energy/1 with read command DevReadAll as vector of size 3.
    mot2dcadd ID00/Energy/1 mono 0 energy 1 u42u 2
    Links motors mono, energy and u42u to the same device. Motor positions will be written to the DC after each movement (user_getpangles and user_checkall).
    dc2motsetup ID00/MainRot/1 DevRead 1 mrot 0
    Links the scalar DC device ID00/MainRot/1 with motor mrot. The device will be read each time user_checkall is executed and the corresponding motor will be moved to the read position. A very simple loop can put a session in a "server mode":
    while (1) { mv dummy 0; sleep(0.1) }
    will read all the time the DC and move the mrot motor if necessary, provided that dummy is a non-hooked, NONE-type motor.
    multimsetup calorim type=dc device=ID00/Calorim/1 cmd=DevRead polltime=0.1
    Sets up the counter calorim to read the scalar DC device ID00/Calorim/1 with the command DevRead and a polling time of 0.1 seconds. polltime is a parameter recognized by multim macros. The final count will be the average of all the readings made. See multim.mac documentation for details.
    %LOG% history - 05/10/94 - ag - created 11/10/94 - jk - improved it radically 12/10/94 - ag - made it more generic 24/04/02 - ah - added counter and motor stuff $Revision: 4.3 $ $Log: dc.mac,v $ Revision 4.3 2008/02/27 16:42:30 rey documentation changes Revision 4.2 2007/01/21 11:34:42 ahoms Set arrsize=0 for scalars, allowing arrays with arrsize=1 Revision 4.1 2004/10/28 12:48:05 ahoms Added dc_create; DC readers will create and initialise devices if not exist. Device array size can be modified in SETUP. Changed to if-else style. Revision 4.0 2002/05/23 11:14:47 ahoms Added support for linking motors and counters to DC devices

    INTERNALS
    All macros (except dcsetup) share the same DC read/write mechanism. They are based in an associative array that store for each DC device the read command, the array size and all the numbers to write to or read from it. Thus only two functions are needed to access the DC: dc_put and dc_read. In the same way, the setup and add macros share the same interfaces, which are implemented in dc_low_setup and dc_low_add. The first macro initializes the particular internal array, and will call an add macro if motors/counters are specified. The second macro will call an inst macro for each channel specified and a post macro for the device. Those "user" macros are supposed to hook in the correct macros the reading or writing operations. The multim_read_dc uses the new internal variable loop_n supported by the multim macros for reading the DC only once per multim loop.

    DEPENDENCIES
    Reading from the DC to counters is made using multim macros.

Macros:
    dcsetup
    Usage: dcsetup dev-name key VAL1 .... VAL8
    Creates a pseudo device dev-name in data collector and hooks into prompt_mac to write the specified VALx as an array.

    cnt2dcsetup
    Usage: cnt2dcsetup dev-name dev-cmd arr-size [var-type] [cnt-name arr-pos] ...
    Defines a new DC device dev-name with size arr-size, command dev-cmd and type var-type, and links the specified counters to it by calling cnt2dcadd.

    cnt2dcadd
    Usage: cnt2dcadd dev-name cnt-name arr-pos [cnt-name arr-pos] ...
    Links the specified counters cnt-name to the DC device dev-name at position arr-pos.

    mot2dcsetup
    Usage: mot2dcsetup dev-name dev-cmd arr-size [var-type] [mot-name arr-pos] ...
    Defines a new DC device dev-name with size arr-size, command dev-cmd and type var-type, and links the specified motors to it by calling mot2dcadd.

    mot2dcadd
    Usage: mot2dcadd dev-name mot-name arr-pos [mot-name arr-pos] ...
    Links the specified motors mot-name to the DC device dev-name at position arr-pos.

    dc2motsetup
    Usage: dc2motsetup dev-name dev-cmd arr-size [mot-name arr-pos] ...
    Defines a new DC device dev-name with size arr-size and command dev-cmd, and links the specified motors to it by calling dc2motadd.

    dc2motadd
    Usage: dc2motadd dev-name mot-name arr-pos [mot-name arr-pos] ...
    Links the specified motors mot-name to the DC device dev-name at position arr-pos.

Internal Macros:
    dc_update
    Usage: dc_update dev-name key VAL1 .... VAL8
    update data collector with values

    dc_low_setup
    Usage: dc_low_setup (arr-name, add-mac-name, create-dev, setup-str)
    Analizes the setup-str (with format "dev-name cmd arr-size [var-type] [mot-cnt-name arrpos] ...") passed to the calling setup macro. Initializes the DC device dev-name (only if create-dev is non-zero) and the variables in the array arr-name, and calls the macro add-mac-name for linking motors/counters if they are specified. var-type is not analyzed if not create-dev. Asks the user if the values are not specified in the command line of the calling macro.

    dc_create
    Usage: dc_create (dev-name, cmd-name, var-type, arr-size)
    Creates a DC device

    dc_low_add
    Usage: dc_low_add (arr-name, setup-mac, is-cnt, chan-mac, post-mac, add-str)
    Analizes the add-str (with format "dev-name mot-cnt-name arrpos [cnt-name arr-pos] ...") passed to the calling "add" macro. Links the specified motors/counters mot-cnt-name to the the DC device dev-name (defined in arr-name by the macro setup-mac) at position arr-pos. is-cnt is 1 for counters and 0 for motors. The real hook is made by calling "chan-mac(dev-name, mot-cnt-name, arr-pos)" for every channel and "post-mac(dev-name)" for the device. Asks the user if the values are not specified in the command line of the calling macro.

    dc_put
    Usage: dc_put (arr-name, dev-name)
    Fills the DC device dev-name with the values previously stored in the array arr-name.

    dc_read
    Usage: dc_read (arr-name, dev-name)
    Reads the DC device dev-name into the array arr-name.

    cnt2dc_inst
    Usage: cnt2dc_inst (dev-name, cnt-name, arr-pos)
    Called by dc_low_add for each counter. Hooks into cnt2dc_getcounts the command for filling the C2DC array position arr-pos with the cnt-name counts.

    cnt2dc_post
    Usage: cnt2dc_post (dev-name)
    Called by dc_low_add for each DC device. Hooks into user_getcounts the command for filling all the DC devices, cnt2dc_getcounts, and hooks into it for filling the specified device dev-name.

    mot2dc_inst
    Usage: mot2dc_inst (dev-name, mot-name, arr-pos)
    Called by dc_low_add for each motor. Hooks into mot2dc_getangles the command for filling the M2DC array position arr-pos with the mot-name position.

    mot2dc_post
    Usage: mot2dc_post (dev-name)
    Called by dc_low_add for each DC device. Hooks into user_getpangles and user_finished1 the command for filling all the DC devices, mot2dc_getcounts, and hooks into it for filling the specified device dev-name.

    dc2mot_inst
    Usage: dc2mot_inst (dev-name, mot-name, arr-pos)
    Called by dc_low_add for each motor. Hooks into dc2mot_checkall the command for setting the mot-name position from the DC2M array index arr-pos.

    dc2mot_post
    Usage: dc2mot_post (dev-name)
    Called by dc_low_add for each DC device. Hooks into user_checkall the command for filling the motor angles array A[] from the DC devices, dc2mot_checkall, and hooks into it for reading the specified device dev-name.

    multim_init_dc
    Usage: multim_init_dc
    Called when multimsetup <cnt-mne> type=dc is invoked. Checks for the parameters dev, cmd, channel and arrsize. If channel is not specified it is taken from the config file; if arrsize is not specified it is set to 0. Parameters cmd and arrsize can be omitted if another DC multim counter was defined before with the same dev.

    multim_read_dc
    Usage: multim_read_dc
    Called from multim_readinstrument for counters with type=dc. Local variables cntr, ok and value are defined; the last two must be properly set. .

Filename: dc.mac
Author: AG, JK - 10/94, AH - 02/02
$Revision: 4.3 $ / $Date: 2008/02/27 16:42:30 $
Last mod.: 27/02/2008 17:42 by rey