##########################################################################
# Description:
# This database gets the digital input status from the Aerotech controller
# and splits it into two MBBI records.
# This database also gets axis specifc status and fault pv`s
# Disableallpvs PV can be used to disable all the pv`s for the device
#
# Macros:
# U 	- Device prefix
# PORT 	- Aerotech asyn port
# AXIS 	- Aerotech axis identifier
# SCAN 	- Desired scan rate
# MAD   - mad device name
##########################################################################
record(ai, "$(DEVICE):DISTAT") {
  field(DESC, "digital inputs")
  field(PINI, "YES")
  field(DTYP, "stream")
  field(INP, "@aerotech.proto getDINall(@$(AXIS)) $(ASYN_PORT)")
  field(SCAN, "1 second")
}

record(mbbiDirect, "$(DEVICE):DISTATS1") {
  field(DESC, "Digital input lower bits")
  field(DTYP, "Raw Soft Channel")
  field(INP, "$(DEVICE):DISTAT CP MS")
}

record(mbbiDirect, "$(DEVICE):DISTATS2") {
  field(DESC, "Digital input higher bits")
  field(DTYP, "Raw Soft Channel")
  field(INP, "$(DEVICE):DISTAT CP MS")
  field(SHFT, "16")
}

record(ai, "$(DEVICE):STAT") {
  field(DESC, "axis status")
  field(PINI, "YES")
  field(DTYP, "stream")
  field(INP, "@aerotech.proto axisStatus(@$(AXIS)) $(ASYN_PORT)")
  field(SCAN, "1 second")
}

record(ai, "$(DEVICE):FAULT") {
  field(DESC, "axis fault")
  field(PINI, "YES")
  field(DTYP, "stream")
  field(INP, "@aerotech.proto axisFault(@$(AXIS)) $(ASYN_PORT)")
  field(SCAN, "1 second")
}

record(ai, "$(DEVICE):AUTOHOMETRIGFAULT") {
  field(DESC, "fault to trigger autohome")
  field(DTYP, "stream")
  field(INP,  "@aerotech.proto getIGLOBAL(60) $(ASYN_PORT)")
  field(PINI, "YES")
  field(SCAN,"1 second")
}

record(mbbiDirect, "$(DEVICE):AUTOHOMETRIGFAULTS1") {
  field(DESC, "fault lower bits")
  field(DTYP, "Raw Soft Channel")
  field(INP, "$(DEVICE):AUTOHOMETRIGFAULT CP MS")
}

record(mbbiDirect, "$(DEVICE):AUTOHOMETRIGFAULTS2") {
  field(DESC, "fault higher bits")
  field(DTYP, "Raw Soft Channel")
  field(INP, "$(DEVICE):AUTOHOMETRIGFAULT CP MS")
  field(SHFT, "16")
}

record(mbbiDirect, "$(DEVICE):STATS1") {
  field(DESC, "status lower bits")
  field(DTYP, "Raw Soft Channel")
  field(INP, "$(DEVICE):STAT CP MS")
}

record(mbbiDirect, "$(DEVICE):STATS2") {
  field(DESC, "status higher bits")
  field(DTYP, "Raw Soft Channel")
  field(INP, "$(DEVICE):STAT CP MS")
  field(SHFT, "16")
}

record(mbbiDirect, "$(DEVICE):FAULTS1") {
  field(DESC, "fault lower bits")
  field(DTYP, "Raw Soft Channel")
  field(INP, "$(DEVICE):FAULT CP MS")
}

record(mbbiDirect, "$(DEVICE):FAULTS2") {
  field(DESC, "fault higher bits")
  field(DTYP, "Raw Soft Channel")
  field(INP, "$(DEVICE):FAULT CP MS")
  field(SHFT, "16")
}

record(bi, "$(DEVICE):ENABLEDSTAT") {
  field(DESC, "Axis enabled")
  field(INP,  "$(DEVICE):STATS1.B0 CP MS")
  field(ZNAM, "Disabled")
  field(ONAM, "Enabled")
}

record(bi, "$(DEVICE):HOMEDSTAT") {
  field(DESC, "Axis homed")
  field(INP,  "$(DEVICE):STATS1.B1 CP MS")
  field(ZNAM, "Not Homed")
  field(ONAM, "Homed")
  field(ZSV, "MAJOR")
  field(OSV, "NO_ALARM")
}

# If both limit switch show as active
record(calcout, "$(DEVICE):CABLESTAT_CALC") {
  field(DESC, "Motor Cable Status")
  field(INPA, "$(DEVICE):STATS2.B6 CP MS")
  field(INPB, "$(DEVICE):STATS2.B7 CP MS")
  field(CALC, "(A&&B)")
  field(FLNK, "$(DEVICE):CABLESTAT")
}

record(bo, "$(DEVICE):CABLESTAT") {
  field(DESC, "Motor Cable Status")
  field(DOL,  "$(DEVICE):CABLESTAT_CALC MS")
  field(ONAM, "Motor cable disconnected")
  field(ZNAM, "OK")
  field(ZSV, "MAJOR")
  field(OSV, "NO_ALARM")
}

record(bi, "$(DEVICE):MOVEACTIVE") {
  field(DESC, "Move active")
  field(INP,  "$(DEVICE):STATS1.B3 CP MS")
  field(ZNAM, "Not moving")
  field(ONAM, "Moving")
}

record(stringout, "$(DEVICE):FAULTACK") {
  field(DESC, "Ack fault on axis")
  field(DTYP, "stream")
  field(OUT,  "@aerotech.proto axisFaultAck(@$(AXIS)) $(ASYN_PORT)")
}

record(stringout, "$(DEVICE):ENABLE") {
  field(DESC, "Enable axis")
  field(DTYP, "stream")
  field(OUT,  "@aerotech.proto axisEnable(@$(AXIS)) $(ASYN_PORT)")
}

record(stringout, "$(DEVICE):ABORT") {
  field(DESC, "Abort axis")
  field(DTYP, "stream")
  field(OUT,  "@aerotech.proto axisAbort(@$(AXIS)) $(ASYN_PORT)")
}

record(stringout, "$(DEVICE):DISABLE") {
  field(DESC, "Disable axis")
  field(DTYP, "stream")
  field(OUT,  "@aerotech.proto axisDisable(@$(AXIS)) $(ASYN_PORT)")
}

record(stringout, "$(DEVICE):HOME") {
  field(DESC, "Home axis")
  field(DTYP, "stream")
  field(OUT,  "@aerotech.proto axisHome(@$(AXIS)) $(ASYN_PORT)")
}

record(ai, "$(DEVICE):IDES") {
  field(DESC, "axis current")
  field(PINI, "YES")
  field(DTYP, "stream")
  field(INP, "@aerotech.proto getCur(@$(AXIS)) $(ASYN_PORT)")
  field(SCAN, "1 second")
  field(PREC, 2)
}

record(ai, "$(DEVICE):EXTPOSN") {
  field(DESC, "Aux Encoder Position")
  field(PINI, "YES")
  field(DTYP, "stream")
  field(INP, "@aerotech.proto extPos(@$(AXIS)) $(ASYN_PORT)")
  field(SCAN, "1 second")
  field(PREC, 3)
  field(LINR, "SLOPE")
  info(autosaveFields, "ESLO EOFF EGU")
}

record(ai, "$(DEVICE):EncOffset") {
    field(DESC, "$(MAD) Encoder offset")
    field(DTYP, "stream")
    field(INP, "@aerotech.proto getEncOff(@$(AXIS)) $(ASYN_PORT) ")
    field(PINI, "YES")
    field(PREC, "3")
    field(EGU, "mm")
}


# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP0IN0") {
  field(DESC, "Port 0 Input 0")
  field(INP,  "$(DEVICE):DISTATS0.B0 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP0IN1") {
  field(DESC, "Port 0 Input 1")
  field(INP,  "$(DEVICE):DISTATS0.B1 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP0IN2") {
  field(DESC, "Port 0 Input 2")
  field(INP,  "$(DEVICE):DISTATS0.B2 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP0IN3") {
  field(DESC, "Port 0 Input 3")
  field(INP,  "$(DEVICE):DISTATS0.B3 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP0IN4") {
  field(DESC, "Port 0 Input 4")
  field(INP,  "$(DEVICE):DISTATS0.B4 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP0IN5") {
  field(DESC, "Port 0 Input 5")
  field(INP,  "$(DEVICE):DISTATS0.B5 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP1IN0") {
  field(DESC, "Port 1 Input 0")
  field(INP,  "$(DEVICE):DISTATS0.B8 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP1IN1") {
  field(DESC, "Port 1 Input 1")
  field(INP,  "$(DEVICE):DISTATS0.B9 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP1IN2") {
  field(DESC, "Port 1 Input 2")
  field(INP,  "$(DEVICE):DISTATS0.BA CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP1IN3") {
  field(DESC, "Port 1 Input 3")
  field(INP,  "$(DEVICE):DISTATS0.BB CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP1IN4") {
  field(DESC, "Port 1 Input 4")
  field(INP,  "$(DEVICE):DISTATS0.BC CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP1IN5") {
  field(DESC, "Port 1 Input 5")
  field(INP,  "$(DEVICE):DISTATS0.BD CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP1IN6") {
  field(DESC, "Port 1 Input 6")
  field(INP,  "$(DEVICE):DISTATS0.BE CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP1IN7") {
  field(DESC, "Port 1 Input 7")
  field(INP,  "$(DEVICE):DISTATS0.BF CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP2IN0") {
  field(DESC, "Port 2 Input 0")
  field(INP,  "$(DEVICE):DISTATS1.B0 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP2IN1") {
  field(DESC, "Port 2 Input 1")
  field(INP,  "$(DEVICE):DISTATS1.B1 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP2IN2") {
  field(DESC, "Port 2 Input 2")
  field(INP,  "$(DEVICE):DISTATS1.B2 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP2IN3") {
  field(DESC, "Port 2 Input 3")
  field(INP,  "$(DEVICE):DISTATS1.B3 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP2IN4") {
  field(DESC, "Port 2 Input 4")
  field(INP,  "$(DEVICE):DISTATS1.B4 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP2IN5") {
  field(DESC, "Port 2 Input 5")
  field(INP,  "$(DEVICE):DISTATS1.B5 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP2IN6") {
  field(DESC, "Port 2 Input 6")
  field(INP,  "$(DEVICE):DISTATS1.B6 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

# Borrowed
# File: xleap_din_bit.template
# Author: Wayne Lewis
# Date: 2017-05-08
#
# Description:
# This database is the template for the generic Aerotech 
# digital input PVs.
#
# Macros:
# U 	- Device prefix
# Port 	- Aerotech input port number (port is Aerotech terminology)
# In .	- Input number
# Word 	- MBBI word (from aerotech_din.db) 
# Bit 	- Bit number from word

record(bi, "$(DEVICE):DIP2IN7") {
  field(DESC, "Port 2 Input 7")
  field(INP,  "$(DEVICE):DISTATS1.B7 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  info(autosaveFields, "DESC")
}

record(motor, "$(DEVICE):MOTR") {
  field(DESC, "$(MAD)")
  field(DTYP, "asynMotor")
  field(DIR, "Pos")
  field(VELO, "2")
  field(VBAS, "1")
  field(VMAX, "4")
  field(ACCL, "0.1")
  field(BDST, "0")
  field(OUT, "@asyn($(MOTOR_PORT),$(AXIS))")
  field(MRES, "2.5e-4")
  field(ERES, "1")
  field(PREC, "4")
  field(EGU, "mm")
  field(DHLM, "0")
  field(DLLM, "0")
  field(UEIP, "1")
  field(TWV, "1")
  field(FOFF, "Frozen")
  field(OFF, "0")
  field(URIP, "0")
  field(RRES, "1")
  field(RTRY, "0")
  field(RDBL, "")
  field(RDBD, "1")
  field(DLY, "0")
  field(SCAN, "Passive")
  info(autosaveFields_pass0, "VAL")
  info(autosaveFields, "DIR DESC VMAX VBAS ACCL VELO MRES ERES PREC EGU DHLM DLLM DLY TWV RDBL RRES RTRY URIP UEIP FOFF OFF FRAC JVEL JAR HVEL HLM LLM")
}
# Store if device is in position
record(bi, "$(DEVICE):State"){
  field(DESC, "Chicane usable")
  field(ZNAM, "Active")
  field(ONAM, "Locked Off")
}

# motor encoder offset
record(ai, "$(DEVICE):EncOffset") {
    field(DESC, "$(MAD) Encoder offset")
    field(DTYP, "stream")
    field(INP, "@aerotech.proto getEncOff(@$(AXIS)) $(ASYN_PORT) ")
    field(PINI, "YES")
    field(PREC, "6")
    field(EGU, "mm")
}

# Set target position when wiggler is extracted 
record(ao, "$(DEVICE):TargetPos") {
    field(DESC, "$(MAD) Target position")
    field(DRVH, "306.64")
    field(DRVL, "-1.0")
    field(HOPR, "306.64")
    field(LOPR, "-1.0")
    field(PREC, "4")
    field(EGU, "mm")
    info(autosaveFields, "VAL DRVL DRVH LOPR HOPR")
}

# Move request initiates a sequence
record(bo, "$(DEVICE):TRIM") {
  field(DESC, "Start moving $(MAD)")
  field(ZNAM, "Standby")
  field(ONAM, "Start Move")
}

record(bi, "$(DEVICE):TRIMSTS") {
  field(DESC, "$(MAD) Trim status")
  field(ZNAM, "Move Done")
  field(ONAM, "Move Requested")
}

record(bi, "$(DEVICE):TRIM_DBG") {
  field(DESC, "$(MAD) Trim debug")
  field(ZNAM, "Off")
  field(ONAM, "On")
}

record(bo, "$(DEVICE):MOTR_ALRM") {
  field(DESC, "In Beam Alarm")
  field(DOL,  "$(DEVICE):MOTRERROR MS")
  field(OMSL, "closed_loop")
  field(ZNAM, "IN_BEAM")
  field(ONAM, "OUT_OF_BEAM")
  field(ZSV,  "MAJOR")
  field(OSV,  "NO_ALARM")
}

record(calcout, "$(DEVICE):MOTRERROR") {
  field(CALC, "ABS(A-B)>C?0:1")
  field(FLNK, "$(DEVICE):MOTR_ALRM")
  field(SCAN, "1 second")
  field(INPA, "$(DEVICE):MOTR.RBV NPP MS")
  field(INPB, "0")
  field(INPC, "260")
  field(HIGH, "1")
  field(LOW,  "0")
  field(HSV, "MAJOR")
  field(LSV, "NO_ALARM")
  info(autosaveFields, "CALC INPA INPB INPC")
}

