Frequently Asked Questions: About Modbus
Frequently Asked Questions: About Modbus
What is a CRC?
About
Enron What are the formats of Modbus commands and responses?
MODBUS
What are data types?
RTU Master
What is byte and word ordering?
RTU Slave What is a Modbus Map?
TCP Client What is the difference between Modbus ASCII and Modbus RTU?
What else?
What is Modbus?
Modbus is an open protocol, meaning that it's free for manufacturers to build into their
equipment without having to pay royalties. It has become a standard communications
protocol in industry, and is now the most commonly available means of connecting
industrial electronic devices. It is used widely by many manufacturers throughout many
industries. Modbus is typically used to transmit signals from instrumentation and
control devices back to a main controller or data gathering system, for example a
system that measures temperature and humidity and communicates the results to a
computer. Modbus is often used to connect a supervisory computer with a remote
terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems.
Versions of the Modbus protocol exist for serial lines (Modbus RTU and Modbus
ASCII) and for Ethernet (Modbus TCP).
Modbus is transmitted over serial lines between devices. The simplest setup would be a
single serial cable connecting the serial ports on two devices, a Master and a Slave.
>
The data is sent as series of ones and zeroes called bits. Each bit is sent as a voltage.
Zeroes are sent as positive voltages and a ones as negative. The bits are sent very
quickly. A typical transmission speed is 9600 baud (bits per second).
What is hexadecimal?
When troubleshooting problems, it can be helpful to see the actual raw data being
transmitted. Long strings of ones and zeroes are difficult to read, so the bits are
combined and shown in hexadecimal. Each block of 4 bits is represented by one of the
sixteen characters from 0 to F.
Each block of 8 bits (called a byte) is represented by one of the 256 character pairs
from 00 to FF.
What is ASCII?
ASCII stand for American Standard Code for Information Interchange. In the same
way that every 4 bits can be combined and represented by one of sixteen hexadecimal
characters from 0 to F, every 8 bits (every byte) can be combined and represented by
one of 256 ASCII characters, including the common keyboard characters. For
example, some of the values for ASCII characters are...
34 0010 0010 22 #
35 0010 0011 23 $
36 0010 0100 24 %
47 0010 1111 2F /
48 0011 0000 30 0
49 0011 0001 31 1
56 0011 1000 38 8
57 0011 1001 39 9
58 0011 1010 3A :
64 0100 0000 40 @
65 0100 0001 41 A
66 0100 0010 42 B
89 0101 1001 59 Y
90 0101 1010 5A Z
91 0101 1011 5B [
95 0101 1111 5F _
96 0110 0000 60 `
97 0110 0001 61 a
Coil/Register Numbers can be thought of as location names since they do not appear in
the actual messages. The Data Addresses are used in the messages.
For example, the first Holding Register, number 40001, has the Data Address 0000.
The difference between these two values is the offset.
Each table has a different offset. 1, 10001, 30001 and 40001.
Each slave in a network is assigned a unique unit address from 1 to 247. When the
master requests data, the first byte it sends is the Slave address. This way each slave
knows after the first byte whether or not to ignore the message.
The second byte sent by the Master is the Function code. This number tells the slave
which table to access and whether to read from or write to the table.
CRC stands for Cyclic Redundancy check. It is two bytes added to the end of every
modbus message for error detection. Every byte in the message is used to calculate the
CRC. The receiving device also calculates the CRC and compares it to the CRC from
the sending device. If even one bit in the message is received incorrectly, the CRCs will
be different and an error will result.
Follow the links in this table to see examples of the requests and responses.
The example for FC03 shows that register 40108 contains AE41
which converts to the 16 bits 1010 1110 0100 0001
Great! But what does it mean? Well, it could mean a few things.
Register 40108 could also be combined with 40109 to form any of these 32-bit data
types:
A 32-bit unsigned integer (a number between 0 and 4,294,967,295)
40108,40109 = AE41 5652 = 2,923,517,522
More registers can be combined to form longer ASCII strings. Each register being used
to store two ASCII characters (two bytes).
The Modbus specification doesn't define exactly how the data is stored in the registers.
Therefore, some manufacturers implemented modbus in their equipment to store and
transmit the higher byte first followed by the lower byte. (AE before 41).
Alternatively, others store and transmit the lower byte first (41 before AE).
Similarly, when registers are combined to represent 32-bit data types, Some devices
store the higher 16 bits (high word) in the first register and the remaining low word in
the second (AE41 before 5652) while others do the opposite (5652 before AE41)
It doesn't matter which order the bytes or words are sent in, as long as the receiving
device knows which way to expect it.
For example, if the number 2,923,517,522 was to be sent as a 32 bit unsigned integer, it
could be arranged any of these four ways.
also know as
AE41 5652 high byte first high word first "big endian"
5652 AE41 high byte first low word first
41AE 5256 low byte first high word first
5256 41AE low byte first low word first "little endian"
Some devices are built with a fixed map that is defined by the manufacturer. While
other devices allow the operator to configure or program a custom map to fit their
needs.
Since the range of the analog output holding registers is 40001 to 49999, it implies that
there cannot be more than 9999 registers. Although this is usually enough for most
applications, there are cases where more registers would be beneficial.
Many modbus software drivers (for Master PCs) were written with the 40001 to 49999
limits and cannot access extended registers in slave devices. And many slave devices do
not support maps using the extended registers. But on the other hand, some slave
devices do support these registers and some Master software can access it, especially if
custom software is written.
Since a single byte is normally used to define the slave address and each slave on a
network requires a unique address, the number of slaves on a network is limited to 256.
The limit defined in the modbus specification is even lower at 247.
To get beyond this limit, a modification can be made to the protocol to use two bytes
for the address. The master and the slaves would all be required to support this
modification. Two byte addressing extends the limit on the number of slaves in a
network to 65535.
By default, the Simply Modbus software uses 1 byte addressing. When an address
greater than 255 is entered, the software automatically switches to 2 byte addressing
and stays in this mode for all addresses until the 2 byte addressing is manually turned
off.
Enron Modbus includes commands for moving events and historical data..
What else?
If you read this page, We would love to hear your comments. Please send an email
to info@simplymodbus.ca and let us know what you found helpful and what topics we
could add, expand or clarify.