ModbusIP Slave TLM
  SoftPLC    Font size:      

Usage

Concepts

The SoftPLC runtime software supports TLMs, which are shared library extensions to SoftPLC. A TLM may be loaded either as a DRIVER or as a MODULE. The difference between a DRIVER and a MODULE is that a DRIVER is called once per SoftPLC scan, and optionally an additional number of times per scan. A MODULE is only called when the control program decides to call it. TLMs are made known to SoftPLC in the MODULES.LST file which may be edited by TOPDOC NexGen by traversing to: PLC | Modules.

Features

In order to use the modbus IP slave TLM you need a working ethernet connection. This TLM listens on the standard TCP and UDP port 502 and acts as a "slave" or a "server". On the other end of any Modbus conversation is a "master" or a "client". Because the slave implemented by this TLM supports both TCP and UDP carriers for the Modbus protocol, the master may choose which it will use. More than one master may talk to this slave at once, and each master may chose independently to do this on either TCP or UDP, or both.

When TCP is used by the master, there is a TCP connection established. When UDP is used by the master, the request response sequence takes place in a "connection-less" fashion. Because UDP is not a guaranteed delivery service, any Modbus master using UDP instead of TCP to carry the modbus requests and responses should implement timeout and retry logic. On most hardware platforms, SoftPLC will respond to a request within a millisecond or two, and knowledge of this can be used to pick reasonable timeouts for the required UDP logic.

This slave TLM supports 32 simultaneous Modbus/TCP connections and an unlimited number of Modbus/UDP sessions. SoftPLC 4.x's integrated firewall may be used to restrict which network nodes can communicate to this TLM.

SoftPLC also provides a Modbus IP Master TLM, which is documented here. A single SoftPLC machine can be both a master and a slave. This capability gives the systems designer the power and flexibility to develop very powerful, fast and flexible distributed control systems. Obviously a SoftPLC Modbus master can talk to a SoftPLC Modbus slave as well as third party slaves.

Typical System Architecture

distributed control

Supported Modbus Commands

Modbus FunctionNameSupported
1Read CoilsYes
2Read Input DiscretesYes
3Read Multiple RegistersYes
4Read Input RegistersYes
5Write CoilYes
6Write Single RegisterYes
7Read Exception StatusNo
15Force Multiple CoilsYes
16Write Multiple RegistersYes
20Read General ReferencesNo
21Write General RegistersNo
22Mask Write RegisterYes
23Read Write RegistersYes
24Read FIFO QueueNo

Requirements

  • A working ethernet or PPP link.
  • Version 4.x SoftPLC or later.

Installation

The TLM is named mbipslav.tlm.so and is found as part of the standard SoftPLC 4.x installation in the /SoftPLC/tlm directory. To use it you merely have to enable it in NexGen's PLC | MODULES editor. Then you must edit the text file MBIPSLAV.LST which is the TLM's configuration file.

It is easy to edit the configuration file from the PLC | MODULES editor as well. Simply click on the "Configure" button after selecting and enabling the Modbus IP Slave TLM there.

Configuration

Modbus commands were originally designed for a Modicon PLC. Therefore they assume 4 different types of memory regions:

  1. Input States (boolean inputs)
  2. Input Registers (16 bit words)
  3. Output Coils (boolean outputs)
  4. Output Registers (16 bit words)

In order to make use of the Modbus commands, we must map the 4 required memory regions to datatable files within SoftPLC.

Modbus TCP protocol includes the original "slave id" field which was part of the modbus on serial line protocol. In the case of communications on ethernet, either via TCP or UDP, this field is no longer used to qualify the actual network node that will respond to a request. The reason for this is because the IP Address in the ethernet frame serves this purpose. Therefore the "slave id" field becomes available for another use. This TLM can be configured to use the slave id field as a "selector" in the mapping of the four Modbus memory regions to SoftPLC datatable files.

All the configuration is done in the single text file MPIPSLAV.LST. Below is a sample. Any part of a line of text to the right of a semicolon ; is considered a comment and is ignored.

Sample Configuration File

; This is the configuration file for the MODBUS IP Slave TLM.
; Anything after a semicolon is ignored during parsing.
; There are two sections: [DRIVER] and [SLAVES]:

; [DRIVER] contains global options, such as DEBUG and IOCHECK
;
; Set DEBUG to > 0 if you want diagnostic output temporarily.
;  DEBUG=0 gives no diagnostic output.
;  DEBUG=1 gives a nice Query Response trace.  
;  DEBUG=2 gives what 1 does and more.
;
; Set IOCHECK to YES if you want the turn around time to be reduced
;  by having SoftPLC service the modbus commands more frequently than
;  once per scan. This is effective only when you have more rungs 
;  than STARTUP.LST's oneCheckInterval setting.

[DRIVER]
DEBUG=2
IOCHECK=NO


; [SLAVES] should include one line for each group of files you want to 
; expose. Each SLAVE is a fictitious internal Modicon device that is 
; addressed by including the corresponding "Slave ID" in the modbus 
; request packet.
;
; Each SLAVE line can provide access to up to 4 datatable files, one 
; for each of these purposes:
;
; 1) Holding Registers, 
; 2) Output Coils, 
; 3) Input Registers, 
; 4) Input States.
; Any or all of the 4 files can be the same as each other, for each 
; SLAVE. The given files must start at element 0 and be of type
; INTEGER, BIT, INPUT, OUTPUT, or STATUS.
; 
; A SLAVE with a SlaveID of -1 is special.  It will be used when the 
; incoming request packets do not match any other SlaveID.  In many cases,
; you will only need a single SLAVE row and will want to use -1 as the 
; SlaveID.

[SLAVES]
;SlaveID 0-255
;|  Holding Registers StartAddress:
;|  |        Output Coils StartAddress
;|  |        |        Input Registers StartAddress
;|  |        |        |         Input States StartAddress
;|  |        |        |         |
-1, N12:0,   N12:0,   N12:0,    N12:0

;0, N100:0,  N101:0,  N102:0,   N103:0
;2, N100:0,  B3:0,    N7:0,     I:0    edit/copy, uncomment as needed

; Make sure you use TOPDOC to create the Datatable Files that you are 
; referencing for each slave.

; Make sure you install this TLM as a DRIVER and not a MODULE.

; FIREWALL:
; If you want to restrict which network nodes can access this
; SoftPLC's MODBUS IP SLAVE functionality, then you should setup 
; the internal Gatecraft Firewall with support from SoftPLC Corp.

;EOF
Note
You may supply a single SLAVE row that has a -1 as the SlaveID. A SlaveID of -1 is special. This row, if supplied, is the default when the incoming SlaveID does not match any other row.

After using NexGen to edit the configuration file, Send it down to the SoftPLC. The next step is to cycle power on the SoftPLC for the changes to take place. As an alternative to cycling power, you may enter "Remote Program" mode using NexGen, then select "Remote Program" a second time. This psuedo transition from Remote Program to Remote Program is a signal to the TLM that it should reload its configuration file. This way you can reconfigure without cycling power, although it does require you enter "Remote Program" mode (twice!).