#==============================================================
#
#  Abs:  Configure DG645 Time Delay asyn connections
#
#  Name: init_tdly.cmd
#
#  Side: expects the following macros:
#            IO_PORT    - Comm asyn port name (i.e. "L2")
#            PORT       - Interface asyn port name (i.e. "DG0")
#            TDLY_NODE  - Host IP and port
#            AWG_NODE   - IP of AWG
#
#  Warning!!! MOXA ports start at 2001, while DIGI start at 2101
#
#  Facility:  EED Magnet Controls
#
#  Auth: 06-Dec-2021, An Le           (ANLE)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        09-Mar-2022, An Le           (ANLE):
#         Suppress debug messages
#
#==============================================================
#

# drvAsynIPPortConfigure(*portName,*hostInfo,priority,noAugoConnection,userFlags)
#   const char   *portName
#   const char   *hostInfo
#   unsigned int  priority
#   int           noAutoConnect
#   int           userFlags
drvAsynIPPortConfigure("${IO_PORT}","${TDLY_NODE}:5025",0,0,0)

# Diagnostics
asynSetTraceMask("${IO_PORT}", -1, 0x1F)
asynSetTraceIOMask("${IO_PORT}", -1, 0x2)

# Initialize input/output EOS
# asynOctetSetInputEos(*port, addr, *eos)
#   const char *port
#   int         addr
#   const char *eos
asynOctetSetInputEos("${IO_PORT}",0,"\r\n")

# asynOctetSetOutputEos(*port,addr,*eos)
#   const char *port
#   int         addr
#   const char *eos
asynOctetSetOutputEos("${IO_PORT}",0,"\n")

# drvAsynDG645(myport,ioport,ioaddr)
#       myport  - Interface asyn port name (i.e. "DG0")
#       ioport  - Comm asyn port name (i.e. "L2")
#       ioaddr  - Comm asyn port addr
drvAsynDG645("${PORT}","${IO_PORT}",-1)

# Connect to AWG through asyn IP Port
drvAsynIPPortConfigure("AWG", "${AWG_NODE}:5025")

epicsThreadSleep 1
asynSetTraceMask("${IO_PORT}", -1, 0x1)
asynSetTraceIOMask("${IO_PORT}", -1, 0x2)
asynSetTraceMask("${PORT}", -1, 0x1)
asynSetTraceIOMask("${PORT}", -1, 0x2)

# End of script
