Closed prjemian closed 4 years ago
Consider a bo record called acquire
, want a string (ISO 8601 date/time) that records when it was last started acquiring (transitioned from 0 to 1). Only when it started. We cannot modify the bo record to produce this (which means we can't change the record's FLNK
field to our needs). This support is an add-on that can't modify the bo record.
Here is a suitable bo record definition:
record(bo, "acquire") {
field(ZNAM, "idle")
field(ONAM, "Acquiring")
}
If we just record types from EPICS base, then a calcout record can watch acquire
and mark when acquire starts. According to the calcout record documentation, the [acquire
PV] can be a database link (in the same IOC), channel access link (in a different IOC), or a constant.
This database will watch the acquire
PV and create the timestamp string described above.
record(calcout, "_calc") {
field(DESC, "watch acquire start")
field(TSEL, "acquire.TIME")
field(INPA, "acquire")
field(CALC, "A>0.5")
field(SCAN, ".1 second")
field(OUT, "_buffer PP")
field(OOPT, "Transition To Non-zero")
}
record(ao, "_buffer") {
field(TSEL, "_calc.TIME")
field(FLNK, "started")
}
record(stringin, "started") {
field(DESC, "when acquire started")
field(DTYP, "Soft Timestamp")
field(INP, "@%Y-%m-%d %H:%M:%S.%03f")
field(SCAN, "Passive")
field(TSEL, "_buffer.TIME")
}
As a convention, internal PV use a _
prefix.
Let's generalize that for any input PV which is a number (bool, int, or float) and be able to specify appropriate prefixes. Also allow for more than one instance of this database.
Here's an example:
$ sleep 2
$ caput acquire 1
Old : acquire idle
New : acquire Acquiring
$ sleep 0.1; caget started
started 2020-09-11 16:16:44.706
$ sleep 2
$ caput acquire 0
Old : acquire Acquiring
New : acquire idle
$ sleep 0.1; caget started
started 2020-09-11 16:16:44.706
$ sleep 2
$ caput acquire 1
Old : acquire idle
New : acquire Acquiring
$ sleep 0.1; caget started
started 2020-09-11 16:18:23.824
$ sleep 2
$ caput acquire 0
Old : acquire Acquiring
New : acquire idle
$ sleep 0.1; caget started
started 2020-09-11 16:18:23.824
Here's the timestamp.db
database at work:
Run a softIoc
watching blackfly_optical
. The test database uses prefix tst:ts:
.
bash-4.2$ softIoc -m A=9idFLY2:cam1:Acquire,CALC="A>0.5",P=tst:,D=ts:,OOPT="Transition To Non-zero" -d timestamp.db
Starting iocInit
############################################################################
## EPICS R3.14.12.3-ext1 $Date: 2012/12/20 19:45:40 $
## EPICS Base built Jul 10 2013
############################################################################
iocRun: All initialization complete
In [27]: RE(record_sample_image_on_demand("Jemian", "sample_name", md))
D Fri-17:17:54 - make_filename: /mnt/share1/USAXS_data/2020-09/09_11_Pete/09_11_Pete_Jemian/sample_name_0042.jpg
D Fri-17:17:54 - write_path: /mnt/share1/USAXS_data/2020-09/09_11_Pete/09_11_Pete_Jemian/
Out[27]: ()
In [28]: !caget tst:ts:started
tst:ts:started 2020-09-11 17:17:54.879
Make a database (re-useable) to get ISO8601-formatted timestamp PVs for the start time of the various detectors.
Originally posted by @prjemian in https://github.com/APS-USAXS/ipython-usaxs/issues/351#issuecomment-652043593