Counting from nicos works, but time preset is not correct
This commit is contained in:
1
Makefile
1
Makefile
@@ -20,6 +20,7 @@ TEMPLATES += db/daq_common.db
|
||||
TEMPLATES += db/daq_2nd_gen.db
|
||||
TEMPLATES += db/daq_2nd_gen_test.db
|
||||
TEMPLATES += db/daq.proto
|
||||
TEMPLATES += db/daq_soft_proton.db
|
||||
|
||||
# Just for simulation
|
||||
TEMPLATES += db/daq_simcontrol.db
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# EPICS database for counterbox-like interface using proton current,
|
||||
# as retrieved via network from HIPA.
|
||||
#
|
||||
# This is created to be able reuse the SinqDAQ interface
|
||||
@@ -52,10 +51,11 @@ record(bi, "$(INSTR)$(NAME):IS_LOWRATE")
|
||||
# Commands
|
||||
################################################################################
|
||||
|
||||
record(int64in, "$(INSTR)$(NAME):PRESET-COUNT")
|
||||
record(ao, "$(INSTR)$(NAME):PRESET-COUNT")
|
||||
{
|
||||
field(DESC, "Count until preset reached")
|
||||
field(VAL, 0)
|
||||
field(PREC, 2)
|
||||
field(FLNK, "$(INSTR)$(NAME):PRESET-COUNT-TRIG")
|
||||
}
|
||||
|
||||
@@ -68,58 +68,75 @@ record(longout, "$(INSTR)$(NAME):PRESET-COUNT-TRIG")
|
||||
field(FLNK, "$(INSTR)$(NAME):COUNT-TYPE")
|
||||
}
|
||||
|
||||
record(calcout, "$(INSTR)$(NAME):PRESET-TIME")
|
||||
record(ao, "$(INSTR)$(NAME):PRESET-TIME")
|
||||
{
|
||||
field(DESC, "Count for specified time")
|
||||
field(VAL, 0)
|
||||
field(PREC, 2)
|
||||
field(EGU, "seconds")
|
||||
field(EGU, "seconds")
|
||||
field(FLNK, "$(INSTR)$(NAME):PRESET-TIME-TRIG")
|
||||
}
|
||||
|
||||
record(longout, "$(INSTR)$(NAME):PRESET-TIME-TRIG")
|
||||
{
|
||||
field(DESC, "Count until preset time reached")
|
||||
# Signal count preset as command
|
||||
field(OCAL, 2)
|
||||
field(OOPT, "Every Time")
|
||||
field(DOPT, "Use OCAL")
|
||||
field(VAL, 2)
|
||||
field(OUT, "$(INSTR)$(NAME):COMMAND-TRIG PP")
|
||||
field(FLNK, "$(INSTR)$(NAME):COUNT-TYPE")
|
||||
}
|
||||
|
||||
record(calcout, "$(INSTR)$(NAME):PAUSE")
|
||||
record(longout, "$(INSTR)$(NAME):PAUSE")
|
||||
{
|
||||
field(DESC, "Pause the current count")
|
||||
field(VAL, 0)
|
||||
field(OCAL, 3)
|
||||
field(OOPT, "Every Time")
|
||||
field(DOPT, "Use OCAL")
|
||||
field(VAL, 3)
|
||||
field(DRVL, 3)
|
||||
field(DRVH, 3)
|
||||
field(OUT, "$(INSTR)$(NAME):COMMAND-TRIG PP")
|
||||
}
|
||||
|
||||
record(calcout, "$(INSTR)$(NAME):CONTINUE")
|
||||
record(longout, "$(INSTR)$(NAME):CONTINUE")
|
||||
{
|
||||
field(DESC, "Continue with a count that was paused")
|
||||
field(VAL, "0")
|
||||
field(OCAL, 4)
|
||||
field(OOPT, "Every Time")
|
||||
field(DOPT, "Use OCAL")
|
||||
field(VAL, 4)
|
||||
field(DRVL, 4)
|
||||
field(DRVH, 4)
|
||||
field(OUT, "$(INSTR)$(NAME):COMMAND-TRIG PP")
|
||||
}
|
||||
|
||||
record(calcout, "$(INSTR)$(NAME):STOP")
|
||||
record(longout, "$(INSTR)$(NAME):STOP")
|
||||
{
|
||||
field(DESC, "Stop the current counting operation")
|
||||
field(OCAL, 5)
|
||||
field(OOPT, "Every Time")
|
||||
field(DOPT, "Use OCAL")
|
||||
field(VAL, 5)
|
||||
field(DRVL, 5)
|
||||
field(DRVH, 5)
|
||||
field(OUT, "$(INSTR)$(NAME):COMMAND-TRIG PP")
|
||||
}
|
||||
|
||||
record(calcout, "$(INSTR)$(NAME):FULL-RESET")
|
||||
record(longout, "$(INSTR)$(NAME):FULL-RESET")
|
||||
{
|
||||
field(DESC, "Reset the DAQ")
|
||||
field(OCAL, 6)
|
||||
field(OOPT, "Every Time")
|
||||
field(DOPT, "Use OCAL")
|
||||
field(DESC, "Perform full reset")
|
||||
field(VAL, 6)
|
||||
field(DRVL, 6)
|
||||
field(DRVH, 6)
|
||||
field(OUT, "$(INSTR)$(NAME):COMMAND-TRIG PP")
|
||||
}
|
||||
|
||||
# Emulate Reset elapsed time
|
||||
# 0. set status to busy
|
||||
# 1. set elapsed time to 0
|
||||
# 2. set status to OK
|
||||
record(seq, "$(INSTR)$(NAME):CT")
|
||||
{
|
||||
field(SELM, "All")
|
||||
field(LNK0, "$(INSTR)$(NAME):ETS PP")
|
||||
field(DO0, 1)
|
||||
field(LNK1, "$(INSTR)$(NAME):ELAPSED-TIME PP")
|
||||
field(DO1, 0)
|
||||
field(LNK2, "$(INSTR)$(NAME):ETS PP")
|
||||
field(DO2, 0)
|
||||
}
|
||||
|
||||
# Record is to signal command given by the client to the emulated counter.
|
||||
# It's set back to no command from the emulated counter subroutine record
|
||||
record(mbbi, "$(INSTR)$(NAME):COMMAND-TRIG")
|
||||
@@ -138,8 +155,8 @@ record(mbbi, "$(INSTR)$(NAME):COMMAND-TRIG")
|
||||
field(FRVL, 4)
|
||||
field(FVST, "Stop command")
|
||||
field(FVVL, 5)
|
||||
field(FVST, "Full reset command")
|
||||
field(FVVL, 6)
|
||||
field(SXST, "Full reset command")
|
||||
field(SXVL, 6)
|
||||
}
|
||||
|
||||
# Copy COMMAND-TRIG to memorize what type of count is on-going
|
||||
@@ -173,6 +190,35 @@ record(ai,"$(INSTR)$(NAME):ELAPSED-TIME")
|
||||
{
|
||||
field(DESC, "DAQ Measured Time")
|
||||
field(EGU, "sec")
|
||||
# We need to process ETS to signal to client
|
||||
# field(FLNK, "$(INSTR)$(NAME):ETO")
|
||||
}
|
||||
|
||||
# Trigger a change in status as value returned to 0
|
||||
#record(seq, "$(INSTR)$(NAME):ETO")
|
||||
#{
|
||||
# field(DESC, "Trigger Returned to 0 Status")
|
||||
# field(LNK0, "$(INSTR)$(NAME):ETS PP")
|
||||
# field(DO0, 0)
|
||||
# field(SELM, "Specified")
|
||||
# field(SELL, "$(INSTR)$(NAME):ELAPSED-TIME.VAL")
|
||||
#}
|
||||
|
||||
# Current Status of elapsed time
|
||||
# This is only to satify the interface.
|
||||
record(bi, "$(INSTR)$(NAME):ETS")
|
||||
{
|
||||
field(DESC, "Channel Status")
|
||||
field(VAL, 0)
|
||||
field(ZNAM, "OK")
|
||||
field(ONAM, "CLEARING")
|
||||
}
|
||||
|
||||
record(longout, "$(INSTR)$(NAME):MONITOR-CHANNEL")
|
||||
{
|
||||
alias("$(INSTR)$(NAME):MONITOR-CHANNEL_RBV")
|
||||
field(DESC, "PRESET-COUNT Monitors this channel")
|
||||
field(VAL, 1)
|
||||
}
|
||||
|
||||
# Array Subroutine record which emulates the counterbox functionality
|
||||
@@ -187,49 +233,50 @@ record(aSub, "$(INSTR)$(NAME):EMULATION")
|
||||
# The first 4 inputs are also mapped as the first 4 outputs
|
||||
field(INPA, "$(INSTR)$(NAME):STATUS")
|
||||
field(FTA, "ULONG")
|
||||
field(INPB, "$(INSTR)$(NAME):M0")
|
||||
field(INPB, "$(INSTR)$(NAME):M1")
|
||||
field(FTB, "INT64")
|
||||
field(INPC, "$(INSTR)$(NAME):ELAPSED-TIME")
|
||||
field(FTC, "DOUBLE")
|
||||
field(OUTD, "$(INSTR)$(NAME):COMMAND-TRIG")
|
||||
field(INPD, "$(INSTR)$(NAME):COMMAND-TRIG")
|
||||
field(FTD, "ULONG")
|
||||
field(OUTE, "$(INSTR)$(NAME):THRESHOLD")
|
||||
field(INPE, "$(INSTR)$(NAME):THRESHOLD")
|
||||
field(FTE, "DOUBLE")
|
||||
|
||||
# Address the PV which are mapped as input backwards
|
||||
field(INPF, "$(INSTR)$(NAME):COUNT-TYPE")
|
||||
field(FTF, "ULONG")
|
||||
field(INPG, "$(INSTR)$(NAME):PRESET-COUNT")
|
||||
field(FTG, "INT64")
|
||||
field(FTG, "DOUBLE")
|
||||
field(INPH, "$(INSTR)$(NAME):PRESET-TIME")
|
||||
field(FTH, "DOUBLE")
|
||||
# L is last input before EPICS 7.0.10
|
||||
field(INPJ, "$(INSTR)$(NAME):R0-PREV")
|
||||
field(INPJ, "$(INSTR)$(NAME):R1-PREV")
|
||||
field(FTJ, "DOUBLE")
|
||||
field(INPL, "$(INSTR)$(NAME):R0 PP")
|
||||
field(INPL, "$(INSTR)$(NAME):R1 PP")
|
||||
field(FTL, "DOUBLE")
|
||||
|
||||
# The first 4 outputs are also mapped as the first 4 inputs
|
||||
field(OUTA, "$(INSTR)$(NAME):STATUS PP")
|
||||
field(FTVA, "ULONG")
|
||||
field(OUTB, "$(INSTR)$(NAME):M0 PP")
|
||||
field(OUTB, "$(INSTR)$(NAME):M1 PP")
|
||||
field(FTVB, "INT64")
|
||||
field(OUTC, "$(INSTR)$(NAME):ELAPSED-TIME PP")
|
||||
field(FTVC, "DOUBLE")
|
||||
field(OUTD, "$(INSTR)$(NAME):COMMAND-TRIG PP")
|
||||
field(FTVD, "ULONG")
|
||||
field(OUTE, "$(INSTR)$(NAME):R0-PREV PP")
|
||||
field(FTVE, "DOUBLE")
|
||||
field(OUTE, "$(INSTR)$(NAME):R1-PREV PP")
|
||||
field(FTVE, "DOUBLE")
|
||||
field(OUTF, "$(INSTR)$(NAME):IS_LOWRATE PP")
|
||||
field(FTVF, "ULONG")
|
||||
field(OUTF, "$(INSTR)$(NAME):MSG_TXT PP")
|
||||
field(FTVF, "CHAR")
|
||||
field(FTVF, "ULONG")
|
||||
field(OUTF, "$(INSTR)$(NAME):MsgTxt PP")
|
||||
field(FTVF, "CHAR")
|
||||
field(NEVF, 40)
|
||||
}
|
||||
|
||||
#######################
|
||||
# Channel interface
|
||||
#######################
|
||||
record(int64in, "$(INSTR)$(NAME):M0")
|
||||
record(int64in, "$(INSTR)$(NAME):M1")
|
||||
{
|
||||
field(DESC, "DAQ CH0, proton current")
|
||||
field(EGU, "cts")
|
||||
@@ -237,7 +284,7 @@ record(int64in, "$(INSTR)$(NAME):M0")
|
||||
|
||||
# The proton rate take by a PV over the network, PV named indicated by $(REMOTE_RATE_PV) macro
|
||||
# It emulates Zero rate if either shutter is closed.
|
||||
record(calc, "$(INSTR)$(NAME):R0")
|
||||
record(calc, "$(INSTR)$(NAME):R1")
|
||||
{
|
||||
field(DESC, "Rate of DAQ CH0 proton current")
|
||||
#field(INPA, "$(REMOTE_RATE_PV) CA")
|
||||
@@ -252,24 +299,28 @@ record(calc, "$(INSTR)$(NAME):R0")
|
||||
}
|
||||
|
||||
# Store previous rate value, so we can average over the period
|
||||
record(ai, "$(INSTR)$(NAME):R0-PREV") {
|
||||
record(ai, "$(INSTR)$(NAME):R1-PREV") {
|
||||
field(DESC, "Previous rate of DAQ CH0 proton current")
|
||||
}
|
||||
|
||||
# Clear channel, has to be calcout due to client
|
||||
# writing 1 to it.
|
||||
record(calcout, "$(INSTR)$(NAME):C0")
|
||||
# Emulate clearing channel
|
||||
# 0. set status to busy
|
||||
# 1. set elapsed time to 0
|
||||
# 2. set status to OK
|
||||
record(seq, "$(INSTR)$(NAME):C1")
|
||||
{
|
||||
field(DESC, "Clear the current channel count")
|
||||
field(OOPT, "Every Time")
|
||||
field(DOPT, "Use OCAL")
|
||||
field(OCAL, "0")
|
||||
field(OUT, "$(INSTR)$(NAME):M0 PP")
|
||||
field(SELM, "All")
|
||||
field(LNK0, "$(INSTR)$(NAME):S1 PP")
|
||||
field(DO0, 1)
|
||||
field(LNK1, "$(INSTR)$(NAME):M1 PP")
|
||||
field(DO1, 0)
|
||||
field(LNK2, "$(INSTR)$(NAME):S1 PP")
|
||||
field(DO2, 0)
|
||||
}
|
||||
|
||||
# Current Status of Channel, i.e. is it ready to count?
|
||||
# This is probbably only need to satify the interface.
|
||||
record(bi, "$(INSTR)$(NAME):S0")
|
||||
# Current Status of Channel
|
||||
# This is only to satify the interface.
|
||||
record(bi, "$(INSTR)$(NAME):S1")
|
||||
{
|
||||
field(DESC, "Channel Status")
|
||||
field(VAL, 0)
|
||||
@@ -279,7 +330,7 @@ record(bi, "$(INSTR)$(NAME):S0")
|
||||
|
||||
record(calc, "$(INSTR)$(NAME):PROTON_CURR") {
|
||||
field(SCAN, ".1 second")
|
||||
field(CALC, "1500 * 101 * SIN(A)")
|
||||
field(CALC, "1500 + 101 * SIN(A)")
|
||||
field(INPA, "$(INSTR)$(NAME):PROTON_CURR_VAR PP")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
require sinqDAQ, soederqvist_a
|
||||
|
||||
|
||||
var softProtonDebug=1
|
||||
var softProtonDebug 1
|
||||
|
||||
dbLoadRecords("$(sinqDAQ_DB)daq_soft_proton.db", "INSTR=$(INSTR), NAME=$(NAME), PROTO=$(PROTO), ASYN_PORT=ASYN_$(NAME), CHANNELS=4")
|
||||
dbLoadRecords("$(sinqDAQ_DB)daq_soft_proton.db", "INSTR=$(INSTR), NAME=$(NAME), REMOTE_RATE_PV=NULL")
|
||||
|
||||
iocInit
|
||||
|
||||
dbpr SQ:TEST:SPC:EMULATION
|
||||
|
||||
@@ -4,3 +4,4 @@
|
||||
|
||||
device(stringin, INST_IO, devDAQStringError, "devDAQStringError")
|
||||
function(processEmulatedCounter)
|
||||
variable("softProtonDebug", int)
|
||||
|
||||
@@ -31,7 +31,7 @@ struct spc_internal {
|
||||
epicsFloat64 proton_rate;
|
||||
epicsFloat64 prev_proton_rate;
|
||||
epicsUInt32 count_type;
|
||||
epicsInt64 preset_count;
|
||||
epicsFloat64 preset_count;
|
||||
epicsFloat64 preset_time;
|
||||
epicsFloat64 average_rate;
|
||||
};
|
||||
@@ -61,6 +61,7 @@ enum status {
|
||||
|
||||
int handleNoop(struct spc_internal* spc, epicsOldString* msg_text) {
|
||||
const char* funcstr = "handleNoop";
|
||||
//if (softProtonDebug) printf("%s was called\n", funcstr);
|
||||
/* This shouldn't happen, but let's handle it just in case */
|
||||
if (spc->status >= INVALID || spc->command_trig > FULL_RESET) {
|
||||
strcpy(*msg_text, "INVALID STATE!");
|
||||
@@ -122,7 +123,7 @@ int handleNoop(struct spc_internal* spc, epicsOldString* msg_text) {
|
||||
static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
{
|
||||
const char* funcstr = "processEmulatedCounter";
|
||||
if (softProtonDebug) printf("%s was called\n", funcstr);
|
||||
//if (softProtonDebug) printf("%s was called\n", funcstr);
|
||||
|
||||
/* Declare internal variable */
|
||||
struct spc_internal spc_int;
|
||||
@@ -136,7 +137,7 @@ static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
spc->command_trig = *(epicsUInt32*)psub->d;
|
||||
spc->threshold = *(epicsFloat64*)psub->e;
|
||||
spc->count_type = *(epicsUInt32*)psub->f;
|
||||
spc->preset_count = *(epicsInt64*)psub->g;
|
||||
spc->preset_count = *(epicsFloat64*)psub->g;
|
||||
spc->preset_time = *(epicsFloat64*)psub->h;
|
||||
spc->prev_proton_rate = *(epicsFloat64*)psub->j;
|
||||
spc->proton_rate = *(epicsFloat64*)psub->l;
|
||||
@@ -157,9 +158,16 @@ static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
*prev_proton_rate_out = spc->proton_rate;
|
||||
|
||||
if (spc->average_rate < spc->threshold) {
|
||||
*is_low_rate_out = 0; /* Illogical but 0 is low_rate, 1 high rate */
|
||||
*is_low_rate_out = 1;
|
||||
} else {
|
||||
*is_low_rate_out = 1; /* Illogical but 0 is low_rate, 1 high rate */
|
||||
*is_low_rate_out = 0;
|
||||
}
|
||||
|
||||
if (softProtonDebug) {
|
||||
printf("%s: DEBUG:\n"
|
||||
"Status has value %d, \n"
|
||||
"Command trigger has value %d\n",
|
||||
funcstr, spc->status, spc->command_trig);
|
||||
}
|
||||
|
||||
/* Handle noop situations both valid and invalid */
|
||||
@@ -178,7 +186,7 @@ static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
*command_trig_out = NONE;
|
||||
if (softProtonDebug) printf("%s: Full reset done!\n", funcstr);
|
||||
return 0;
|
||||
} else if (spc->command_trig == STOP ||
|
||||
} else if (spc->command_trig == STOP ||
|
||||
(spc->status == IDLE && spc->command_trig == NONE)) {
|
||||
/* Stop is always valid, retains everything except status goes to idle.
|
||||
* This happens to be the same case as when IDLE and no command received */
|
||||
@@ -186,6 +194,7 @@ static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
*command_trig_out = NONE;
|
||||
*monitor_count_out = spc->monitor_count;
|
||||
*elapsed_time_out = spc->elapsed_time;
|
||||
if (softProtonDebug) printf("%s: Case STOP or IDLE!\n", funcstr);
|
||||
return 0;
|
||||
} else if (((spc->status == COUNTING || spc->status == LOW_RATE)
|
||||
&& spc->command_trig == PAUSE) ||
|
||||
@@ -198,6 +207,7 @@ static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
*command_trig_out = NONE;
|
||||
*monitor_count_out = spc->monitor_count;
|
||||
*elapsed_time_out = spc->elapsed_time;
|
||||
if (softProtonDebug) printf("%s: Case PAUSE!\n", funcstr);
|
||||
return 0;
|
||||
} else if (spc->status == IDLE &&
|
||||
(spc->command_trig == COUNT_PRESET || spc->command_trig == TIME_PRESET)) {
|
||||
@@ -218,6 +228,7 @@ static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
} else {
|
||||
*status_out = COUNTING;
|
||||
}
|
||||
if (softProtonDebug) printf("%s: Case received COUNT command!\n", funcstr);
|
||||
return 0;
|
||||
} else if ((((spc->status == LOW_RATE && spc->command_trig == NONE) ||
|
||||
(spc->status == LOW_RATE && spc->command_trig == CONTINUE)))
|
||||
@@ -228,9 +239,11 @@ static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
/* Maintain same counter and time*/
|
||||
*monitor_count_out = spc->monitor_count;
|
||||
*elapsed_time_out = spc->elapsed_time;
|
||||
if (softProtonDebug) printf("%s: Case LOW_RATE!\n", funcstr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (softProtonDebug) printf("%s: Case COUNT incremental cycle!\n", funcstr);
|
||||
/* Ending up here means:
|
||||
* 1. status == COUNTING && command_trig == NONE
|
||||
* 2. status == COUNTING && command_trig == CONTINUE
|
||||
@@ -262,7 +275,7 @@ static long processEmulatedCounter(struct aSubRecord *psub)
|
||||
(*elapsed_time_out >= spc->preset_time &&
|
||||
spc->count_type == TIME_PRESET) ||
|
||||
/* Monitor based count finished */
|
||||
(*monitor_count_out >= spc->preset_time &&
|
||||
(*monitor_count_out >= spc->preset_count &&
|
||||
spc->count_type == COUNT_PRESET)) {
|
||||
*status_out = IDLE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user