##########################################################################
# 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, "$(U):DISTAT") {
  field(DESC, "digital inputs")
  field(PINI, "YES")
  field(DTYP, "stream")
  field(INP, "@aerotech.proto getDINall($(AXIS)) $(PORT)")
  field(SCAN, "1 second")
  field(SDIS, "$(U):DISABLEALLPVS")
}

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

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

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

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

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

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

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

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

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

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

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

record(bi, "$(U):ENABLEDSTAT") {
  field(DESC, "Axis enabled")
  field(INP,  "$(U):STATS1.B0")
  field(ZNAM, "Disabled")
  field(ONAM, "Enabled")
  field(SDIS, "$(U):DISABLEALLPVS")
}

record(bi, "$(U):HOMEDSTAT") {
  field(DESC, "Axis homed")
  field(INP,  "$(U):STATS1.B1")
  field(ZNAM, "Not Homed")
  field(ONAM, "Homed")
  field(SDIS, "$(U):DISABLEALLPVS")
}

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

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

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

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

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

record(bo, "$(U):DISABLEALLPVS") {
  field(DESC, "Disable all pvs")
  field(ZNAM, "Device unavailable")
  field(ONAM, "Active")
}

record(ai, "$(U):IDES") {
  field(DESC, "axis current")
  field(PINI, "YES")
  field(DTYP, "stream")
  field(INP, "@aerotech.proto getCur($(AXIS)) $(PORT)")
  field(SCAN, "1 second")
  field(PREC, 2)
  field(SDIS, "$(U):DISABLEALLPVS")
}
# 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, "$(U):DIP0IN0") {
  field(DESC, "Port 0 Input 0")
  field(INP,  "$(U):DISTATS0.B0 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP0IN1") {
  field(DESC, "Port 0 Input 1")
  field(INP,  "$(U):DISTATS0.B1 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP0IN2") {
  field(DESC, "Port 0 Input 2")
  field(INP,  "$(U):DISTATS0.B2 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP0IN3") {
  field(DESC, "Port 0 Input 3")
  field(INP,  "$(U):DISTATS0.B3 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP0IN4") {
  field(DESC, "Port 0 Input 4")
  field(INP,  "$(U):DISTATS0.B4 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP0IN5") {
  field(DESC, "Port 0 Input 5")
  field(INP,  "$(U):DISTATS0.B5 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP1IN0") {
  field(DESC, "Port 1 Input 0")
  field(INP,  "$(U):DISTATS0.B8 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP1IN1") {
  field(DESC, "Port 1 Input 1")
  field(INP,  "$(U):DISTATS0.B9 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP1IN2") {
  field(DESC, "Port 1 Input 2")
  field(INP,  "$(U):DISTATS0.BA CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP1IN3") {
  field(DESC, "Port 1 Input 3")
  field(INP,  "$(U):DISTATS0.BB CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP1IN4") {
  field(DESC, "Port 1 Input 4")
  field(INP,  "$(U):DISTATS0.BC CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP1IN5") {
  field(DESC, "Port 1 Input 5")
  field(INP,  "$(U):DISTATS0.BD CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP1IN6") {
  field(DESC, "Port 1 Input 6")
  field(INP,  "$(U):DISTATS0.BE CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP1IN7") {
  field(DESC, "Port 1 Input 7")
  field(INP,  "$(U):DISTATS0.BF CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP2IN0") {
  field(DESC, "Port 2 Input 0")
  field(INP,  "$(U):DISTATS1.B0 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP2IN1") {
  field(DESC, "Port 2 Input 1")
  field(INP,  "$(U):DISTATS1.B1 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP2IN2") {
  field(DESC, "Port 2 Input 2")
  field(INP,  "$(U):DISTATS1.B2 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP2IN3") {
  field(DESC, "Port 2 Input 3")
  field(INP,  "$(U):DISTATS1.B3 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP2IN4") {
  field(DESC, "Port 2 Input 4")
  field(INP,  "$(U):DISTATS1.B4 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP2IN5") {
  field(DESC, "Port 2 Input 5")
  field(INP,  "$(U):DISTATS1.B5 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP2IN6") {
  field(DESC, "Port 2 Input 6")
  field(INP,  "$(U):DISTATS1.B6 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  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, "$(U):DIP2IN7") {
  field(DESC, "Port 2 Input 7")
  field(INP,  "$(U):DISTATS1.B7 CP NMS")
  field(ZNAM, "Off")
  field(ONAM, "On")
  field(SDIS, "$(U):DISABLEALLPVS")
  info(autosaveFields, "DESC")
}

