#=================================================================#
# Template file: NDROIStat.template
###################################################################
#
# Database template for ROI Stat plugin. This only provides
# the Name records. To add in ROIs use the NDROIStatN.template,
# or alternatively use a single NDROIStat8.template to get up to 8
# ROIs.
# 
# Macros:
# P,R - Base PV name
# PORT - Asyn port name
# ADDR - The Asyn address
# TIMEOUT - Asyn port timeout
#
# Matt Pearson
# Nov 2014
#
###################################################################

include "NDPluginBase.template"

# ///
# /// Reset the data for all the ROIs
# ///
record(bo, "$(P)$(R)ResetAll")
{
   field(DTYP, "asynInt32")
   field(OUT,  "@asyn($(PORT),$(ADDR=0),$(TIMEOUT=1))ROISTAT_RESETALL")
}

###################################################################
#  These records control time series                              #
###################################################################
record(mbbo, "$(P)$(R)TSControl")
{
   field(DTYP, "asynInt32")
   field(OUT,  "@asyn($(PORT),$(ADDR=0),$(TIMEOUT=1))ROISTAT_TS_CONTROL")
   field(ZRVL, "0")
   field(ZRST, "Erase/Start")
   field(ONVL, "1")
   field(ONST, "Start")
   field(TWVL, "2")
   field(TWST, "Stop")
   field(THVL, "3")
   field(THST, "Read")
   field(FRVL, "4")
   field(FRST, "Erase")
}

# This record periodically pokes the TSControl record with 3 to read the time series
# but only when TSAcquiring = Acquiring
record(longout, "$(P)$(R)TSRead")
{
   field(SDIS, "$(P)$(R)TSAcquiring NPP NMS")
   field(DISV, "0")
   field(OUT,  "$(P)$(R)TSControl PP MS")
   field(VAL,  "3")
   field(SCAN, "1 second")
   info(autosaveFields, "SCAN")
}

record(longout, "$(P)$(R)TSNumPoints")
{
   field(PINI, "YES")
   field(DTYP, "asynInt32")
   field(OUT,  "@asyn($(PORT),$(ADDR=0),$(TIMEOUT=1))ROISTAT_TS_NUM_POINTS")
   field(VAL,  "$(NCHANS)")
   field(DRVH, "$(NCHANS)")
   info(autosaveFields, "VAL")
}

record(longin, "$(P)$(R)TSCurrentPoint")
{
   field(DTYP, "asynInt32")
   field(INP,  "@asyn($(PORT),$(ADDR=0),$(TIMEOUT=1))ROISTAT_TS_CURRENT_POINT")
   field(SCAN, "I/O Intr")
}

record(bi, "$(P)$(R)TSAcquiring")
{
   field(DTYP, "asynInt32")
   field(INP,  "@asyn($(PORT),$(ADDR=0),$(TIMEOUT=1))ROISTAT_TS_ACQUIRING")
   field(ZNAM, "Done")
   field(ONAM, "Acquiring")
   field(ZSV,  "NO_ALARM")
   field(OSV,  "MINOR")
   field(SCAN, "I/O Intr")
}

