The DrvModbus driver is used to communicate via Modbus TCP, RTU and ASCII.
For more information about the Modbus protocol read for example https://en.wikipedia.org/wiki/Modbus
DrvModbus uses a modbus master from proconX.
Information:
This document is used in conjunction with Chapter "IO-devices" of the Web Port manual.
To use DrvModbus, an IO device is first created and then used to communicate with the connected device. Tags are then used to define which Modbus registers are to be read from and written to (see chapter Tags).
The driver does not have its own settings, these are set uniquely for each IO device created.
Installation
The installation of DrvModbus is done by selecting DrvModbus when installing the Web Port. See "Installation" for more information on the installation process.
IO-device
To use DrvModbus, an IO device is created according to chapter "IO-devices" of the manual.
In addition to general settings (see "general settings" in IO-devices), the following settings are available for an IO device of type DrvModbus:
-
Poll delay [ms]:
- Delay in milliseconds from response to next read from device. Used to limit how often queries are made to a modbus device. This can be useful for slow devices.
-
Retry count:
- How many immediate retries are made in case of a failed read.
-
Read timeout:
- The maximum time a read may take in seconds.
-
Byte Order:
- Specifies how multi-register integer values are read, i.e. which register is most significant when reading across two registers. The setting offers two options: Big Endian Ints and Mid-Little Endian Ints. For example, for a tag with address
40001and data typeLONG, Big Endian Ints will treat register40001as the most significant (containing values > 65535) and40002as the least significant, while Mid-Little Endian Ints will treat40001as the least significant and40002as the most significant. If you get values in the wrong order of magnitude on data types such asLONGorULONG, this setting may need to be adjusted.
- Specifies how multi-register integer values are read, i.e. which register is most significant when reading across two registers. The setting offers two options: Big Endian Ints and Mid-Little Endian Ints. For example, for a tag with address
-
Swapped Floats:
- Specifies whether alternate bit ordering is used for floating point numbers (data type REAL).
-
Slave address:
- Slave address of the unit. Can be left blank and instead specified on tag address, see infobox under Tags.
-
Modbus type:
- Specifies the type of modbus to be used: TCP, Encapsulated RTU, RTU (Serial), ASCII.
-
Init address:
- Enter any working modbus address to do extended communication check on connection.
-
Use KeepAlive:
- Performs read from initiation address every second. Use only in case of problems.
-
Write HR with FC16:
- Writes to holding registers with FC16 (write multiple registers) by default.
-
(TCP) Device address:
- IP address of modbus device or modbus gateway. If there is a name lookup on the network, the device name can also be used. Used only with TCP and Encapsulated RTU.
-
(TCP) Port:
- Port for communication. For Modbus TCP, port 502 is usually used. Used only with TCP and Encapsulated RTU. NOTE! Port cannot be higher than 32767!
-
(RTU) COM port:
- COM port on the computer for serial communication.
-
(RTU) Baud rate:
- Serial communication speed.
-
(RTU) Parity:
- Parity for serial communication.
-
(RTU) Data bits:
- Number of data bits for serial communication.
-
(RTU) Stop bits:
- Number of stop bits for serial communication.
-
Link to:
- Used to link several IO devices of DrvModbus type. This is used when multiple Modbus serial devices are on the same loop. Communication settings are then set for the first device on the loop while the others are linked to it. Please note that the Slave address must be specified for all devices.
Tags
In order to read and write Modbus registers via an IO device, tags must be created and associated with it.
For more information on how to create tag lists and tags, see chapter "Tags" of the manual.
Tip!
Create a tag list for each IO device. This is to get a good structure and to easily find tags in the lists.
Tags attached to a DrvModbus IO device can have the following data types:
| Data type: | Description: |
| DIGITAL | Used for Discrete Input and Output(Coils) |
| (U)INT | Used for 16-bit integer, Input and Output (Holding) registers |
| (U)LONG | Used for 32-bit integer, Input and Output (Holding) registers. Read from two sequential registers |
| (U)INT64 | Used for 64-bit integer, Input and Output (Holding) registers. Read from four sequential registers |
| REAL | Used for 32-bit floating point, Input and Output (Holding) registers |
Information:
The address field specifies the modbus address to be read/written.
Addresses can be entered both with full register location and with function code.
When function code is used, the address is given in the form function_code:address.
Example:
| Register type: | With function code: | Full register |
| Discrete outputs (Coils) | 1:1 - 1:65536 | 00001 - 065536 |
| Discrete Inputs | 2:1 - 2:65536 | 10001 - 165536 |
| Input registers | 4:1 – 4:65536 | 30001 - 365536 |
| Output (Holding) registers | 3:1 - 3:65536 | 40001 – 465536 |
Tip!
To invert a tag or make a comparison, the address can be terminated with a Boolean expression.
The data type remains the same but the tag value becomes 1 or 0 depending on whether the expression is satisfied or not.
Example:
| 40001=0 | Returns 1 when register 40001 = 0. |
For more information see chapter "Tag naming convention" in the manual.
Tip!
To mask out individual bits from a register, the following syntax can be used at the address: Address.bit-index. The index is chosen between 0-15 where 0 is the least significant. The data type selected is INT.
Example:
| 40001.0 | Returns the least significant bit (rightmost) |
Information
To specify slave addresses directly on the tag addresses, use the format slaveaddress@register, e.g. 1@40001.
Import of tags
It is possible to import tags from uploaded files of any type (e.g. .csv), as well as the possibility to
process these with scripts (or directly download a file via e.g. FTP), which can also be combined with a
import filter.
This is handled from a tag list and Import Tags.
| File to import | Select or upload a new file to import. Can e.g. be a .csv or .xml file. Loading and processing of this then takes place in the import script |
| Import script | Select or upload a new script |
Example of code:
//Load an xml filevar doc = new System.Xml.XmlDocument();doc.LoadXml(importfile);//Create and import tagvar tag = new Moldeo.WebPortCommon.Tag(“NEWTAG_PV”); tag.SetParameter("datatype", "INT");tag.SetParameter("description", "Active day");tag.SetParameter("address", "3:12");tags.Add(tag);
Additional script parameters are specified in the format paramname=value,paramname2=value2
Importfilter
Another possibility to import tags into Web Port is using the import file
DrvModbusImportFilterExample.csv. This comes with the installation of DrvMODBUS and is located below
the WebPort data directory /assets/import/DrvMODBUS/.
The file has the following columns:
| Column: | Description: |
| startwidth | Filters symbol names that starts with xxx |
| contains | Filters symbol names that contains xxx |
| endswith | Filters symbol names like ends with xxx |
| find | Searches for this expression in the symbol name and replaces it |
| replace | Replaces the match from find with this value |
| rawmin | Optional scaling value (rawmin) for tag |
| rawmax | Optional scaling value (rawmax) for tag |
| engmin | Any scaling value or limit (engmin) for tag |
| engmax | Any scaling value or limit (engmax) for tag |
| unit | Any device for the tag |
| format | Any formatting for the tag |
| description | Description of the tag |
| alarmoption | Any alarm settings for the tag |
| trendoption | Any trend settings for the tag |
Information
DrvMODBUSImportFIlter.csv contains a number of lines to show how it can be used. To be
useful, however, it should be extended and adapted to the library and notation standard that
used when programming the control system.
To perform an import, go to System settings/Tags and open the tag list where the tags should be
are imported. Click the Import Tags tool button. In the dialog that opens, select the IO device that
tags should be imported from, and enter the Prefix that the tags should get in Web Port. Click the button
import in the dialog box to start the import. If Update existing is selected, Web Port will appear
update existing tags affected by the import. When the import has completed, a
information box appears showing how many tags have been imported.
NOTE!
The import skips tags that are already in Web Port. This applies even if the tags are in other tag lists, as Web Port checks the tag name generated during import
NOTE!
DrvModbus supports Big Endian and Mid Little Endian byte order. When communicating with Modbus registers, this affects how data is interpreted and displayed. For example, a 32-bit LONG is stored across two registers (e.g., 30001 and 30002), where each register consists of two bytes. Depending on the selected byte order, the arrangement of these bytes differs:
- Big Endian: ab-cd
- Mid Little Endian: cd-ab
It is important to select the correct byte order to ensure proper data handling and avoid misinterpretations in the system
Web Port Modbus Integration
More info and help on connecting a Modbus device to Web Port:
Web Port Modbus Integration