|
| 1 | +# Genie Python Commands |
| 2 | + |
| 3 | +## Running `genie_python` commands |
| 4 | + |
| 5 | +When running python from an interactive console such as from |
| 6 | +the GUI, or after running `C:\Instrument\Apps\Python3\genie_python.bat`, |
| 7 | +the `genie` module will be aliased to `g`. Genie commands can then |
| 8 | +be accessed by using the prefix `g.[COMMAND_NAME]`. For example: |
| 9 | + |
| 10 | +```python |
| 11 | +g.begin() |
| 12 | +g.cset("BLOCK_1", 1) |
| 13 | +g.abort() |
| 14 | +``` |
| 15 | + |
| 16 | +This is particularly useful from the GUI which will auto-complete |
| 17 | +commands and provide tool tips describing each function and its |
| 18 | +arguments. |
| 19 | + |
| 20 | +For user or instrument scripts, the standard way of importing `genie_python` is: |
| 21 | + |
| 22 | +```python |
| 23 | +from genie_python import genie as g |
| 24 | +``` |
| 25 | + |
| 26 | +Note that in many cases, arguments will be optional. For instance, |
| 27 | +{external+genie_python:py:obj}`g.begin <genie.begin>` can be used as `g.begin()`, despite additionally supporting optional |
| 28 | +arguments including `period`, `meas_id`, `meas_type`, `meas_subid`, |
| 29 | +`sample_id`, `delayed`, `quiet`, `paused`, and `verbose`. |
| 30 | + |
| 31 | +## Common `genie_python` commands |
| 32 | + |
| 33 | +Some commonly used `genie_python` commands are listed below. |
| 34 | + |
| 35 | +This is **not a complete list**; For full information, consult the {external+genie_python:doc}`genie_python reference manual <genie_python>`. |
| 36 | +Click on a command name below to view the detailed documentation for that command in the reference manual. |
| 37 | + |
| 38 | +### Starting and stopping a run |
| 39 | + |
| 40 | +| Command | Description | Example | |
| 41 | +|-------------------------------------------------------|------------------------------------------|--------------| |
| 42 | +| {external+genie_python:py:obj}`begin <genie.begin>` | Starts a new run | `g.begin()` | |
| 43 | +| {external+genie_python:py:obj}`end <genie.end>` | Ends the current run (saving data) | `g.end()` | |
| 44 | +| {external+genie_python:py:obj}`abort <genie.abort>` | Aborts the current run (discarding data) | `g.abort()` | |
| 45 | +| {external+genie_python:py:obj}`pause <genie.pause>` | Pauses the current run | `g.pause()` | |
| 46 | +| {external+genie_python:py:obj}`resume <genie.resume>` | Resumes the current run after it has been paused | `g.resume()` | |
| 47 | + |
| 48 | +### Updating blocks and PVs |
| 49 | + |
| 50 | +| Command | Description | Example | |
| 51 | +|-------------------------------------------------------|--------------------------------------------------------------------|----------------------------------------| |
| 52 | +| {external+genie_python:py:obj}`cget <genie.cget>` | Gets the useful values associated with a block | `g.cget("NEW_BLOCK")` | |
| 53 | +| {external+genie_python:py:obj}`cset <genie.cset>` | Sets the setpoint, and optionally runcontrol settings, for a block | `g.cset("NEW_BLOCK",1)` | |
| 54 | +| {external+genie_python:py:obj}`get_pv <genie.get_pv>` | Gets the value of the specified PV | `g.get_pv("IN:INSTNAME:IOC_01:STAT")` | |
| 55 | +| {external+genie_python:py:obj}`set_pv <genie.set_pv>` | Sets the value of the specified PV | `g.set_pv("IN:INSTNAME:IOC_01:STAT",1)` | |
| 56 | + |
| 57 | +### Run control |
| 58 | + |
| 59 | +| Command | Description | Example | |
| 60 | +|---------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------| |
| 61 | +| {external+genie_python:py:obj}`get_uamps <genie.get_uamps>` | Gets the number of micro-amp hours of beam collected in the current run | `g.get_uamps()` | |
| 62 | +| {external+genie_python:py:obj}`get_frames <genie.get_frames>` | Gets the number of {abbr}`good frames (Pulses which were counted, not counting any pulses that were ignored due to hardware vetoes or software run-control settings)` of beam collected in the current run | `g.get_frames()` || {external+genie_python:py:obj}`get_runstate <genie.get_runstate>` | Gets the current status of the instrument as a string | `g.get_runstate()` | |
| 63 | +| {external+genie_python:py:obj}`get_mevents <genie.get_mevents>` | Gets the total counts for all the detectors, in millions of events. | `g.get_mevents()` | |
| 64 | +| {external+genie_python:py:obj}`get_totalcounts <genie.get_totalcounts>` | Gets the total counts for all the detectors. | `g.get_totalcounts()` | |
| 65 | +| {external+genie_python:py:obj}`waitfor <genie.waitfor>` | Waits until certain conditions are met. | `g.waitfor("NEW_BLOCK",value=1)` | |
| 66 | +| {external+genie_python:py:obj}`waitfor_block <genie.waitfor_block>` | Waits until block reaches specific value. | `g.waitfor_block("NEW_BLOCK",1)` | |
| 67 | +| {external+genie_python:py:obj}`waitfor_time <genie.waitfor_time>` | Waits for a specified amount of time. | `g.waitfor_time(seconds=1)` | |
| 68 | +| {external+genie_python:py:obj}`waitfor_frames <genie.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)` | |
| 69 | +| {external+genie_python:py:obj}`waitfor_uamps <genie.waitfor_uamps>` | Waits for the number of total uAmp-hours collected in the current run to reach the specified total value. | `g.waitfor_uamps(5.0)` | |
| 70 | +| {external+genie_python:py:obj}`waitfor_runstate <genie.waitfor_runstate>` | Waits for a particular instrument run state. | `g.waitfor_runstate("PAUSED")` | |
| 71 | +| {external+genie_python:py:obj}`waitfor_move <genie.waitfor_move>` | Waits for all motion, or specified motion axes, to complete. | `g.waitfor_move()` | |
| 72 | + |
| 73 | +## Toggling options |
| 74 | + |
| 75 | +Various options can be toggled using the {external+genie_python:py:obj}`genie_toggle_settings` module. |
| 76 | + |
| 77 | +For example, toggling the verbosity of all calls to a command using {external+genie_python:py:obj}`toggle.cset_verbose(True) <genie_toggle_settings.cset_verbose>`. This can be convenient, as there will be no need to explicitly set `verbose=True` for each `cset` call. |
| 78 | + |
| 79 | +There are also advanced options such as {external+genie_python:py:obj}`toggle.exceptions_raised(True) <genie_toggle_settings.exceptions_raised>`, which will allow exceptions to propagate instead of genie handling them, in case you want to handle exceptions yourself. |
| 80 | + |
| 81 | +```{warning} |
| 82 | +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. |
| 83 | +``` |
| 84 | + |
| 85 | +## Running in simulation mode |
| 86 | + |
| 87 | +Genie_python supports a basic simulation mode; see {doc}`Simulating-Scripts` for how to use this. |
0 commit comments