TRIUMF Device and Driver Support for Modbus/TCP Protocol under EPICS


Rolf Keitel,   updated 2005-08-24

Version 2.21 24-Aug-2005
bug-fix in mbbodirectRecord initialization
Version 2.2   09-Dec-2004
improve error checking on connect time-out
Version 2.11 31-Mar-2004
default reconnect behaviour changed to "reconnect"
Version 2.1  08-Feb-2004 reconnect behaviour is now configurable
keep-alive function for Momentum series PLCs
Version 2.0 15-Dec-2003 added support for bipolar ADCs and DACs

In case of discrepancies between this documentation and documentation in the source code, the source code is (probably) more correct.

Download from here

Table of Contents

Functionality
Interface Functions
Connection Failures
TRIUMF's way to avoid stale PLC data
Limitations and Known Problems
NSLS port to support WAGO PLCs on Linux
Combined Linix/VxWorks version with support for Modicon, Wago, and Siemens S5 Fetch/write (Beta - use at your own risk)



The TRIUMF modtcp driver allows reading of data from Modicon PLCs and writing of data to Modicon PLCs over Ethernet. It uses the Modbus/TCP protocol.
This device/driver support is used in the ISAC control system with Quantum and Momentum series PLCs.

Functionality:


top





Interface Functions:

The following commands are implemented for use in IOC startup scripts and from the IOC consolse (you'll find probably a few more in the source code). The example of an IOC startup script shows the typical use of these functions. Please note in this example, that the polling of the PLC is slowed down by setting the global variable moddelay to 20

modtcpDrvCreate

Defines a new PLC. The first call to this function creates PLC 0, the next PLC 1, ...


Parameters: type
1
PLC name
string
2
TCP/IP port
integer
3
PLC IP address
string
4
length of  memory buffer
integer
   
Example:   
modtcpDrvCreate("itwplc",502,"142.90.132.94",4096)


modtcpDrvReadGroup

Defines a "read group",  i.e. a contiguous set of registers to be read from the PLC.


Parameters: type
1
PLC name
string
2
start of read group in PLC (1 <==> 400001)
integer
3
length of read group (must be <= 125) integer
4
offset into memory buffer for storage
integer
5
read-only-once flag (0 = read continuously)
integer
   
Example:   
modtcpDrvReadGroup("itwplc",1001,23,1001,0)

modtcpDrvWriteGroup

Defines a "write group",  i.e. a contiguous area of the memory buffer, which is monitored for changes. Changed values are written to the PLC.


Parameters: type
1
PLC name
string
2
start of write group in PLC (1 <==> 400001)
integer
3
length of write group (must be <= 125) integer
4
offset into memory buffer (start of data to write)
integer
   
Example:   
modtcpDrvWriteGroup("itwplc",2001,23,2001)

modtcpWatchdog

Specifies a watchdog location in the PLC, where the value is changing with each PLC scan.


Parameters: type
1
PLC name
string
2
watchdog address (1 <==> 400001)
integer
   
Example:   
modtcpWatchdog("itwplc",3001)

modtcpKeepAlive

Specifies a location in the PLC, to which the driver writes a changed value every 5 seconds.
For some PLCs (e.g.  Momentum series PLCs), this call needs to be added to the IOC startup script.
Otherwise the TCP/IP server in the PLC closes write connections after a short period of inactivity.


Parameters: type
1
PLC name
string
2
"keep alive" address (1 <==> 400001)
integer
   
Example:   
modtcpKeepAlive("itwplc",101)


modtcpInit

Initializes communication with all PLCs
   
Example:   
modtcpInit

modtcpAbort

Aborts communication with all PLCs
   
Example:   
modtcpAbort


modtcpReport

Reports information about all PLCs on the system. If an optional parameter > 0 is given, the reported information is more detailed
   
Example:   
modtcpReport 1



modtcpSetAutoReconnect

Enables/disables the auto-reconnect function of the driver. Default is set by #define DEFAULT_RECONNECT in file drvModtcp.c.
NOTE: this function has no effect, if there is no watchdog specified.


Parameters: type
1
PLC name string
2
1 (= yes)  or 0 (= no)
integer
   
Example:   
modtcpSetAutoReconnect("itwplc",1);
top



Connection Failures

Behaviour of the driver if the Ethernet is interrupted:
  1. if no watchdog task is specified in startup script:
    In this case read and write tasks block on their TCP/IP recv functions.
    Use commands from the IOC consoles:
    "modtcpAbort"    (or "modtcpAbortPLC(<PLC index>)", if the IOC drives more than one PLC)   to abort the read and write tasks
    "modtcpInit"   (or "modtcpInitPLC(<PLC index>)", to restart the  read and write tasks
  1. if watchdog task is specified in startup script:
    In this case, the read and write tasks are aborted, when there is no communication for X 5-second intervals. X is configurable  (see Console Interface).

    The reconnect behaviour is determined by the directive
    #define DEFAULT_RECONNECT in the source file drvModtcp.c.
    This compile-time value can be overridden by a call to  modtcpSetAutoReconnect(1) in the IOC startup script. A value of 1 causes the driver to attempt reconnecting  every 20 seconds.
top 



Limitations and Known Problems:

Note, however, that EPICS device support supports binary input and output records.

Known problems:
    - none, until you tell me


top