# template record for reading a single 16 bit value from an ADAM4572
#
# Macros:
# P - Record prefix
# R - Record name
# PORT - asyn modbus support port name
# B - Bit number (offset from 0)
#
record(longin,$(P)$(R)){
field( SCAN, ".5 second")
field( DTYP, "asynInt32" )
field( INP, "@asyn($(PORT) $(B))UINT16" )
}
########################### ADAM config ###########################
# IP address 10.10.10.10 is a static (reserved) IP address linked to the MAC of the ADAM4572;
# 502 is Modbus TCP/IP port
drvAsynIPPortConfigure("ADAM4572_PORT", "10.10.10.10:502", 0, 0, 1)
#modbusInterposeConfig(const char *portName, modbusLinkType, int timeoutMsec, int writeDelayMsec)
modbusInterposeConfig("ADAM4572_PORT", 0, 2000, 0)
# Read the 8 channels of an ADAM4019+ module at slave address 1 via ADAM4572 MODBUS ethernet gateway
# There are 8 holding registers that correspond to the 8 channels (0-8), starting at modbus address=40001.
# EPICS seems to use offset addresses, so 40001 = 0, 04002 = 1, etc.
# Data type is UINT (dataType=0). Signal is 4-20 mA.
#drvModbusAsynConfigure(char *portName, char *octetPortName, int slaveAddress, int modbusFunction,
# int modbusStartAddress, int modbusLength, modbusDataType dataType,
# int pollMsec, char *plcType)
drvModbusAsynConfigure("ADAM4572_CHANNELS", "ADAM4572_PORT", 1, 3, 0, 8, 0, 1000, "ADAM")
# Read 8 holding registers from 40200. These correspond to the input types of the 8 channels.
drvModbusAsynConfigure("ADAM4572_INPUT_TYPES", "ADAM4572_PORT", 1, 3, 200, 8, 0, 1000, "ADAM")
# Use the template to publish bits as channel access variables
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_CHANNELS,R=ch1,B=0") #Voltage
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_CHANNELS,R=ch2,B=1") #Current
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_CHANNELS,R=ch3,B=2") #Upper diff ram
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_CHANNELS,R=ch4,B=3") #Lower diff ram
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_CHANNELS,R=ch5,B=4") #Main ram advance
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_CHANNELS,R=ch6,B=5") #Main ram retract
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_CHANNELS,R=ch7,B=6") #unused
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_CHANNELS,R=ch8,B=7") #unused
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_INPUT_TYPES,R=ch1_type,B=0")
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_INPUT_TYPES,R=ch2_type,B=1")
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_INPUT_TYPES,R=ch3_type,B=2")
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_INPUT_TYPES,R=ch4_type,B=3")
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_INPUT_TYPES,R=ch5_type,B=4")
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_INPUT_TYPES,R=ch6_type,B=5")
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_INPUT_TYPES,R=ch7_type,B=6")
dbLoadRecords("./adam4572.template", "P=adam:,PORT=ADAM4572_INPUT_TYPES,R=ch8_type,B=7")