8 Commits
0.0.1 ... 0.0.5

12 changed files with 255 additions and 126 deletions

View File

@ -7,17 +7,17 @@ EPICS_VERSIONS=7.0.7
ARCH_FILTER=RHEL%
# additional module dependencies
REQUIRED+=stream
REQUIRED+=asyn
REQUIRED+=calc
# Release version
LIBVERSION=ed-dev
REQUIRED+=stream
# DB files to include in the release
TEMPLATES += db/counterbox.db
TEMPLATES += db/counterbox.proto
TEMPLATES += db/counterbox_common.db
TEMPLATES += db/counterbox_4ch.db
TEMPLATES += db/counterbox_8ch.db
TEMPLATES += db/counterbox_v2.db
TEMPLATES += db/counterbox_v2_test.db
TEMPLATES += db/counterbox_common.db
TEMPLATES += db/counterbox.proto
# DBD files to include in the release
DBDS += src/counterbox.dbd
@ -25,7 +25,8 @@ DBDS += src/counterbox.dbd
# Source files to build
SOURCES += src/counterbox.cpp
SCRIPTS += scripts/counterbox.cmd
SCRIPTS += scripts/counterbox_4ch.cmd
SCRIPTS += scripts/counterbox_8ch.cmd
SCRIPTS += scripts/counterbox_v2.cmd
CXXFLAGS += -std=c++17

70
README.md Normal file
View File

@ -0,0 +1,70 @@
Counterbox Epics Module
-----------------------
A Stream and Asyn based driver for Counterboxes as SINQ.
This supports the older 4 and 8 channel EL737 models and the new 10CH 2nd
generation systems.
## How to Use
Unless a custom database is needed, a device can be configure simply by setting
the required environment variables when calling the correct counterbox script.
Required Variables
| Environment Variable | Purpose |
|----------------------|-----------------------------------------|
| PREFIX | Prefix of all device specific PVs |
| NAME | First field in all PVs after Prefix |
| ASYN_PORT | Unique name for referencing Asyn device |
| CNTBOX_HOST | Network IP and Port of device |
All PVs take the form
```
$(PREFIX):$(NAME):*
```
Available device startup scripts
* scripts/counterbox_4ch.cmd
* scripts/counterbox_8ch.cmd
* scripts/counterbox_v2.cmd
A device can be configured using one of the startup scripts as follows
```
epicsEnvSet("PREFIX", "SQ:INSTRUMENT") # can also be set in runScript call
runScript "$(counterbox_DIR)counterbox_v2.cmd" "NAME=COUNTERBOX, ASYN_PORT=CBOXV2, CNTBOX_HOST=TestInst-DAQ1:2000"
```
## PVs of Interest
| PV | Description |
|---------------------------------------|----------------------------------------------------------------------|
| \$(PREFIX):\$(NAME):MsgTxt | Contains unexpected response to executed command |
| \$(PREFIX):\$(NAME):STATUS | 0: Idle, 1: Counting, 2: Low rate, 3: Paused, 4: Error |
| \$(PREFIX):\$(NAME):MONITOR-CHANNEL | Channel that PRESET-COUNT monitors (has RBV, only v2 can be changed) |
| \$(PREFIX):\$(NAME):PRESET-COUNT | Run count until specified pv value reached |
| \$(PREFIX):\$(NAME):PRESET-TIME | Run count until specified pv value in seconds reached |
| \$(PREFIX):\$(NAME):THRESHOLD | Minimum rate for counting to preceed. (has RBV) |
| \$(PREFIX):\$(NAME):THRESHOLD-MONITOR | Channel monitored for minimum rate (has RBV) |
| \$(PREFIX):\$(NAME):ELAPSED-TIME | Time Counterbox has been measuring for |
| \$(PREFIX):\$(NAME):M_ | Current count on channel. (1-10 depending on box) |
| \$(PREFIX):\$(NAME):CHANNELS | Number of available channels (4, 8 or 10) |
## Testing
The 2nd generation systems have two test channels that can be used to output
signals at a variable rate. These can be used to ensure the other channels are
working and to check the IOC - Nicos integration. These can be loaded at
runtime via the following
```
epicsEnvSet("LOAD_TEST_PVS","")
runScript "$(counterbox_DIR)counterbox_v2.cmd" "NAME=COUNTERBOX, ASYN_PORT=CBOXV2, CNTBOX_HOST=TestInst-DAQ1:2000"
```
See the file [counterbox\_v2\_test.db](./db/counterbox_v2_test.db)

View File

@ -95,6 +95,12 @@ readMinRate{
################################################################################
# Read Values From Monitors
readAll4 {
out "RA";
in "%(\$1ELAPSED-TIME)f %(\$1M1)d %(\$1M2)d %(\$1M3)d %(\$1M4)d";
@mismatch{in "%(\$1MsgTxt)s";}
}
readAll8 {
out "RA";
in "%(\$1ELAPSED-TIME)f %(\$1M1)d %(\$1M2)d %(\$1M3)d %(\$1M4)d %(\$1M5)d %(\$1M6)d %(\$1M7)d %(\$1M8)d";

View File

@ -1,4 +1,4 @@
# EL737 EPICS Database for streamdevice support
# Counterbox EPICS Database
# Macros
# P - Prefix
# NAME - just a name, e.g. EL737
@ -22,6 +22,13 @@ record(longin, "$(P):$(NAME):MONITOR-CHANNEL_RBV")
field(DISP, 1)
}
record(longin, "$(P):$(NAME):CHANNELS")
{
field(DESC, "Total Supported Channels")
field(VAL, 4)
field(DISP, 1)
}
################################################################################
# Count Commands
@ -30,7 +37,7 @@ record(longout,"$(P):$(NAME):THRESHOLD-MONITOR")
field(DESC, "Channel monitored for minimum rate")
field(VAL, "1") # Monitor
field(DRVL, "1") # Smallest Threshold Channel
field(DRVL, "8") # Largest Threshold Channel
field(DRVL, "4") # Largest Threshold Channel
}
################################################################################
@ -39,8 +46,7 @@ record(longout,"$(P):$(NAME):THRESHOLD-MONITOR")
record(ai, "$(P):$(NAME):READALL")
{
field(DESC, "Reads monitors and elapsed time")
field(INP, "@$(PROTO) readAll8($(P):$(NAME):) $(ASYN_PORT)")
field(SCAN, ".2 second")
field(INP, "@$(PROTO) readAll4($(P):$(NAME):) $(ASYN_PORT)")
field(DTYP, "stream")
field(FLNK, "$(P):$(NAME):UNSET-COUNTING")
field(FLNK, "$(P):$(NAME):MAP-STATUS")
}

72
db/counterbox_8ch.db Normal file
View File

@ -0,0 +1,72 @@
# EL737 EPICS Database for streamdevice support
# Macros
# P - Prefix
# NAME - just a name, e.g. EL737
# PROTO - Stream device protocol file
# ASYN_PORT - Low level Asyn IP Port to EL737
################################################################################
# Status Variables
record(longin, "$(P):$(NAME):MONITOR-CHANNEL")
{
field(DESC, "PRESET-COUNT Monitors this channel")
field(VAL, 1)
field(DISP, 1)
}
record(longin, "$(P):$(NAME):MONITOR-CHANNEL_RBV")
{
field(DESC, "PRESET-COUNT Monitors this channel")
field(VAL, 1)
field(DISP, 1)
}
record(longin, "$(P):$(NAME):CHANNELS")
{
field(DESC, "Total Supported Channels")
field(VAL, 8)
field(DISP, 1)
}
################################################################################
# Count Commands
record(longout,"$(P):$(NAME):THRESHOLD-MONITOR")
{
field(DESC, "Channel monitored for minimum rate")
field(VAL, "1") # Monitor
field(DRVL, "1") # Smallest Threshold Channel
field(DRVL, "8") # Largest Threshold Channel
}
################################################################################
# Read all monitors values
record(ai, "$(P):$(NAME):READALL")
{
field(DESC, "Reads monitors and elapsed time")
field(INP, "@$(PROTO) readAll8($(P):$(NAME):) $(ASYN_PORT)")
field(DTYP, "stream")
field(FLNK, "$(P):$(NAME):MAP-STATUS")
}
record(longin, "$(P):$(NAME):M5")
{
field(DESC, "Counterbox CH5")
}
record(longin, "$(P):$(NAME):M6")
{
field(DESC, "Counterbox CH6")
}
record(longin, "$(P):$(NAME):M7")
{
field(DESC, "Counterbox CH7")
}
record(longin, "$(P):$(NAME):M8")
{
field(DESC, "Counterbox CH8")
}

View File

@ -23,7 +23,7 @@ record(fanout, "$(P):$(NAME):INIT-BOX")
field(DESC, "Rewrite PVs to Box")
field(SELM, "All")
field(LNK0, "$(P):$(NAME):MONITOR-CHANNEL_RBV PP")
field(LNK1, "$(P):$(NAME):READALL PP")
field(LNK1, "$(P):$(NAME):RAW-STATUS PP")
field(LNK2, "$(P):$(NAME):THRESHOLD_RBV PP")
}
@ -63,45 +63,17 @@ record(seq, "$(P):$(NAME):REINIT-CONF")
field(SELL, "$(P):$(NAME):INVALID-CONFIG.VAL")
}
# The COUNTING PV stays True until Counterbox has switched back to idle mode
# and the monitor counts have been read. Therefore, we know that the monitor
# values have been updated to represent their final values, when this switches
# back to False.
#
# This is accomplished via the explicit SET-COUNTING and UNSET-COUNTING seq
# records, that are triggered by a switch to the counting status
# (RAW-STATUS == 1 || 2) and a read of the monitors respectively.
record(bi, "$(P):$(NAME):COUNTING")
{
field(DESC, "Counterbox is Counting")
field(VAL, 0)
}
record(seq, "$(P):$(NAME):SET-COUNTING")
{
field(LNK1, "$(P):$(NAME):COUNTING PP")
field(DO1, 1)
field(SELM, "Specified")
field(SELL, "$(P):$(NAME):MAP-STATUS.VAL")
field(FLNK, "$(P):$(NAME):STATUS")
}
record(seq, "$(P):$(NAME):UNSET-COUNTING")
{
field(LNK0, "$(P):$(NAME):COUNTING PP")
field(DO0, 0)
field(SELM, "Specified")
field(SELL, "$(P):$(NAME):RAW-STATUS.VAL")
field(FLNK, "$(P):$(NAME):MAP-STATUS")
}
# Important! The "$(P):$(NAME):READALL" isn't configure with a SCAN. Instead,
# it must always be triggered after the value of $(P):$(NAME):RAW-STATUS is
# updated, so that it can't be the case that the status changes back from
# counting to idle, without having updated the time and count values.
record(longin, "$(P):$(NAME):RAW-STATUS")
{
field(DESC, "Raw returned status value")
field(DTYP, "stream")
field(SCAN, ".2 second")
field(SCAN, ".1 second")
field(INP, "@$(PROTO) readStatus($(P):$(NAME):) $(ASYN_PORT)")
field(FLNK, "$(P):$(NAME):MAP-STATUS")
field(FLNK, "$(P):$(NAME):READALL")
}
record(calc, "$(P):$(NAME):MAP-STATUS")
@ -109,9 +81,8 @@ record(calc, "$(P):$(NAME):MAP-STATUS")
field(DESC, "Maps Raw Status to State")
field(INPA, "$(P):$(NAME):RAW-STATUS NPP")
field(INPB, "$(P):$(NAME):INVALID-CONFIG NPP")
field(INPC, "$(P):$(NAME):COUNTING NPP")
field(CALC, "B=1?4:(C=1&&A=0)||A=1||A=2?1:A=0?0:A=5||A=6?2:A=9||A=13||A=10||A=14?3:4")
field(FLNK, "$(P):$(NAME):SET-COUNTING")
field(CALC, "B=1?4:A=0?0:(A=1||A=2)?1:(A=5||A=6)?2:(A=9||A=13||A=10||A=14)?3:4")
field(FLNK, "$(P):$(NAME):STATUS")
}
record(mbbi, "$(P):$(NAME):STATUS")
@ -229,26 +200,6 @@ record(longin, "$(P):$(NAME):M4")
field(DESC, "Counterbox CH4")
}
record(longin, "$(P):$(NAME):M5")
{
field(DESC, "Counterbox CH5")
}
record(longin, "$(P):$(NAME):M6")
{
field(DESC, "Counterbox CH6")
}
record(longin, "$(P):$(NAME):M7")
{
field(DESC, "Counterbox CH7")
}
record(longin, "$(P):$(NAME):M8")
{
field(DESC, "Counterbox CH8")
}
# Not yet sure whether we want to support this
# record(longin, "$(P):$(NAME):R1")
# {

View File

@ -24,6 +24,13 @@ record(longin, "$(P):$(NAME):MONITOR-CHANNEL_RBV")
field(SCAN, "5 second")
}
record(longin, "$(P):$(NAME):CHANNELS")
{
field(DESC, "Total Supported Channels")
field(VAL, 10)
field(DISP, 1)
}
################################################################################
# Count Commands
@ -42,9 +49,28 @@ record(ai, "$(P):$(NAME):READALL")
{
field(DESC, "Reads monitors and elapsed time")
field(INP, "@$(PROTO) readAll10($(P):$(NAME):) $(ASYN_PORT)")
field(SCAN, ".2 second")
field(DTYP, "stream")
field(FLNK, "$(P):$(NAME):UNSET-COUNTING")
field(FLNK, "$(P):$(NAME):MAP-STATUS")
}
record(longin, "$(P):$(NAME):M5")
{
field(DESC, "Counterbox CH5")
}
record(longin, "$(P):$(NAME):M6")
{
field(DESC, "Counterbox CH6")
}
record(longin, "$(P):$(NAME):M7")
{
field(DESC, "Counterbox CH7")
}
record(longin, "$(P):$(NAME):M8")
{
field(DESC, "Counterbox CH8")
}
record(longin, "$(P):$(NAME):M9")
@ -56,33 +82,3 @@ record(longin, "$(P):$(NAME):M10")
{
field(DESC, "Counterbox CH10")
}
################################################################################
# Testing Commands
# These won't match the values on the machine after a full restart But I chose
# not to force their intialisation as they are only important for testing
record(bo, "$(P):$(NAME):TESTGEN")
{
field(DESC, "Turn on/off Testgen Signal")
field(DTYP, "stream")
field(OUT, "@$(PROTO) switchTestgenOnOff($(P):$(NAME):) $(ASYN_PORT)")
field(VAL, 0)
}
record(longout, "$(P):$(NAME):TESTGEN-LOWRATE")
{
field(DESC, "Set Minimum Testgen Rate")
field(DTYP, "stream")
field(OUT, "@$(PROTO) setTestSignal($(P):$(NAME):) $(ASYN_PORT)")
field(VAL, 1000)
}
record(longout, "$(P):$(NAME):TESTGEN-HIGHRATE")
{
field(DESC, "Set Maximum Testgen Rate")
field(DTYP, "stream")
field(OUT, "@$(PROTO) setTestSignal($(P):$(NAME):) $(ASYN_PORT)")
field(VAL, 1000)
}

31
db/counterbox_v2_test.db Normal file
View File

@ -0,0 +1,31 @@
################################################################################
# Testing Commands
# These won't match the values on the machine after a full restart But I chose
# not to force their intialisation as they are only important for testing
record(bo, "$(P):$(NAME):TESTGEN")
{
field(DESC, "Turn on/off Testgen Signal")
field(DTYP, "stream")
field(OUT, "@$(PROTO) switchTestgenOnOff($(P):$(NAME):) $(ASYN_PORT)")
field(VAL, 0)
field(ZNAM, "OFF")
field(ONAM, "ON")
}
record(longout, "$(P):$(NAME):TESTGEN-LOWRATE")
{
field(DESC, "Set Minimum Testgen Rate")
field(DTYP, "stream")
field(OUT, "@$(PROTO) setTestSignal($(P):$(NAME):) $(ASYN_PORT)")
field(VAL, 1000)
}
record(longout, "$(P):$(NAME):TESTGEN-HIGHRATE")
{
field(DESC, "Set Maximum Testgen Rate")
field(DTYP, "stream")
field(OUT, "@$(PROTO) setTestSignal($(P):$(NAME):) $(ASYN_PORT)")
field(VAL, 1000)
}

View File

@ -1,13 +0,0 @@
require asyn
# Need to be set by user
# epicsEnvSet("CNTBOX_HOST", "testinst-daq1:2000")
# epicsEnvSet("ASYN_PORT", "el737")
# epicsEnvSet("PREFIX", "SQ:SINQTEST")
# epicsEnvSet("NAME", "COUNTERBOX")
epicsEnvSet("PROTO", "$(sinq_DB)counterbox.proto")
drvAsynIPPortConfigure("$(ASYN_PORT)", "$(CNTBOX_HOST)", 0, 0, 0)
dbLoadRecords("$(sinq_DB)counterbox_common.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")
dbLoadRecords("$(sinq_DB)counterbox.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")

View File

@ -0,0 +1,7 @@
require asyn
require stream
epicsEnvSet("PROTO", "$(counterbox_DB)counterbox.proto")
drvAsynIPPortConfigure("$(ASYN_PORT)", "$(CNTBOX_HOST)", 0, 0, 0)
dbLoadRecords("$(counterbox_DB)counterbox_common.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")
dbLoadRecords("$(counterbox_DB)counterbox_4ch.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")

View File

@ -0,0 +1,7 @@
require asyn
require stream
epicsEnvSet("PROTO", "$(counterbox_DB)counterbox.proto")
drvAsynIPPortConfigure("$(ASYN_PORT)", "$(CNTBOX_HOST)", 0, 0, 0)
dbLoadRecords("$(counterbox_DB)counterbox_common.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")
dbLoadRecords("$(counterbox_DB)counterbox_8ch.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")

View File

@ -1,13 +1,8 @@
require asyn
require stream
# Need to be set by user
# epicsEnvSet("CNTBOX_HOST", "testinst-daq1:2000")
# epicsEnvSet("ASYN_PORT", "el737")
# epicsEnvSet("PREFIX", "SQ:SINQTEST")
# epicsEnvSet("NAME", "COUNTERBOX")
epicsEnvSet("PROTO", "$(sinq_DB)counterbox.proto")
epicsEnvSet("PROTO", "$(counterbox_DB)counterbox.proto")
drvAsynIPPortConfigure("$(ASYN_PORT)", "$(CNTBOX_HOST)", 0, 0, 0)
dbLoadRecords("$(sinq_DB)counterbox_common.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")
dbLoadRecords("$(sinq_DB)counterbox_v2.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")
dbLoadRecords("$(counterbox_DB)counterbox_common.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")
dbLoadRecords("$(counterbox_DB)counterbox_v2.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")
$(LOAD_TEST_PVS=#) $(LOAD_TEST_PVS) dbLoadRecords("$(counterbox_DB)counterbox_v2_test.db", "P=$(PREFIX), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=$(ASYN_PORT)")