Skip to content

genie_python Commands

Tom Willemsen edited this page Nov 18, 2024 · 14 revisions

Scripting > 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.

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

Running in simulation mode

Genie_python can be used in simulation mode. Simulation mode will allow you to run scripts but without changing items on your instrument. It does this by putting dummy commands in for some genie command, it also creates dummy blocks on the fly so that block values can be read and written to. N.B. This means that simulation can not be this will not validate your block names within the script. To run in simulation mode use the genie_python_simulate.bat found in C:\Instrument\Apps\Python3.

Common genie_python commands

Many genie_python commands share the same name with their Open GENIE equivalent so it will often be very straightforward to find the function you're looking for. Still, here is a list of the most commonly used genie_python commands. This is not a complete list. For full information, consult the genie_python reference manual.

Starting and stopping a run

Command Description Example
begin Starts a new run g.begin()
end Ends the current run g.end()
abort Aborts the current run 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 runcontrol settings for blocks g.cset("NEW_BLOCK",1)
get_pv Gets the value for the specified PV g.get_pv("IN:INSTNAME:IOC_01:STAT")
set_pv Sets the value for the specified PV g.set_pv("IN:INSTNAME:IOC_01:STAT",1)

Run control

Command Description Example
get_uamps Gets the current number of micro-amp hours g.get_uamps()
get_frames Gets the current number of good frames g.get_frames()
get_runstate Gets the current status of the instrument as a string g.get_runstate()
get_mevents Gets the total counts for all the detectors g.get_mevents()
get_totalcounts Gets the total counts for the current run 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(1)
waitfor_frames Waits for a number of total good frames to reach parameter value g.waitfor_frames(1000)
waitfor_uamps Waits for a specific total charge g.waitfor_uamps(9.9)
waitfor_runstate Waits for a particular instrument run state g.waitfor_runstate("paused")
waitfor_move Waits for all motion or specific motion to complete g.waitfor_move("NEW_BLOCK")

Toggling options

Various options can be toggled with the toggle command.

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 this toggled to True and there is an exception within genie_python it will stop your script from running unless you catch the exception yourself.

Clone this wiki locally