Genie Python Commands

Running genie_python commands

When running python from an interactive console such as from the GUI, or after running C:\Instrument\Apps\Python3\genie_python.bat, the genie module will be aliased to g. Genie commands can then be accessed by using the prefix g.[COMMAND_NAME]. For example:

g.begin()
g.cset("BLOCK_1", 1)
g.abort()

This is particularly useful from the GUI which will auto-complete commands and provide tool tips describing each function and its arguments.

For user or instrument scripts, the standard way of importing genie_python is:

from genie_python import genie as g

Note that in many cases, arguments will be optional. For instance, g.begin can be used as g.begin(), despite additionally supporting optional arguments including period, meas_id, meas_type, meas_subid, sample_id, delayed, quiet, paused, and verbose.

Common genie_python commands

Some commonly used genie_python commands are listed below.

This is not a complete list; For full information, consult the genie_python reference manual. Click on a command name below to view the detailed documentation for that command in the reference manual.

Starting and stopping a run

Command

Description

Example

begin

Starts a new run

g.begin()

end

Ends the current run (saving data)

g.end()

abort

Aborts the current run (discarding data)

g.abort()

pause

Pauses the current run

g.pause()

resume

Resumes the current run after it has been paused

g.resume()

Updating blocks and PVs

Command

Description

Example

cget

Gets the useful values associated with a block

g.cget("NEW_BLOCK")

cset

Sets the setpoint, and optionally runcontrol settings, for a block

g.cset("NEW_BLOCK",1)

get_pv

Gets the value of the specified PV

g.get_pv("IN:INSTNAME:IOC_01:STAT")

set_pv

Sets the value of the specified PV

g.set_pv("IN:INSTNAME:IOC_01:STAT",1)

Run control

Command

Description

Example

get_uamps

Gets the number of micro-amp hours of beam collected in the current run

g.get_uamps()

get_frames

Gets the number of good frames of beam collected in the current run

g.get_frames()

get_mevents

Gets the total counts for all the detectors, in millions of events.

g.get_mevents()

get_totalcounts

Gets the total counts for all the detectors.

g.get_totalcounts()

waitfor

Waits until certain conditions are met.

g.waitfor("NEW_BLOCK",value=1)

waitfor_block

Waits until block reaches specific value.

g.waitfor_block("NEW_BLOCK",1)

waitfor_time

Waits for a specified amount of time.

g.waitfor_time(seconds=1)

waitfor_frames

Waits for the number of total good frames collected in the current run to reach the specified total value.

g.waitfor_frames(5000)

waitfor_uamps

Waits for the number of total micro-amp hours collected in the current run to reach the specified total value.

g.waitfor_uamps(5.0)

waitfor_runstate

Waits for a particular instrument run state.

g.waitfor_runstate("PAUSED")

waitfor_move

Waits for all motion, or specified motion axes, to complete.

g.waitfor_move()

Toggling options

Various options can be toggled using the genie_toggle_settings module.

For example, toggling the verbosity of all calls to a command using toggle.cset_verbose(True). This can be convenient, as there will be no need to explicitly set verbose=True for each cset call.

There are also advanced options such as toggle.exceptions_raised(True), which will allow exceptions to propagate instead of genie handling them, in case you want to handle exceptions yourself.

Warning

If you have exceptions_raised toggled to True and there is an exception within genie_python, it will stop your script from running unless you catch the exception yourself.

Running in simulation mode

Genie_python supports a basic simulation mode; see Simulating Scripts for how to use this.