#==============================================================
#
#  Abs:  Initialize Pilz ModBus Asyn communications
#
#  Name: init_pilz.cmd
#
#  Facility:  EED Personnel Protection System (PPS)
#
#  Auth: 10-Jul-2020, Kristi Luchini  (LUCHINI)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        dd-mmm-yyyy, First Lastname   (USERNAME):
#          comment
#
#==============================================================
#
# PILZ PLC ASYN Port Configuration 
# Use the following commands for TCP/IP
#drvAsynIPPortConfigure(const char *portName,
#                       const char *hostInfo,
#                       unsigned int priority,
#                       int noAutoConnect,
#                       int noProcessEos);
drvAsynIPPortConfigure ("${PLC_PORT}", "$(PLC_IP):502" ,0,0,0)
asynSetOption("${PLC_PORT}",0,"disconnectOnReadTimeout", "Y")

# Initialize Pliz PLC MODBUS Interpose Layer
modbusInterposeConfig ("${PLC_PORT}", 0, 100, 0)

#drvModbusAsynConfigure(portName,
#                       tcpPortName,
#                       modbusFunction,
#                       modbusStartAddress,
#                       modbusLength,
#                       dataType,
#                       pollMsec,
#                       plcType);
#
# portName: Name of the modbus port to be created.
# tcpPortName: Name of the asyn IP or serial port previously created.
# modbusFunction: Modbus function code (1, 2, 3, 4, 5, 6, 15, or 16).
# modbusStartAddress: Start address for the Modbus data segment to be accessed.
#                     (0-65535 decimal, 0-0177777 octal).
# modbusLength: The length of the Modbus data segment to be accessed.
#               This is specified in bits for Modbus functions 1, 2, 5 and 15.
#               It is specified in 16-bit words for Modbus functions 3, 4, 6 and 16.
#               Length limit is 2000 for functions 1 and 2, 1968 for functions 5 and 15,
#               125 for functions 3 and 4, and 123 for functions 6 and 16.
# modbusDataType: Modbus data type:
#Supported Modbus data types
#modbusDataType value    drvUser field   Description
#                0       UINT16          Unsigned 16-bit binary integers
#                1       INT16SM         16-bit binary integers, sign and magnitude format.
#                2       BCD_UNSIGNED    Binary coded decimal (BCD), unsigned.
#                3       BCD_SIGNED      4-digit binary coded decimal (BCD), signed.
#                4       INT16           16-bit signed (2's complement) integers.
#                5       INT32_LE        32-bit integers, little endian
#                6       INT32_BE        32-bit integers, big endian
#                7       FLOAT32_LE      32-bit floating point, little endian
#                8       FLOAT32_BE      32-bit floating point, big endian
#                9       FLOAT64_LE      64-bit floating point, little endian
#                10      FLOAT64_BE
# pollMsec: Polling delay time in msec for the polling thread for read functions.
#           For write functions, a non-zero value means that the Modbus data should
#           be read once when the port driver is first created.
#  plcType: Type of PLC (e.g. Koyo, Modicon, etc.).
#           This parameter is currently used only to print information in asynReport.
#           In the future it could be used to modify the driver behavior for a specific PLC.
#drvModbusAsynConfigure(portName, tcpPortName, slaveAddress, modbusFunction, modbusStartAddress, 
#                       modbusLength, dataType, pollMsec, plcType);
# PILZ PLC MODBUS ASYN Configuration
drvModbusAsynConfigure("PLC_RD"       , "${PLC_PORT}", 1, 1, 0    , 160, 0, 500, "PILZ")
drvModbusAsynConfigure("PLC_CHECKSUM"", "${PLC_PORT}", 3, 1, 0    , 10,  0, 500, "PILZ")
drvModbusAsynConfigure("PLC_WT"       , "${PLC_PORT}", 5, 1, 16384, 48,  0, 500, "PILZ")

# End of script

