controlscript name [-controllertype type] [-initscript path] [-updatescript path] [-monitorscript path] [-monitorproc proc]
The controlscript package provides a snit::type called controlscript that can be used to source Tcl scripts as a result of slow control requests. The idea is that the user can create an instance of the snit::type and then register it as a Module with type=tcl. The behavior can be useful you have special Tcl code that might need to execute on the server side during a run. It is also a means for the using some of the low-level Tcl drivers provided by the CCUSBReadout and VMUSBReadout.
The only required option is -controllertype
, whose
argument specifies whether the driver will be handling VMUSB or CCUSB
requests. The rest of the options are truly optional.
The -controllertype parameter is the only required option. Its argument,
type
, must be either "vmusb" or "ccusb". If neither
is provided, an error will occur.
The -initscript
option specifies the path to a Tcl
script that will be evaluated in the global scope. It is executed at
the startup of the slow controls server (i.e. at program startup) and
any time the user calls the init from within the
Readout program it is associated with. If this option is not provided,
it will be ignored.
While the script executes, the Globals::aController variable will refer to the VMUSB or CCUSB object managed by the Readout program. The object is either a cvmusb::CVMUSBusb or cccusb::CCCUSBusb object and has methods provided by the cvmusb or cccusb package, respectively.
The -updatescript
option specifies the path to a Tcl
script that will be evaluated in the global scope. It is executed
whenever an update request is received for the associated
slow-controls module. If this option is not provided, it will be
ignored.
While the script executes, the Globals::aController variable will refer to the VMUSB or CCUSB object managed by the Readout program. The object is either a cvmusb::CVMUSBusb or cccusb::CCCUSBusb object and has methods provided by the cvmusb or cccusb package, respectively.
The -monitorscript
option specifies the path to a
Tcl script that will be evaluated in the global scope. It is only
meaningful in the context of VMUSBReadout. In this script, you should
add stack commands to the "Globals::aReadoutList" object, which is a
CVMUSBReadout object. The commands that are added to the stack will
be executed periodically during the run and the resulting data will
be processed by the proc identified in the
-monitorproc
option. This will be executed on at
program startup. If this option is not provided, it will be ignored.
While the script executes, the Globals::aReadoutList variable will refer to the VMUSB or CCUSB object managed by the Readout program. It can be manipulated using the methods provided in the cvmusbreadoutlist or cccusbreadoutlist package.
The -monitorproc
option specifies a proc that will
be used to parse the data generated by the commands added in the script
passed as an argument to the -monitorscript
option. It
should parse the byte data and then return the number of bytes that it
processed.
Example 1. An example usage in VMUSBReadout
Consider that you are running VMUSBReadout and need to execute some code contained in a file myScript.tcl at the startup of the program. After the initial program startup, you do not require it to be executed again unless you choose to do so via an init command. In this case, you would want to use the controlscript. This should go in your ctlscript and it might look something like:
lappend auto_path [file join $::env(DAQROOT) TclLibs]lappend auto_path $::env(DAQLIB) package require cvmusb package require cvmusbreadoutlist package require controlscript
controlscript _myScript -controllertype vmusb
_myScript configure -initscript [file join /path to myScript.tcl] Module create tcl myScript
Module config myScript -ensemble _myScript
Your myScript.tcl file might look something like this if it were to write 1 to a register in some module (address=0xa2020100) using A32 single data access (0x09) and then verify that the write succeeded.
set ctlr $::Globals::aController # write, read, and then check the value $ctlr vmeWrite16 0xa2020100 0x09 1 set newValue [$ctlr vmeRead16 0xa2020100 0x09] if {$newValue != 1} { puts "ERROR! Write did not successfully set the value in the module" }