Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

OpModbus

Block

Mask

Description

The OpModbus block allows users to define the (TCP and RTU) Modbus slave parameters that instantiate a simulated slave device. This device can be accessed through a Modbus-TCP/RTU master.

One OpModbus block has to be present for each simulated slave device. It allows exchanging data with any industrial devices through Modbus Ethernet or serial messaging. Using a standard network interface card or the standard serial port, this interface can be easily and rapidly added to any simulation model. The complete Modbus communication stack is handled by a dedicated thread running in parallel with the simulation model. The process data is exchanged with the simulation model through a shared memory where inputs/outputs are automatically mapped. The communication stack does not add then any significant or non-deterministic delay to the simulation.

Parameters

Configuration fileName of the configuration file (opal file, .csv file or .xls file in Excel 97-2003 format)
Sample timeSpecifies the sample time of the Simulink block (must be a multiple of the model sample time). Note that this is different from the internal slave cycle. This parameter specifies the execution rate of this block.


Inputs

BitsThis input will accept a vector of status that will be transferred to the simulated Modbus slave database at the rate defined in the mask. The vector order must respect the configuration file order. The status addresses are specified in the configuration file (incoming_bits section).
Input bitsThis input will accept a vector of input status that will be transferred to the simulated Modbus slave database at the rate defined in the mask. The vector order must respect the configuration file order. The input status addresses are specified in the configuration file (incoming_input_bits section).
RegistersThis input will accept a vector of registers that will be transferred to the simulated Modbus slave database at the rate defined in the mask. The vector order must respect the configuration file order. The register addresses are specified in the configuration file (incoming_registers section).
Input registersThis input will accept a vector of input registers that will be transferred to the simulated Modbus slave database at the rate defined in the mask. The vector order must respect the configuration file order. The input register addresses are specified in the configuration file (incoming_input_registers section).
NBRemoving the sections incoming_bits, incoming_input_bits, incoming_registers, incoming_input_registers from the configuration file will remove the associated inports of the block.


Outputs

BitsThis output is a vector of status that is transferred from the simulated Modbus slave database at the rate defined in the mask. The vector order respects the configuration file order. The status addresses are specified in the configuration file (outgoing_bits section).
Input bitsThis output is a vector of input status that is transferred from the simulated Modbus slave database at the rate defined in the mask. The vector order respects the configuration file order. The input status addresses are specified in the configuration file (outgoing_input_bits section).
RegistersThis output is a vector of registers that is transferred from the simulated Modbus slave database at the rate defined in the mask. The vector order respects the configuration file order. The register addresses are specified in the configuration file (outgoing_registers section).
Input registersThis output is a vector of input registers that is transferred from the simulated Modbus slave database at the rate defined in the mask. The vector order respects the configuration file order. The input register addresses are specified in the configuration file (outgoing_input_registers section).
NBRemoving the sections outgoing_bits, outgoing_input_bits, outgoing_registers, outgoing_input_registers from the configuration file will remove the associated outports of the block.


Configuration File

The configuration file can be either in the internal "opal" format (extension .opal) or in 'Comma Separated Value' (.csv) format or a .xls file in Excel 97-2003 format. Hereafter is a definition of the different configuration parameters.

ParameterDescription
nameSelected by the user, it identifies the device instance.
proto_nameProtocol name (TCP,RTU).
cpuSpecifies on which cpu core this device will run.
verboseProvides extra information on RT-LAB Display console.
nb_bitsNumber of status in the slave internal database.
nb_input_bitsNumber of input status in the slave internal database.
nb_registersNumber of registers in the slave internal database.
nb_input_registersNumber of input registers in the slave internal database.
pinoutsimulink block interface definition (inports/outports).
incoming_bitsAdds an inport to the block. The size of the input vector depends on the number of items in this section. Each item defines the address of the associated status.
incoming_input_bitsAdds an inport to the block. The size of the input vector depends on the number of items in this section. Each item defines the address of the associated input status.
incoming_registersAdds an inport to the block. The size of the input vector depends on the number of items in this section. Each item defines the address of the associated register.
incoming_input_registersAdds an inport to the block. The size of the input vector depends on the number of items in this section. Each item defines the address of the associated input register.
outgoing_bitsAdds an outport to the block. The size of the output vector depends on the number of items in this section. Each item defines the address of the associated status.
outgoing_input_bitsAdds an outport to the block. The size of the output vector depends on the number of items in this section. Each item defines the address of the associated input status.
outgoing_registersAdds an outport to the block. The size of the output vector depends on the number of items in this section. Each item defines the address of the associated register.
outgoing_input_registersAdds an outport to the block. The size of the output vector depends on the number of items in this section. Each item defines the address of the associated input register.
tasksThis section defines the slave cycle time.
deadlineSlave device cycle time. This parameter sets the period of the slave for processing incoming requests from the master.
TCP Specific ParametersDescription
ipSpecifies the slave's IP address.
networkInterfaceSpecifies the network interface to be used. (eth0 by default)
portThis section defines the network port on which the slave listens.
RTU Specific ParametersDescription
baudDefines the baud rate. (All valid baud rates are available)
parityDefines the parity configuration. (O=odd,E=even,N=none)
data_bitsDefines the serial data bits configuration. (8, 7)
stop_bitsDefines the stop bits configuration. (1, 1.5, 2).
device_rtuDefines the communication port to be used. (/dev/xxx...)
slave_idDefines the slave ID required for RTU communication.

Here is an example of the content of a '.opal' configuration file.

To simplify the usage, the configuration file can be in '.xls' format. The name of the file (including the .csv extension) must be specified in the 'Configuration file' field of the Matlab/Simulink block. Here is an example of what the .csv file must contain. This file can be found in the Modbus slave example model folder. The file template is the same if the user prefers to use a .xls configuration file in Excel 97-2003 format.

The left column items must match with the example file. Any kind of delimiters can be used between the addresses.

File Transfer

The configuration file will be automatically transferred to the target before loading the model.

Characteristics and Limitations

Protocols: Modbus TCP/RTU Slave

Supported Modbus functions:

  • Modbus function code 0x01 (read coil status)
  • Modbus function code 0x02 (read input status)
  • Modbus function code 0x03 (read holding registers)
  • Modbus function code 0x04 (read input registers)
  • Modbus function code 0x05 (force single coil)
  • Modbus function code 0x06 (preset single register)
  • Modbus function code 0x0F (force multiple coils)
  • Modbus function code 0x10 (preset multiple registers)
  • Maximum queries per second: 100

Mapping:

  • Unlimited number of coils (only limited by hardware)
  • Unlimited number of registers (only limited by hardware)
  • Unlimited number of input coils (only limited by hardware)
  • Unlimited number of input registers (only limited by hardware)

Maximum of 100 slaves in a single model

Support RT-LAB extra-high performance simulation mode (XHP)

Support multi-rate modeling

1 Matlab/Simulink block per slave

All configuration parameters are tunable without re-compilation except the Matlab/Simulink inport and outport dimensions. When a modification to the configuration file does not affect the number of input/outputs of the Matlab/Simulink block, the user only has to update the model diagram for the modification to be effective during the next model load.

Additional limitations are shown in the table below:

Direct FeedthroughNo
Discrete sample timeYes
XHP supportYes
Work offlineNo

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323