A simple package that gives wrapped caput and writeMatrix functions for writing EPICS channels which save previous values and a restoreEpics function can be used later to restore all values in case of error, interrupt, or as a final restore.
Project description
restoreEpics
A simple package that gives wrapped caput and writeMatrix functions for writing EPICS channels which save previous values and a restoreEpics function can be used later to restore all values in case of error, interrupt, or as a final restore.
Usage
Restoring channels
from restoreEpics import restoreEpics, caput, caget
try:
# do some work that uses caget or caput as usual
except BaseException:
# Handle error cases
finally:
restoreEpics() # Will restore all changes to previous values
Writing to matrices with form basename_ii_jj_suffix
from restoreEpics import restoreEpics, writeMatrix
try:
writeMatrix(basename, mat, suffix=suffix, tramp=10)
except BaseException:
# Handle error cases
finally:
restoreEpics() # Will restore all changes to previous values
Writing multiple channels with option of ramping together
from restoreEpics import restoreEpics, writeChannels
try:
chanInfo = {'channels': {'C1:FIRST_CH': {'value': 5},
'C1:SECON_CH': {'value': 10}},
'tramp': 4}
writeChannels(chanInfo)
except BaseException:
# Handle error cases
finally:
restoreEpics() # Will restore all changes to previous values
Make your own restoring methods
from restoreEpics import restoreEpics, backUpVals, restoreMethods
from awg import Sine
def exciteSine(ch, freq, ampl, duration=10, ramptime=1, bak=backUpVals):
exc = Sine(ch, freq, ampl, duration=duration)
exc.start(ramptime=ramptime)
if ch in bak:
bak[ch] = {'type': 'excSine', # Store the exc object wth a type defined.
'name': ch, # Values
'exc': exc, # Values
'sno': len(bak)} # Assign a serial number like this
def restoreExc(bakVal):
bakVal['exc'].stop() # Restoring method for excitation.
# Add the restoring method to restoreMethods dictionary with type defined above as key
restoreMethods['excSine'] = restoreExc
try:
exciteSine('blah', 0.5, 10)
except BaseException:
# Handle error cases
finally:
restoreEpics() # Will restore all changes to previous values
Command line tools
The readMatrix and writeMatrix functions are available as command line tools on installation through pip. Usage:
$ readMatrix -h
usage: readMatrix [-h] [--firstRow FIRSTROW] [--firstCol FIRSTCOL] [-s SUFFIX]
basename inMatFile rows cols
This reads matrix coefficients from EPICS channels to a text file to. Note
that all indices start from 1 by convention for EPICS channels.
positional arguments:
basename Matrix EPICS base name
inMatFile Input Matrix file name
rows Number of rows to read. Default None(all)
cols Number of columns to read. Default None(all)
optional arguments:
-h, --help show this help message and exit
--firstRow FIRSTROW First index of output. Default 1
--firstCol FIRSTCOL First index of input. Default 1
-s SUFFIX, --suffix SUFFIX
Any suffix after the matrix indices in channel names.
Default is None.
$ writeMatrix -h
usage: writeMatrix [-h] [-r ROWS] [-c COLS] [--firstRow FIRSTROW]
[--firstCol FIRSTCOL] [--fileRowInd FILEROWIND]
[--fileColInd FILECOLIND] [-t TRAMP] [-s SUFFIX]
inMatFile basename
This writes matrix coefficients from a text file to EPICS channels. Note that
all indices start from 1 by convention for EPICS channels.
positional arguments:
inMatFile Input Matrix file name
basename Matrix EPICS base name
optional arguments:
-h, --help show this help message and exit
-r ROWS, --rows ROWS Number of rows to write. Default None(all)
-c COLS, --cols COLS Number of columns to write. Default None(all)
--firstRow FIRSTROW First index of output. Default 1
--firstCol FIRSTCOL First index of input. Default 1
--fileRowInd FILEROWIND
First row index in file. Default 1
--fileColInd FILECOLIND
First col index in file. Default 1
-t TRAMP, --tramp TRAMP
Ramping time when chaning values. Default 3
-s SUFFIX, --suffix SUFFIX
Any suffix after the matrix indices in channel names.
Default is None.
$ caputt -h
usage: caputt [-h] [-t TRAMP] [-w] [-o TIMEOUT] [chanInfo [chanInfo ...]]
This script is a version of nominal caput command with added functionality of
setting a tramp and reading a set of channels from yaml files if they need to
be set all together or ramped all together to new values.
positional arguments:
chanInfo Channel name and value pairs sepaated by space or name
of the yaml file containing them.
optional arguments:
-h, --help show this help message and exit
-t TRAMP, --tramp TRAMP
Global ramping time in seconds.
-w, --wait Whether to wait until the processing has completed.
Global and would override any other value from
paramter file.
-o TIMEOUT, --timeout TIMEOUT
how long to wait (in seconds) for put to complete
before giving up. Global and would override any other
value from paramter file.
Example use:
caputt C1:FIRST_CH 8.0
caputt C1:FIRST_CH 8.0 -t 5
caputt C1:FIRST_CH 8.0 C1:SECOND_CH 5.6 -t 6 -w -o 60
caputt channelsFile.yml
Example of channelsFile.yml
channels:
C1:FIRST_CH:
value: 10
C1:SECOND_CH:
value: 20
C1:THIRD_CH:
value: 30
tramp: 5 # Individual tramp, will get overridden by global tramp if present.
C1:FOURTH_CH:
value: 40
timeout: 60 # Time after which the process will call it failed attempt.
wait: True # Will wait for the process to end
tramp: 5 # GLobal tramp, overrides individual tramp
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file restoreEpics-0.3.3.4.tar.gz.
File metadata
- Download URL: restoreEpics-0.3.3.4.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07c080e5a58a39396f7023f29ff4c4cf417499a1adc35f18426ed2ca15fe2acc
|
|
| MD5 |
c156e26587da4b8b4c124511aeede557
|
|
| BLAKE2b-256 |
656767c6310f8735b79f81fe6211028b52f86df8adc9a44beaa6ad76bbdc265f
|
File details
Details for the file restoreEpics-0.3.3.4-py3-none-any.whl.
File metadata
- Download URL: restoreEpics-0.3.3.4-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cad9294d04b4f0d022631b952f30b873ff668533e98d2c34c0b79ff57c576f19
|
|
| MD5 |
26bcaae137c809459570eccb1a1e01a0
|
|
| BLAKE2b-256 |
9f13300cf4aaedf4f14e24f0da84e436aa95979ac513aeeffc2dffe427813d56
|