VISUAL BASIC APP CODE FOR INDUSTRIAL LIQUID
TEMPERATURE CONTROL WITH EZ-ZONE® RAIL MOUNT
CONTROL MODULE (RMC) USING MODBUS
List of figures
Fig. 1. Modbus frame over Serial Line [7] ............................................................................................... 8
Fig. 2 Modbus RTU message frame [7] ................................................................................................... 8
Fig. 3 System diagram ........................................................................................................................... 12
Fig. 4 Modbus RTU Master.................................................................................................................... 13
2
1. Introduction
1.1 Overview
Temperature controllers are widely used in industrial environments to perform different
types of control approaches like on-off, PID, etc. Nowadays such industrial devices are
connected to PC systems to perform monitoring and control over networks. To fulfill this task
there are many possibilities regarding networks, communication protocols, devices,
interfaces, etc. For example, it is possible to monitor and control an industrial device remotely
from an application software running on a PC over a network and this is the topic covered in
this Scientific Project: "Industrial liquid temperature control".
1.2 Problem
How is it possible to use the RMC Control module using Modbus communication protocol
through the Com-Server?
1.3 Main objective
Develop a software application in Visual Basic running on a PC to monitor and control thermal
processes via the EZ-ZONE® Rail Mount Control module (RMC) using Modbus as
communication protocol and making use of the Com-Server as interface.
1.4 Specific objectives
- To determine how Com-Server works
- To determine how RMC Control module works
- To determine Com-Server communication capabilities
- To determine RMC Control module communication capabilities
- To understand the Modbus protocol
- To understand serial communications
- To understand Ethernet networks
- To understand TCP/IP protocol
- To figure it out how to interconnect the two devices and a PC in a system
- To develop a PC control application interface in Visual Basic
1.5 Contribution
This project helps the user to speed up the learning curve of the system composed by PC,
Visual Basic application, RMC Control module and Com-Server. The goal is accomplished by
giving a specific review of the most important information about how the devices above
described work, how they can be interconnected, how is it possible to perform the remote
monitor and control of a thermal process, explaining how to use the software application with
a simple and intuitive user guide and also giving some background definitions to understand
the whole process.
3
2. Literature review and background
2.1 Com-Server
2.1.1 Introduction
The Com-Server 58633 is a useful device that is designed to link TCP/IP networks to serial
interfaces (e.g. RS232, RS422, RS485) in different ways, for example creating virtual COM
ports that act as if they were normal PC local ports, but instead they are placed on the Com-
Server in the network [1]. In this way it is possible to write programs that communicate serially
and to be able to perform communication through TCP/IP networks [1]. The Com-Server also
offers other communication protocol such as: UDP, TCP, FTP, etc. [1].
2.1.2 Network interface side
The Com-Server++ includes an Ethernet network interface (IEEE 802.3 – compatible) on a
shielded RJ45 connector, so in the project, it is connected to a Windows PC using TCP/IP
protocol with a max. 100m long patch cable (10/100BaseT). IP address assignment and
parameter configurations can be done using WuTility, the free software provided by W&T [1].
2.1.3 Serial interface side
The Com-Server is provided with RS232/422/485 combi-port that can be easily configured
depending on the individual needs [1]. According to [7], systems at the physical level, may use
different physical interfaces (RS485, RS232), although TIA/EIA-485 (RS485) two-Wire
interface is the most common. For this project, TIA/EIA-485 (RS485) two-Wire interface is
selected because the EZ ZONE RMC control module is provided with Modbus RTU
communication interface using this specific configuration.
2.2 RMC
The EZ-ZONE® Rail Mount Control module (RMC) is a device specially designed to perform
single loop, multi-loop, individual or distributed thermal control [2]. The RMC1Z1Z1Z1ZA1AA
Control module used in the project includes Modbus RTU communications capabilities to
allow the user configure and monitor the control over a network [2]. It also includes other
features like [2]:
- Integrated power controller output
- Current monitoring
- Advanced PID control algorithm
The controller can be seen as three separate blocks which are inputs, functions and outputs
[2]. It should be configured so that the information runs from inputs that deliver the
information (e.g. analog inputs, digital inputs) to functions that could set an alarm or perform
a PID control loop, then functions provide the processed information to outputs that perform
an action like turning on or off equipment, driving on a buzzer, etc. [2].
4
2.3 Serial communication
2.3.1 Introduction
In serial data transmission, bits are sent one after another using one transmission line [3].
This technology is widely used in a number of applications such as in industrial automation,
because of high data rates and cost convenience [3]. There are different interfaces for serial
transmission, e.g. RS232, RS422 and RS485. In this project EIA/TIA 485 serial interface is used
because the EZ ZONE RMC control module only provide this serial communication technology.
2.3.2 RS 485 interface
The RS485 is a serial interface that is used to communicate multiple PC’s and devices in point-
to point or multi-point field networks. An RS-485 network can connect as many as 256 devices
along a single pair of wires [4].
RS 485 is built in two different formats: as 2-wire half-duplex bus or 4-wire full-duplex
interface [3]. As half-duplex, the two-wire bus allows only one device to be transmitting at
any given time [3]. When several transmitters are connected in a network over a single line,
a protocol must guarantee the correct communication between the devices [3].
Some of the advantages of RS-485 are [4]:
- Low cost
- Networking capability (up to 256 nodes)
- Long transmission lines (cable as long as 1200 m.)
- High speed (bit rate as high as 10 Mbps.)
2.4 Ethernet
According to [5] Ethernet is a broadly term ‘used to describe both the logical topology that
uses CSMA/CD and the physical topologies on which CSMA/CD networks run’ (p. 44). As can
be seen, Ethernet is based on CSMA/CD or Carrier Sense Multiple Access/Collision Detection
which is a protocol that describes how computers are connected in a network, how they
communicate in this network segment and what it is done when two or more computers try
to transmit data at the same time (collision) [5]. The basic Ethernet topologies are described
in IEEE standard 802.3 [5].
From the physical topology point of view Ethernet refers to the physical medium like switches,
cables, network cards on which Ethernet networks run [5].
2.5 Network Protocols
Network protocols can be thought as groups of rules that define the way in which data is sent
and received over a physical network and the software that make possible to apply such rules
[5].
5
In order to make effective the transmission of data through a physical network, multiple
protocols work together [5]. The interaction amongst protocols can be explained using a
theoretical model called the OSI seven-layer model [5].
2.6 The OSI Model
The OSI seven-layer model is a theoretical model that shows how data should be transmitted
over a network, from the Application Layer (user interface) to the Physical Layer (cables and
network cards) [5].
- Layer 7 (Application)
- Layer 6 (Presentation)
- Layer 5 (Session)
- Layer 4 (Transport)
- Layer 3 (Network)
- Layer 2 (DataLink)
- Layer 1 (Physical)
2.7 TCP/IP Protocol
TCP/IP is a term used to describe a protocol suite on which the Internet runs [5]. The suite
includes: TCP, IP, ARP, and SMTP amongst others. Actually TCP and IP give the name to the
whole suite protocol because they are the foundation for TCP/IP [5]. Compared with the OSI
Layer model, TCP/IP protocol achieves the tasks using four layers [5].
2.7.1 TCP Protocol
Transmission Control Protocol, is the part of the TCP/IP protocol suite that guarantees the
transportation of packets to the specified destinations [5]. It corresponds to the Transport
OSI Layer 4 [5].
2.7.2 IP Protocol
Internet Protocol, is the part of the TCP/IP protocol that is in charge of addressing and routing
the packets [5]. It corresponds to the Network OSI Layer 3 [5].
2.8 Modbus Protocol
2.8.1 Modbus Application Protocol
According to [6], ‘MODBUS is an application layer messaging protocol, positioned at level 7 of
the OSI model, which provides client/server communication between devices connected on
different types of buses or networks’ (p.2).
It can be implemented using the following interfaces [6]:
- TCP/IP over Ethernet.
6
- Asynchronous serial transmission (wire: EIA/TIA-232-E, EIA-422, EIA/TIA-485-A; fiber,
radio, etc.)
- MODBUS PLUS
2.8.2 Modbus over Serial Line
According to [7] the Modbus standard ‘defines an application layer messaging protocol,
positioned at level 7 of the OSI model that provides client/server communications between
devices connected on different types of buses or networks. It standardizes also a specific
protocol on serial line to exchange MODBUS request between a master and one or several
slaves’ (p.4). On Modbus over serial line protocol the Master of the serial bus acts as client
and the Slaves nodes act as servers. This Master-Slave protocol fits at level 2 of the OSI model
[7].
A master-slave type system has the following characteristics [7]:
- One master node that perform requests to the connected "slave" nodes and process
responses
- Slave nodes usually transmit data only when requested by the master node
- Slave nodes do not communicate with other slaves
- The master node initiates one Modbus transaction at a given time
- The master node makes a request to the slave nodes in two modes:
o In unicast mode (to one specific slave and wait for response)
o In broadcast mode (to all slaves without waiting for a response)
Modbus over Serial Line systems can use different physical interfaces such us (RS485, RS232).
TIA/EIA-485 (RS485) Two-Wire interface is the most common permitting point to point and
multipoint systems [7], and is the one used in this project since EZ-ZONE RMC Controller is
provided with this interface.
2.8.3 Addressing rules
Modbus Addressing rules can be summarized as follows [7]:
- The Modbus addressing space consist of 256 different addresses
- The address 0 is reserved as the broadcast address
- All slave nodes must recognize the broadcast address
- The Modbus Master node has no specific address
- The slave nodes must have unique addresses on a Modbus serial bus between 1 and
247
- From 248 to 255 are reserved addresses
7
2.8.4 Frame description
The Modbus frame over serial line has the following characteristics [7]:
- The Modbus application protocol defines a Protocol Data Unit (PDU)
- Modbus serial line PDU makes use of Modbus PDU and adds an Address field and an
Error checking field
- On Modbus over serial line protocol, the Address field contains the slave address
- The master talks to a slave by introducing the slave address in the address field of the
message.
- The slave insert its own address in the Address field when replies to the master, in this
way the master knows which slave is responding.
- The function code indicates to the server the kind of action to execute.
- The function code can be followed by a data field that contains request and response
parameters.
- The Error checking is based on a "Redundancy Checking" calculation that is performed
on the message contents.
Fig. 1. Modbus frame over Serial Line [7]
2.8.5 RTU Transmission Mode
In Modbus serial line communication using the RTU (Remote Terminal Unit) transmission
mode, each 8–bit byte in a message contains two 4–bit hexadecimal characters. The 11-bits
frame for each byte in RTU mode is specified as follows [7]:
- 8–bit binary
- 1 start bit
- 8 data bits, least significant bit sent first
- 1 bit for parity completion
- 1 stop bit
- Even parity (default mode), odd parity and no parity may also be used
- If No Parity is implemented, an additional stop bit added to complete a full 11-bit
asynchronous frame
- Frame Checking Field performed by Cyclical Redundancy Checking (CRC)
- Maximum size of a MODBUS RTU frame is 256 bytes
Fig. 2 Modbus RTU message frame [7]
8
2.8.6 Error Checking Methods
Modbus Serial Line performs two different ways to check possible errors in the messages [7]:
- Even or odd parity checking should be applied to each character, counting the number
of 1 data bits and setting the parity bit to 0 or 1 depending on the selected parity, to
end with an even or odd number of 1 bits in the message
- Cyclical Redundancy Checking (CRC) method is used in RTU mode, to check for errors
in the entire message
Before sending the message the device perform parity checking if selected and also CRC, then
the receiving device checks the characters and the entire message during receipt [7].
2.8.7 Data Signaling Rates
According to Modbus Serial Line protocol, 19.2 kbps is the required default data signaling
rate, 9600 bps and 19.2 kbps are also required and other baud rates may optionally be
implemented: 1200, 2400, 4800 … 38400 bps, 56 Kbps, 115 Kbps [7].
9
3. Procedure
To achieve the goal, the following steps were followed during the process:
Revision of [1] to:
- understand how the device works
- configure the device
- connect the device to the PC over a network
- connect the device to other devices through a serial interface
Revision of [2] to:
- gain a better understanding on how the device works
- configure the device
- connect the device to other devices through a serial interface
- understand what are the Modbus registers included in the device
- use Modbus registers to configure, monitor and control the device
- connect simple analog sensor to test the application software developed
Revision of [3] and [4] to:
- learn how serial communications works
- identify the different types of serial interfaces
Revision of [3] and [4] about EIA/TIA 485 serial interface to:
- understand the different modes of EIA/TIA 485 serial interface
- connect two-wire EIA/TIA 485 serial interface
Revision of [5] to:
- discover what Ethernet is
- learn how Ethernet is based on CSMA/CD protocol
- learn how CSMA/CD works
- learn the differences between logical and physical topologies
Revision of [5] to:
- understand what network protocols are
- understand how they are related inside the OSI seven-layer model
Revision of [5] to:
- understand the seven layers
- understand how data flows from the application layer to the physical layer
- understand the utility of this theoretical model and also
- understand why it is not implemented in real applications
10
Revision of [5] to:
- understand that TCP/IP protocol is a protocol suite
- understand how it accomplishes the goal to transmit data over networks using only
four layers of the OSI model
- understand TCP protocol
- understand IP protocol
Revision of [6] and [7] to:
- understand Modbus application protocol
- understand the different communication possibilities that Modbus offers
- understand Modbus over serial line protocol
- understand the way transmitted data is organized in PDU (protocol data unit) units
- understand Modbus frame over serial line
- understand the Modbus master/slave state diagrams and how the transmission is
performed
- understand the different transmission modes
- understand how RTU transmission mode works
- understand the parity checking and CRC error checking methods
- Understand how the transmission is physically done
- understand what the different serial interfaces options are
- understand the two wire Modbus interface
Development of the application in Visual Basic:
- search an open source Modbus RTU library
- implement the simple read function
- test the read function
- implement the read continuously function
- test the read continuously function
- implement the write single register function
- test the write single register function
- implement the write float values in two contiguous registers
- test the write float values in two contiguous registers
- check for exceptions and runtime errors
- refine the code
- test the application
11
4. Understanding the system
The result of the project can be summarized in the following section.
Fig. 3 System diagram
12
4.1 Modbus RTU Master application
The Modbus RTU Master was developed in Visual Basic to run on a Windows PC. Modbus RTU
Master was developed in Visual Studio 2015, the integrated development environment (IDE)
from Microsoft using the programming language Visual Basic. This application was developed
using the libraries:
- "[Link] Version 1.12.0" and "[Link] Version [Link] " released by ICP
DAS Co., Ltd. and downloaded from:
[Link]
The Modbus RTU Master Application acts as the Master in a serial communication using
Modbus RTU over Serial Line protocol with devices (slaves) using also Modbus RTU protocol.
The Modbus RTU Master allows the user to swap the word order low/high or high/low for the
reading and writing options.
The application allows the user to:
- Configure parameters such as COM Port, Baud Rate, Data Bits, Parity and Stop Bits
- Write Data in a single register as unsigned integer (uint) number
- Write Data in two contiguous registers as floating point (float) number
- Read Data once
- Read Data continuously with the possibility to set the sampling time
- Capture any possible Exception Message to understand the probable causes
Fig. 4 Modbus RTU Master
13
4.2 Com-Server
The PC is connected to the Com-Server over an Ethernet network using a 10/100BaseT patch
cable because it includes an IEEE 802.3-compatible network interface on a shielded RJ45
connector [1]. The IP address is assigned to the Com-Server using a tool provided by W&T
called WuTility. Using WuTility it is also possible to configure all the Com-Server parameters
using either a Telnet client or a Web-browser both included in WuTility [1].
W&T includes another tool called COM Port Redirector which is used to create a virtual COM
port that act as if it were a normal PC local port, but instead it is placed on the Com-Server in
the network [1]. For this reason, it is possible to use the Modbus RTU Master which is a serial
communication application but at the same time, be able to communicate over an Ethernet
network using TCP/IP protocol [1].
The Com-Server incorporates RS232/422/485 serial interfaces, but for this project RS485
interface is used because RMC Control module includes only RS485 communication
capabilities when using Modbus RTU protocol [2]. The connection is done via 2-wire EIA/TIA
RS485 interface. To select the operation mode as RS485 2-wire automatic control mode, it is
needed to open the Com-Server and take out the circuit board from the housing and then set
the DIP switches accordingly [1].
Important note: for reference and more advanced configurations refer to [1].
4.3 RMC Control module
The RMC Control module includes Modbus using 2-wire EIA/TIA RS485 communication
capabilities [2].
All Modbus RMC Control module registers are [2]:
- 16-bit registers
- relative addresses
- 6 digit ranging from 400001 to 465535
The RMC Controller allows the user to read data, configure parameters and control the
process by reading and or modifying Modbus Registers that can be identified by their Modbus
Relative Addresses and are designed as [2]:
- RWES - Readable / Writable / EEPROM (saved) / User Set (saved)
- RWE - Readable / Writable / EEPROM (saved)
- RW - Readable / Writable
- W – Writable
- R – Readable
The data type of each Modbus register can be [2]:
- uint = unsigned 16-bit integer, eg. single register to select the type of sensor
14
- float = IEEE 754 32-bit floating point number, eg. temperature set point to activate an
alarm
For parameters listed as float only the low order register is displayed [2]. The low order word
contains the two low bytes of the 32-bit parameter and the high order word contains the two
high order bytes [2]. The Modbus protocol does not indicate which register should be
configured as high or low, for this reason the RMC (Control) Module can exchange the word
default order to high/low order [2].
Some Modbus Relative Address columns on Operation and Setup Page tables enclose a
bracket like this [offset 90], this means that the parameter being configured has many
instances, for example the parameter Analog Inputs located in the Modbus Relative Address
360 has 4 instances [2]. The Modbus register presented in the table represent the first
instance [2]. To reach the other instances, add the specified offset multiplied by the number
of the instance that is being to be used [2].
Important note: for reference and more advanced configurations refer to [2].
4.4 User’s guide
The guide is a step by step, logically organized guide to introduce any new user to the use and
configuration of the system composed by Visual Basic application running on a PC, Com-
Server and RMC Control module with the following topics:
- Assign the IP address to the Com-Server
- Configure the Com-Server via Telnet
- Create and configure a virtual COM port in the PC
- Connect RMC Control module to Com-Server serially via EIA/TIA RS485
- Understand how the Modbus registers in the RMC Control module work
- Configure the parameters on the Modbus RTU Master application
- Read data from Modbus registers
- Write data to Modbus registers
- Manage and understand the exceptions
15
5. Conclusions
The accomplishment of the Scientific Project: "Industrial liquid temperature control" was an
exciting project because we could work on a real-world industry problem. During the process
we had to face many challenges and we gain a broad knowledge and develop abilities in the
following fields: industrial devices, industrial networks, serial interfaces, Ethernet networks,
network protocols and also Visual Basic programming. All this knowledge allowed us to get
the comprehension on how to connect and configure the devices to be able to monitor and
control a thermal process over a network. Moreover the code for the Visual Basic application
software was successfully written, as a result the user has a useful tool to read and write
Modbus registers located in the RMC Control module and is this way, monitor and control the
process remotely over a network. All this knowledge is summarized in the present report and
also in the user’s guide presented as a separate document.
As a result of hard work and dedication we are pleased to submit this report, the user’s guide
and the application software that we hope will be useful in the Laboratory. With this two
documents any new user can easily be introduced to the use of the system and gain a good
understanding on how the interconnected devices works, how to perform basic
configurations and how to use the application.
The application was tested exhaustively and we hope that it will work well, but software
development is not exempt from errors (bugs), for this reason we also deliver the Visual Basic
code as clear as possible and commented as best as possible so that any person can follow it
easily and correct any error or upgrade and adapt the application if needed. For more
advanced configuration and use of the equipment please always read carefully the user’s
manuals [1] and [2].
16
6. References
[1] Wiesemann und Theis GmbH © 08/2005, Manual Com-Server Highspeed, Type 58631,
58633, 58031, 58034, 58231, 58431, 58432, 58331, 58334 ,Release 2.09, August 2005; Com-
Server Firmware 1.46 or higher. Available from: [Link]
[Link]
[2] WATLOW, EZ-ZONE® RMC (Control) Module, User’s Guide, 0600-0070-0000 Rev. D,
December 2013. Available from: [Link]
Manuals/[Link]
[3] Samson AG, Serial Data Transmission, Technical Information, Part 1 Fundamentals,
1999/12 – L153 EN. Available from: [Link]
[4] Jan Axelson, Serial Port Complete: COM Ports, USB Virtual COM Ports, and Ports for
Embedded Systems. Second Edition. Madison: Lakeview Research LLC; 2007.
[5] Habraken J, Hayden M, Sams Teach Yourself Networking in 24 Hours. Third Edition.
Indianapolis: Sams Publishing; 2004.
[6] MODBUS APPLICATION PROTOCOL SPECIFICATION, V1.1b3. April 26, 2012. Available
from: [Link]
[7] MODBUS over Serial Line, Specification and Implementation Guide, V1.02. Dec 20, 2006.
Available from: [Link]
17