ScriptContext

ScriptContext in SEA

ScriptContext describes a system for asynchronous drivers in SICS/SEA written in Tcl. Such a driver is a collection of initialization and action scripts. The action scripts are called from the ScriptContext system within a certain context: a sics hipadaba node and a controller object.

Tutorial

Reference


to be done

If different drivers share common code, the common code may be placed in ~/sea/tcl/common/. The individual drivers may then contain only an appropriate source command.


SicsInitializer

New Initialization Scheme for SICS

The idea behind this scheme is, to have to edit only one list when adding a new feature. The aim is not to make the source code shorter. In fact, the initialization code is just moved from a central place to the modules. The main goal is to have a better structure of the code, which should be easier to maintain, and less error-prone.

Let us look at the difference when adding a command or driver. Before using this scheme, there were many different places in psi/psi.c where modifications had to be added:

when adding a new command:

when adding a new driver:

With the new scheme, for a module one has one init function, with prototype "void (void)" placed in the source file of the module. In this function, you call AddCmd, AddIniCmd or AddCommand(SCinter.h) to insert a standalone command, startup command or an object command. To create a new driver, use either the MakeDriver function, if you want to use the MakeObject command to create the driver, or the functions MakeInitializer/GetInitializer, if you want to do use an other factory command (see initializer.h). The init function has to be added to the system by inserting one line to the SiteInit (psi.c) or InitGeneral (ofac.c) function.

Suggestion by Markus Zolliker

At present, only the new stuff I inserted uses this scheme. I propose to move to the new scheme during next shutdown.

ofac.c:

psi.c:

These modifications will not change the behaviour of SICS.


SICSRemoteObjects

SICS Remote Objects

A remote object is a link to an object on an other SICS server. The remote object behaves almost equally as if it would live on the same server. At present, the driveable and the callback interface ist supported.

For any remote server supported, there is a remserver object which may be created with the command

remob server <remserver> <host>:<port>

where <remserver> is the name of the remserver object, <host> is the host running the remote SICS server, and <port> is its ServerPort. The remserver may be used to execute commands on the other server.

Usage of a Remserver

<remserver> <remote command>
execute a command on a remote server (waiting for the response)
<remserver>
return the host:port of the remote server and the host:port of the executing server
<remserver> nowait <remote command>
execute a command on a remote server (do not wait for the response). This is useful, if you want to start a script on a remote server which needs access to the calling server.
<remserver> markForDel
mark all remote objects for this remserver for deletion
<remserver> delMarked
delete all marked remote objects for this remserver. (Note: if a remote object was overwritten since markForDel, it is not deleted).

Create Remote Objects

remob drv <object name> <remserver>
create (or overwrite) a new remob driveable object linked with an object with the same name on the specified remote server.
remob obj <object name> <remserver>
create (or overwrite) a new remob object (not driveable)
remob del <object name>
delete a remote object

Results and Messages from Remote Objects

The result of any command is returned transparently. There is only one visible diffrence: all lines are prefixed with 2 spaces. Messages emitted on the remote server are forwarded to the master client. During a drive or run, the master client is the starting client. If no remote object is driving, any command executed on a client with at least user right makes it a master client.


SicsStrObj

StrObj

A string object is similar to a SICS variable (created with VarMake) but with the following differences:

Creating a StrObj variable is done with

  makeobject <variable name> string
Setting the value has a different syntax from SICS variables:
  <variable> = <value>
This syntax is used for all variables based on pardef. It is used in order to have a clear distinction between a subcommand and setting the main value of an object. If someone wants to perform the interest subcommand, and writes vars intrest and vars is a StrObj, then an error message is written because of the typo. If vars would be a SICS variable, its value would get overwritten, which is a less desired behaviour.

The variable vars is a special variable of this type, used by the graphical sea client to obatin a list of variables beeing to be plotted. The value is a space delimited list of variables. After each variable, an identifier might be put, separated with a slash, indicating the plot window to be used. A convention is to put the unit name as identifer for the plot window. Example:

  vars = te/K te.t2/K te.htr/%
On the graph, two plots will appear, in the first plot the variables te and te.ts are shown, in the second the variable te.htr is shown.
SicsEase

EASE - An Easy Way to Write Sample Environment Drivers

Motivation

Drivers for sample environment (SE) have some special demands which were not fully supported by the original SICS environment controller (EVC):

pardef

pardef.c contains the implementation base class ParData for a new type of SICS object. It contains parameter definition, parameter handling, parameter listing, logging and storing. The parameter definiton function is the heart of any object based on pardef. This function is called by the system for different actions which can be performed on an object.

EASE

ease.c contains two classes: EaseBase inherits ParData. It includes the finite state machine, and the handling of a serial connection to the hardware. EaseDriv inherits EaseBase. It makes the object driveable.

fsm

fsm.c is the implementation of a simple processor. The tasks which can be executed are functions (FsmFunc) which contain a switch statement, where every case is a step of the task to execute. When combined with EASE, the individual steps normally end with a command written to the device. After any step, the FsmFunc returns the line number of the next step. The system calles the FsmFunc again, when the response is ready. FsmFuncs might be nested.

Drivers based on EASE

For a driver, one needs to define

For a list of predefined parameters and subcommands see EaseParametersAndCommands

For list of a available drivers based on EASE see EaseDrivers


EaseParametersAndCommands

Common Parameters and Subcommands for EASE Objects

(c): command
(r): read-only parameters
(w): writeable parameter. The value has to be added to the command.

Command Syntax               Description
Standard commands defined for all objects based on pardef
<obj> list               (c) make a list of most important parameters. listed
                             are all parameters defined with a call to ParTail
                             and not ParList, or with a call to ParList(NULL)  
                             
<obj> list all           (c) make a full list of all parameters  

<obj> list <group>       (c) make a list of only a group of parameters. listed
                             are all parameters defined with a call to
                             ParList("<group>")
                             
<obj> log <par>          (c) switch the logger on for parameter <par>. logging
                             is on by default, off when defined without an
                             explicit call to ParSwitch(NULL)
                             
<obj> log <par> <sugar>  (c) switch the logger on for parameter <par>, giving
                             a sugar name (see [SicsSugar])  
                             
<obj> unlog <par>        (c) switch the logger off for parameter <par>  

<obj> sugar              (c) return a list of sugar parameters  

<obj> save <par>         (c) switch on status file saving for parameter <par>
                             is on by default for changeable parameters, or
                             when explicitley defined with a call to ParSave   
                             
<obj> unsave <par>       (c) switch off status file saving for parameter <par>  

<obj> interest           (c) switch interest callback on. every change will
                             be notified to the calling client 
                             
<obj> uninterest         (c) switch interest callback off
Parameters defined in ParStdDef
<obj> verbose            (w) verbosity. 0 is quiet, 1 is standard
                             2 is verbose (logging all serial communication)
                             
<obj> driver             (r) driver name
                                
<obj> creationCmd        (r) command to create this object              
Parameter defined by EaseBasePar
<obj> restart            (c) reconnect serial connection 
Parameter defined by EaseSendPar
<obj> send <command>     (c) send a serial command. Warning: the response is
                             delayed and can therefore not be used in scripts.
Parameters defined by EaseDrivPar
<obj> upperLimit         (w) upper limit of target value 

<obj> lowerLimit         (w) lower limit of target value

<obj> tolerance          (w) tolerance

<obj> maxwait            (w) maximal time to wait for target value (sec)
                             or 0 for infinite wait
                             
<obj> settle             (w) time to wait after target value is within tolerance

<obj> targetValue        (r) target value
Parameter defined by EaseMsgPar
<obj> status             (r) connection status of the device (empty when normal)

SicsSugar

Sugar

A sugar variable is an alias to an object parameter. It is used in order to give a parameter a more descriptive name, mainly for the plot label. It is created for example with the following command:

  te log t2 Tsample
Give the variable te.t2 the name Tsample. This name is also used for the logger file.
  te sugar
gives a list of defined sugar variables connected to parameters of te.
SicsLogger

Logger - yet an other Variable Logging Utility

The Logger (logger.c)

The logger is a utility to write the history of object parameters. For all drivers based on pardef it is automatically switched on. The data is logged typically every 5 seconds to a file, but only changes are stored in order to save disk space. The file specification for the logfiles is:

<logger base path>/<variable name>/MM-DD.log

Files older than one year will be overwritten. The variable name is the object name for the basic value of the object or <object name>.<parameter name> for the parameters. Important parameter names might be configured to have a more descriptive name.

Syntax of the Log Files

First there is a header line, containing the date and some additional information:

isdst
0/1 when daylight saving time is in effect or not
period
the minimal interval between logged values
exact
0: plot points should be connected with a straight line, 1: plot curves should have only horizontal and vertical lines

For every logger entry, there is one line, containing the time, a tab as separation and a value, (which may be a text or number). There may also be lines starting with a hash symbol, which may contain the same information as in the header line, or just a comment.

#2005-10-30 00:00:00 isdst 1 period 5 exact 0
00:00:00        100.72
00:00:05        100.73
00:01:10        100.73
00:01:15        100.74
00:01:20        100.73

      ...                                   many lines omitted

02:59:55        100.56
#isdst 0                                    change of daylight saving time
02:00:00        100.58

      ...                                   many lines omitted

07:55:00        100.58                      the server was shut down after writing this line
#period 5 exact 0 isdst 0                   the server restarts at 8:30
07:55:05                                    the shutdown time and an empty value
08:30:00        99.95                       the first logged value after startup

The Log Reader (logreader.c)

There is also a utility to read the logged data through the SICS server. The command syntax is:

   graph <start time> <end time> np <number of points> <variable> <variable> ...
   graph <start time> <end time> text <variable> <variable> ...
where

<start time> <end time>
start and end time in seconds. Negative or small values (lower than one year) are relative to the actual time. Large values are treated as unix time values (seconds since 1970-01-01:00:00:00 UTC).
<number of points>
the maximal number of points to be read. If the the number of points is less than the interval duration divided by the logging period, the data is compressed.
<variable>
the variable name or object parameter name (<object>.<parameter>).

The second form with the keyword text does not compress, and is mainly used for text variables.

The returned list has the following syntax:

<compressed> is 0, if no compression appeared, 1 else
<overflow> should be 0, else an internal error occur (might be removed later)


SeaServer

SeaServer

The SeaServer is a sics server running in parallel to the Server for instrument control. The server program is just a copy of the SICServer. However, when testing new features, different versions might be used for instrument control (sics server process) and for sample environment (sea server process).

Directory Structure

All stuff related to sea are placed in $HOME/sea. All script files needed for the sea server process are identical on all instruments and are placed in the directory ~/sea/tcl. There is one exception, ~/sea/sea.tcl. This file contains the location of the files and the instrument name, and calls the instrument independent startup file ~/sea/tcl/seainit.tcl. This file calls all scripts in the directory ~/sea/tcl/startup/'.

The server log files are located in sea/log, and the database for the logger in sea/logger. The copy of the SICServer for sea is sea/SICServer, and there is a link to it (sea/SeaServer) which is started with the script sea/startwithpid.

Connection between Sea and SICS

The following lines should to be included into the instruments startup script:

  source $home/sea/tcl/remob.tcl
  connect_sea
The macro
connect_sea tries to make a connection to sea. If the connection is successful, remob objects are created on sics for all objects listed in the variable env_object_list on sea. Likewise the sea server tries to make a connection to sics on startup and initiates the update of configured objects.

Sea Configuration

To select the sample environment device, the command samenv (defined in sea/tcl/seacom.tcl) is used. It calles the configuration script for the given device (sea/tcl/<name>.config). The configuration scripts do not call makeobject directly, but use the makenv script, which keeps a list of created objects and takes the host:port information from a small database managed by cfgenv.

Syntax:

samenv <device name>         configure sea for the given SE device

samenv                       show the actual configuration

samenv none                  remove all objects related with the actual
                             SE device

cfgenv <driver> <host:port>  configure the serial connection of a controller

cfgenv                       list all configured controllers

makenv <object> <driver>     make an object, using the configuration defined
                             with cfgenv (this command can be used in
                             configuration scripts only)

EaseDrivers

Currently Implemented Drivers based on EASE


EaseIlm

ILM

The Oxford Instruments helium level meters ILM exists in different versions. At SINQ there are two types:

Create a level meter object:

  makeobject lev ilm <terminal server> <port>
The name might be choosen differently, lev is used by convention, and is also used by the scripts called with the samenv command.

Subcommands and Parameters

Command Syntax     Description

lev            (r) helium level
lev lev2       (r) liquid nitrogen level

               (r): read-only

Plus standard commands and parameters defined by EaseBasePar, EaseSendPar, EaseMsgPar


EaseIps

IPS

Oxford Instruments superconducting magnet power supply IPS

Create an IPS object:

  makeobject mf ips <terminal server> <port>
The name might be choosen differently, mf is used by convention, and is also used by the scripts called with the samenv command.

Subcommands and Parameters

Command Syntax     Description

mf             (r) magnetic field

mf persmode    (w) 0: do not work in persistent mode
                   1: go to persistent mode after a drive

mf perswitch   (r) state of persistent mode switch

mf maxlimit    (r) maximal limit for field

mf limit       (w) soft limit for field (when set the first time
                   after initialization, maxlimit is also set)

mf ramp        (w) ramp rate (the real ramp rate may be limited
                   by the sweep limits defined in the IPS)

mf current     (r) the current in the leads (converted to Tesla)

mf lastfield   (r) value the the field before goings to persistent mode

mf confirm     (c) confirm the persistent field in case the stored
                   value in the driver does not match the value
                   stored in the IPS

mf targetValue (r) target value

               (r): read-only
               (w): writeable parameter
               (c): command

Plus standard commands and parameters defined by EaseBasePar, EaseSendPar, EaseMsgPar


EaseItc

ITC

The Oxford Instruments temperature controller and lambda controller exists in 3 different types at SINQ:

Create an ITC object:

  makeobject te itc <terminal server> <port>   (for ITC4 or ITC503)
  makeobject te lc <terminal server> <port>    (for lambda controller)
The name might be choosen differently, te is used by convention, and is also used by the scripts called with the samenv command.

Subcommands and Parameters

Command Syntax       Description

te               (r) the sample temperature (pressure on lambda controller)

te sampleChan    (w) the channel used for sample (1..3)

te controlChan   (w) the channel for control

te dig1          (w) the number of digits after decimal point 
te dig2              (must be configured on an ITC-4, is automatic 
te dig3              on an ITC-503)

te t1            (r) temperature of channel 1
te t2            (r) temperature of channel 2
te t3            (r) temperature of channel 3

te htrMode       (r) heater mode (0: manual, 1: auto, 2:auto needle valve)

te htr           (r) heater output

te gasMode       (w) gas mode (0: manual, 1: auto)

te gas           (r) needle valve position

te setGas        (w) set needle valve position

te autoGasLimit  (w) when the controlled tempeature goes below this
                     value, gas is switched to manual mode, using the value
                     given by setGas. 1 K above this value, gas is
                     switched to auto mode

r: read-only, w: writeable parameter
Plus standard commands and parameters defined by EaseBasePar, EaseSendPar, EaseDrivePar, EaseMsgPar