Labview Modbus Serial Example



MODBUS communication. This will help you identify problems that may appear during serial communication and prevent them. What should I look at as an issue. See manual for addition. The original Modbus Protocol specification, published in 1979, describes Serial Communications where data is transmitted one bit at a time. A later update to the standard, called Modbus TCP, describes how to use Modbus in TCP/IP networks. The rest of this article describes the Modbus protocol is more detail: Modbus Data Types. Creates a serial or TCP Modbus master instance. You must manually select the polymorphic instance to use. You can use the Modbus master instance to perform read and write operations on Modbus slaves. The default read and write operation timeout is 5,000 ms. You can use the Property Node or the Set Timeouts VI to change the timeout.

Modbus Library

Data transmission library using MODBUS Protocol Driver. Serial Communications and via TCP/IP. MODBUS RTU ASCII Modus. Modbus Library with Master, Client and Slave support.

Perform easily Modbus master or slave device functionality in your application written for example with C++, C#, Delphi, LabVIEW, Pascal, Visual Basic (incl. NET) or Java.

Modbus protocol library for TCP RTU over TCP. Bridge RTU over IP Gateway. Modbus for serial RS-485 library. MODBUS/TCP Master and Slave. Data Acquisition Products. MODBUS Protocol with LabView samples. Modbus Master Protocol library. Modbus bridging serial to TCP/IP. Serial MODBUS Library. MODBUS Library with Siemens S7.

Serial Communications and via TCP/IP MODBUS RTU ASCII Modus.

  • Creates a serial or TCP Modbus master instance. You must manually select the polymorphic instance to use. You can use the Modbus master instance to perform read and write operations on Modbus slaves. The default read and write operation timeout is 5,000 ms. You can use the Property Node or the Set Timeouts VI to change the timeout.
  • Serial Parameters are parameters that modify the way the MODBUS frame is structured. Refer to the MODBUS specification for more information about the MODBUS Frame. The Serial Parameters in LabVIEW is a cluster containing an enum (Mode) and an integer (Slave Address).

Modbus driver RTU and ASCII. Data transmission using MODBUS Protocol. Modbus Library.

Modbus TCP slave to Modbus Master converter. Connect a Master Modbus RTU RS232, RS485 with one or more Modbus TCP slaves / servers. Modbus master on serial and slaves on Ethernet (TCP).

Delphi MODBUS RTU & ASCII Unit, Bibliothek.

Delphi Unit supporting Modbus protocol library.

MODBUS protocol Library & Components

MODBUS Protocol LibraryWindows, LinuxLibrary, Component, ActiveX, UnitC#, C / C++, Delphi, Java, Pascal, Visual Basic, VB netSuperCom Suite, SuperCom Serial Library incl. MODBUS, SuperCom for TCP/IP incl. MODBUS MODBUS RTU,MODBUS ASCII Modus, MODBUS TCP. Data transmission library using MODBUS Protocol Driver. Modbus TCP slaves / server. Modbus for TCP RTU over TCP. Bridge RTU over IP Gateway
HomeADONTECSoftware Development, Serial Data Communication, TCP/IP Client Server

Data Communication Solutions by ADONTEC
Some SuperCom MODBUS functions
32 Bit and 64 Bit Versions available!

Version 2.xx

SuperCom MODBUS Protocol Library

MODBUS is an industrial data communication protocol used to control PLC's and automation machines connected through serial lines (RS-232, RS-422, RS-485) or Ethernet TCP/IP connections. The SuperCom MODBUS Protocol Library supports send and receive data with one or more devices which respect the MODBUS protocol.

The SuperCom MODBUS Protocol Library is the most complete MODBUS library and provides a rock solid foundation to develop fast robust MODBUS capable applications. The SuperCom MODBUS Protocol Library hides the complex MODBUS protocol offering one easy to use set of functions that can communicate data packets over serial and TCP/IP connections thus saving valuable time, reducing costs and ensuring quality results.

Perform easily master or slave device functionality in you application written for example with C++, C#, Delphi, Visual Basic (incl. NET), Java etc.

The SuperCom MODBUS Protocol Library supports data communication between devices connected to a serial port, on a bus system or network (TCP/IP). The protocol module supports ASCII and RTU (Remote Terminal Unit) operation mode (ASCII mode transfers ASCII codes and RTU binary data bytes in binary mode).

Run up to 255 simultaneous connections with Modbus devices.

There is only one API to learn! The same functions used with Serial, TCP/IP or ISDN type of connections and operation mode (Modbus ASCII, Modbus RTU, Modbus TCP).

The SuperCom MODBUS Protocol Library also supports custom function codes and data packets by implementing functions that communicate transparently. Controlling machine specific extensions is realy easy using these functions.

Accomplish with ease
In most cases only a handful of functions are needed to talk to a Modbus capable PLC or controller. Your project is updated real fast. A lot of functions is backing you up to accomplish different tasks or configurations.

  • Run a single or multiple simultaneous connections to modbus devices (up to 255 connections per application).
  • Runs smoothly even if multiple concurrently executing connections.
  • Run multiple Modbus masters.
  • Offers short reaction times.
  • Connect one or more MODBUS RTU or ASCII masters to one or more Modbus slaves.
  • The SuperCom MODBUS protocol module can control, based on the used SuperCom software, serial and/or TCP/IP connections.
  • The SuperCom MODBUS protocol module can run concurrently connections thus polling more than one plc the same time is possible.
  • Receive Modbus data packets and simulate one or more MODBUS slaves or Protocol Gateway.
  • Create your own Modbus Gateway or Bridge to route data between serial interface and TCP/IP network, for example a MODBUS TCP to MODBUS RTU Gateway.
  • Use SuperCom for Modbus bridging (e.g. serial to TCP/IP).
  • Create your own Protocol Gateway using one of the other SuperCom industrial protocols (PLC protocols) offered or use your own custom protocol.
  • Create your own Modbus Slave that can handle requests on its own or handed over to the application (manual mode) or mixed. A Modbus Slave, created with SuperCom, can support up to 254 concurrent client connections.
  • Use with PLC from SIEMENS, Allen Bradley, other Modbus capable PLC, Modbus devices and controller. A pre-installed MODBUS protocol module on PLC or connected controller or device assumed.
  • Receiving and transmitting of Modbus raw data is supported
  • Low level Data monitoring and recording also supported.

The SuperCom MODBUS Protocol Library uses the SuperCom Communication Layer which provides a rock solid foundation to develop data communication software fast and without headache. Thus it makes no difference to the programmer if the MODBUS protocol used over TCP/IP or serial lines (RS-232, RS-422, RS-485, Modem, TAPI).

SuperCom enables the application to connect to a PLC (nearly from anywhere, e.g. Modem, TAPI, ISDN, Ethernet (TCP/IP), serial lines e.g. RS-232, RS-422, RS-485) and transfer data and/or read, write operands.

Currently supported compiler
As usual with SuperCom, many well-known compilers are supported. Others are constantly coming. The SuperCom MODBUS library can currently be used with the following compiler languages and compilers: C / C++, C#, Visual C++, C++ Builder, Java, Pascal, Delphi, LabVIEW, Visual Basic, Visual Basic .NET (VB .NET), VBA, PowerBuilder, PureBasic. If you miss one, please inquire. (See also)

1. Read a single coil

C/C++
Init Sequence:
Modbus

The above samples are nearly complete programs. More Init-Sequences can be found here.

2. Read/Write Registers

Capture, Store, Forward - MODBUS Slave or Gateway functions
Communication at lower data packet level is possible thus allowing to capture, store and forward of MODBUS data packets or transmit replies. Monitoring MODBUS data packets, simulating a MODBUS Slave or building a protocol converter / gateway is possible. Simulating a MODBUS Slave can be very handy while testing the software (slave examples available).

Supported Protocols
The SuperCom MODBUS Library enables secure and stable data communications with different Modbus devices from different manufacturers. It supports almost all known Modbus options and variations.

The SuperCom MODBUS Library implements the standard MODBUS protocol for serial and TCP/IP connections* based on the official specification by the MODBUS organization. SuperCom supports MODBUS ASCII and MODBUS RTU protocol with serial interfaces (RS-232, RS-422, RS-485, Modem, TAPI) and the MODBUS TCP/IP (MODBUS/TCP) and Open MODBUS TCP with TCP/IP networks.
*A corresponding SuperCom license (Serial and/or TCP/IP) assumed.

The SuperCom MODBUS Protocol Library is a very complete MODBUS protocol stack!

Also included, non standard variants of the MODBUS protocol e.g. RTU over IP(also known as MODBUS RTU/IP, MODBUS RTU over TCP) enable the SuperCom application to talk to OMTS devices (OMTS = Out of the MODBUS TCP/IP specification). Since not an official specification, additional names and variants may exists.

A small SuperCom MODBUS Slave example can be found here.

How to use?
The SuperCom MODBUS Protocol Protocol Library can be used over any communication link supported by SuperCom (currently Serial(RS-232, RS-422, RS-485, Modem, TAPI), TCP/IP, ISDN). For a list of available SuperCom packages containing MODBUS protocol, see the following chart.

The use of one common API for Serial, TCP/IP and ISDN applies here too (any SuperCom ActiveX API and/or DLL API).

MODBUS Simulator
Speeds up development process. The Modbus slave support included in this software also provides Modbus simulator software. Especially in the SuperCom Suite package. A fast and good test environment to deliver quality software.

What to order?
You will find promotional combinations with MODBUS (e.g. SuperCom Serial incl. MODBUS, SuperCom for TCP/IP incl. MODBUS, SuperCom Protocol Engine, SuperCom Suite).

The order code 638 or 638400 is needed only when the MODBUS protocol module is ordered later in addition to a SuperCom package. The most preferable way (incl. the best price) is buying one package from the above pricelist already including the MODBUS functionality.

License Information
Executables developed using SuperCom MODBUS Protocol Module can be distributed royalty free.More.

Supported compilers
C#, C++, Delphi, Visual C++, Visual Basic, Visual Basic NET, C++ Builder, Borland C/C++, Microsoft C/C++, MinGW, Borland Pascal, Java, LabVIEW, PowerBuilder, PureBasic, VBA and other Windows programming tools (MS .NET ?).

Samples
for C/C++, C#, Visual C++, C++ Builder, Java, Pascal/Delphi, Visual Basic, Visual Basic NET (VB .NET), LabVIEW, PureBasic, ..

The SuperCom Suite contains more example programs and especially Modbus Slaves samples supporting multiple clients.

Get the PDF document with more information and images of some of the included sample programs.

What developers say

.. and the client is now polling real fast consuming low CPU. Great support.
Rob, USA.

I'm really impressed. Very sophisticated software that works fast and is flexible to use. Excelent work guys!
Pete, UK.

Great library, the GUI is not blocked.
Ch., USA.

The slave application works like a charm.
Jon, Australia.

We were really surprised by the short reaction times and how smoothly it works even on multiple concurrent TCP connections.
M., Poland.

Works faster than expected!
S., France.

.. issue solved, thanks.
P., The Netherlands.

MODBUS library | MODBUS RTU | MODBUS ASCII | MODBUS TCP | MODBUS over IP | MODBUS Serial Library | MODBUS RS-485 | MODBUS Slave | MODBUS sample C, C++, C#, Pascal, Delphi, Java, Visual Basic, VBA | MODBUS C library | MODBUS C++ library | MODBUS Delphi library | MODBUS Pascal library | MODBUS VB library | MODBUS RTU example | MODBUS C Code Example

Help Contents

Introduction

The Modbus Protocol was originally developed by Modicon (now part of Schneider Electric). Modbus was developed as a communication protocol for Modicon PLC Devices. The original Modbus Protocol specification, published in 1979, describes Serial Communications where data is transmitted one bit at a time. A later update to the standard, called Modbus TCP, describes how to use Modbus in TCP/IP networks.

The rest of this article describes the Modbus protocol is more detail:

  • Modbus Data Types.
  • Modbus Message Structure.
  • Modbus PDU.
  • Modbus Exception Codes.

Modbus Data Types

The Modbus Protocol supports these data types:

Data TypeAccessDescription
CoilRead-writeSingle bit outputs.
Discrete InputRead-onlySingle bit inputs.
Input RegisterRead-only16-bit input registers.
Holding RegisterRead-write16-bit output registers.

Modbus Message Structure

Modbus is a request-response protocol where:

  • The client sends a request to a Modbus device.
  • The Modbus device sends a response.

The structure of a modbus message is the same for both requests and responses:

Unit AddressModbus PDUError Check

The exact format of the message depends on the variant of Modbus protocol used:

  • Modbus ASCII - A serial protocol using a subset of ASCII characters.
  • Modbus RTU - A serial protocol using 8-bit binary.
  • Modbus TCP - A TCP/IP protocol.
  • Modbus RTU over TCP - A TCP/IP protocol with an additional CRC check.

Modbus ASCII

Modbus ASCII uses a subset of the ASCII character set to send modbus messages over Serial Communications.

Modbus ASCII messages start with the colon (:) character (ASCII 58). Modbus ASCII messages end with carriage return (ASCII 13) and line feed (ASCII 10) characters. Between the start and end characters only hexadecimal characters 0 to 9 and A to F are allowed.

The structure of a Modbus ASCII message is:

StartUnit AddressMessageLRCEnd
ASCII 582 charactersN characters2 charactersASCII 13 + ASCII 10

Where:

  • The Unit Address field is the PLC Address encoded as 2 hexadecimal characters.
  • The Message field is a Modbus PDU where each byte is encoded as 2 hexadecimal characters.
  • The LRC field is the Longitudinal Redundancy Check of the Address and Message fields.

Modbus RTU

Modbus RTU uses 8-bit Serial Communications to send Modbus messages.

Labview modbus crc

The structure of a Modbus RTU message is:

Unit AddressMessageCRC
1 ByteN Bytes2 Bytes

Where:

  • The Unit Address field is the PLC Address encoded as single byte.
  • The Message field is a Modbus PDU.
  • The CRC field is the Cyclic Redundancy Check of the Address and Message fields.

Modbus TCP

Modbus TCP uses a TCP/IP link to send and receive Modbus messages.

The structure of a Modbus TCP message is:

Transaction IdProtocolLengthUnit AddressMessage
2 Bytes2 Bytes2 Bytes1 ByteN Bytes

Where:

  • The Transaction Id field identifies the transaction.
  • The Protocol field is zero to indicate Modbus protocol.
  • The Length field is the number of following bytes.
  • The Unit Address field is the PLC Address encoded as single byte.
  • The Message field is a Modbus PDU.

Unit Address

Note: Real Modbus TCP devices use the Unit Address field in different ways:

  • Some Modbus TCP devices ignore Unit Address.
  • Some Modbus TCP devices require a fixed value for Unit Address, for example 0 or 255.
  • Some Modbus TCP devices are a gateway to multiple PLC where the Unit Address selects which PLC to communicate with.

Modbus RTU over TCP

Modbus RTU over TCP is a non-standard variant of Modbus TCP that includes the CRC from the Modbus RTU message.

The structure of a Modbus RTU over TCP message is:

Transaction IdProtocolLengthUnit AddressMessageCRC
2 Bytes2 Bytes2 Bytes1 ByteN Bytes2 Bytes

Where:

  • The Transaction Id field identifies the transaction.
  • The Protocol field is zero to indicate Modbus protocol.
  • The Length field is the number of following bytes.
  • The Unit Address field is the PLC Address encoded as single byte.
  • The Message field is a Modbus PDU.
  • The CRC field is the Cyclic Redundancy Check of the Address and Message fields.

Modbus PDU

The Modbus Protocol supports these PDU:

  • Modbus Read Coils (01).
  • Modbus Read Discrete Inputs (02).
  • Modbus Read Holding Registers (03).
  • Modbus Read Input Registers (04).
  • Modbus Write Single Coil (05).
  • Modbus Write Single Register (06).
  • Modbus Write Multiple Registers (16).

Modbus Read Coils (01)

Modbus Read Coils, function code 01, reads between 1 and 2000 output coils (bits) from the PLC.

The request PDU consists of 5 bytes:

OffsetLengthDescriptionValues
0ByteFunction Code01
2WordFirst coil address0000h - FFFFh
4WordCoil count0001 - 07D0h

The normal response varies in length from 3 bytes up to 252 bytes depending on the number of coils requested:

OffsetLengthDescriptionValues
0ByteFunction Code01
1ByteByte Count(CoilCount + 7) / 8
2N BytesCoil data..

Note: The total number of bytes returned is 2 + (CoilCount + 7) / 8, where CoilCount is the number of coils requested. For example a request for 1 coil, will return 3 bytes. A request for 8 coils will also return 3 bytes. A request for 9 coils will return 4 bytes. The largest request possible is for 2000 coils, which will return 252 bytes.

If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:

OffsetLengthDescriptionValues
0ByteFunction Code81h
1ByteException CodeSee Exception Codes

Example: Read 12 coils starting at 00033 from a PLC at address 2. Response with coils 00040 and 00042 set and all others clear :

RequestResponse
Modbus ASCII3A 30 32 30 31 30 30 32 30 30 30 30 43 44 31 0D 0A3A 30 32 30 31 30 32 38 30 30 32 37 39 0D 0A
Modbus RTU02 01 00 20 00 0C 3D F602 01 02 80 02 1D FD
Modbus TCP00 05 00 00 00 06 02 01 00 20 00 0C00 05 00 00 00 05 02 01 02 80 02
Labview modbus example

Note: The PDU part of each request and response is shown in Blue.

Modbus Read Discrete Inputs (02)

Modbus Read Discrete Inputs, function code 02, reads between 1 and 2000 inputs from the PLC.

The request PDU consists of 5 bytes:

OffsetLengthDescriptionValues
0ByteFunction Code02
2WordFirst input address0000h - FFFFh
4WordInput count0001 - 07D0h

The normal response varies in length from 3 bytes up to 252 bytes depending on the number of inputs requested:

OffsetLengthDescriptionValues
0ByteFunction Code02
1ByteByte Count(InputCount + 7) / 8
2N BytesInput data..

Note: The total number of bytes returned is 2 + (InputCount + 7) / 8. InputCount is the number of inputs requested. For example a request for 1 input, will return 3 bytes. A request for 8 inputs will also return 3 bytes. A request for 9 inputs will return 4 bytes. The largest request possible is for 2000 inputs, which will return 252 bytes.

If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:

OffsetLengthDescriptionValues
0ByteFunction Code82h
1ByteException CodeSee Exception Codes

Example: Read 16 inputs starting at 10501 from a PLC at address 1. Response with inputs 10501 and 10503 set and all others clear :

RequestResponse
Modbus ASCII3A 30 31 30 32 30 31 46 34 30 30 32 30 45 38 0D 0A3A 30 31 30 32 30 32 30 35 30 30 46 36 0D 0A
Modbus RTU01 02 01 F4 00 20 39 DC01 02 02 05 00 BA E8
Modbus TCP00 0A 00 00 00 06 01 02 01 F4 00 2000 0A 00 00 00 05 01 02 02 05 00

Note: The PDU part of each request and response is shown in Blue.

Modbus Read Holding Registers (03)

Modbus Read Holding Registers, function code 03, reads between 1 and 125 holding registers from the PLC.

The request PDU consists of 5 bytes:

OffsetLengthDescriptionValues
0ByteFunction Code03
2WordFirst input address0000h - FFFFh
4WordRegister count0001 - 007Dh

The normal response varies in length from 4 bytes up to 252 bytes depending on the number of holding registers requested:

OffsetLengthDescriptionValues
0ByteFunction Code03
1ByteByte CountRegisterCount * 2
2N BytesRegister data..

Note: The total number of bytes returned is 2 + 2 * RegisterCount, where RegisterCount is the number of holding registers requested. For example a request for 1 holding register, will return 4 bytes. A request for 2 holding registers will return 6 bytes. A request for 125 holding registers will return 252 bytes.

If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:

OffsetLengthDescriptionValues
0ByteFunction Code83h
1ByteException CodeSee Exception Codes

Example: Read 2 holding registers starting at address 40601 from a PLC at address 1. Response returns register 40601 value 1000, and register 40602 value 5000:

RequestResponse
Modbus ASCII3A 30 31 30 33 30 32 35 38 30 30 30 32 41 30 0D 0A3A 30 31 30 33 30 34 30 33 45 38 31 33 38 38 37 32 0D 0A
Modbus RTU01 03 02 58 00 02 44 6001 03 04 03 E8 13 88 77 15
Modbus TCP00 0F 00 00 00 06 01 03 02 58 00 0200 0F 00 00 00 07 01 03 04 03 E8 13 88

Note: The PDU part of each request and response is shown in Blue.

Modbus Read Input Registers (04)

Modbus Read Input Registers, function code 04, reads between 1 and 125 input registers from the PLC.

Online You can think of it as a very polished version of, but it’s more than that: the team laser focus on macOS means there are all sorts of integrations that similar tools wouldn’t even think to offer, like menus for Windows program in the menu bar and compatible keyboard shortcuts. Thanks to a feature in Parallels called Coherence Mode, which you can use if you’ve, it’s only a click away.In Coherence Mode, your virtual Windows desktop will merge with your Mac one, allowing you to arrange windows from the two operating systems side-by-side.

The request PDU consists of 5 bytes:

OffsetLengthDescriptionValues
0ByteFunction Code04
2WordFirst input address0000h - FFFFh
4WordRegister count0001 - 007Dh

The normal response varies in length from 4 bytes up to 252 bytes depending on the number of input registers requested:

OffsetLengthDescriptionValues
0ByteFunction Code04
1ByteByte CountRegisterCount * 2
2N BytesRegister data..

Note: The total number of bytes returned is 2 + 2 * RegisterCount, where RegisterCount is the number of input registers requested. For example a request for 1 input register, will return 4 bytes. A request for 2 input registers will return 6 bytes. A request for 125 input registers will return 252 bytes.

If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:

OffsetLengthDescriptionValues
0ByteFunction Code84h
1ByteException CodeSee Exception Codes

Example: Read 2 input registers starting at address 30201 from a PLC at address 1. Response returns register 30201 value 10000, and register 30202 value 50000:

RequestResponse
Modbus ASCII3A 30 31 30 34 30 30 43 38 30 30 30 32 33 31 0D 0A3A 30 31 30 34 30 34 32 37 31 30 43 33 35 30 41 44 0D 0A
Modbus RTU01 04 00 C8 00 02 F0 3501 04 04 27 10 C3 50 A0 39
Modbus TCP00 14 00 00 00 06 01 04 00 C8 00 0200 14 00 00 00 07 01 04 04 27 10 C3 50

Note: The PDU part of each request and response is shown in Blue.

Modbus Write Single Coil (05)

Modbus Write Single Coil, function code 05, writes a single coil to the PLC.

The request PDU consists of 5 bytes:

OffsetLengthDescriptionValues
0ByteFunction Code05
2WordFirst coil address0000h - FFFFh
4WordCoil value0x0000 or 0xFF00

The normal response is the request reflected back:

OffsetLengthDescriptionValues
0ByteFunction Code05
2WordFirst coil address0000h - FFFFh
4WordCoil value0x0000 or 0xFF00

If the PLC detects an error, for example an address that is not available, an error response will be sent:

OffsetLengthDescriptionValues
0ByteFunction Code85h
1ByteException CodeSee Exception Codes

Example: Set coil 00101 in device with address 1 to 1.

RequestResponse
Modbus ASCII3A 30 31 30 35 30 30 36 34 46 46 30 30 39 37 0D 0A3A 30 31 30 35 30 30 36 34 46 46 30 30 39 37 0D 0A
Modbus RTU01 05 00 64 FF 00 CD E501 05 00 64 FF 00 CD E5
Modbus TCP00 19 00 00 00 06 01 05 00 64 FF 0000 19 00 00 00 06 01 05 00 64 FF 00

Note: The PDU part of each request and response is shown in Blue.

Modbus Write Single Register (06)

Modbus Write Single Register, function code 06, writes a single register to the PLC.

Labview Modbus Api

The request PDU consists of 5 bytes:

OffsetLengthDescriptionValues
0ByteFunction Code06
2WordFirst register address0000h - FFFFh
4WordRegister value0000h - FFFFh

The normal response is the request reflected back:

OffsetLengthDescriptionValues
0ByteFunction Code06
2WordFirst register address0000h - FFFFh
4WordRegister value0000h - FFFFh

If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:

OffsetLengthDescriptionValues
0ByteFunction Code86h
1ByteException CodeSee Exception Codes

Example: Set Holding Register 40101 in device with address 1 to 15000.

RequestResponse
Modbus ASCII3A 30 31 30 36 30 30 36 34 33 41 39 38 43 33 0D 0A3A 30 31 30 36 30 30 36 34 33 41 39 38 43 33 0D 0A
Modbus RTU01 06 00 64 3A 98 98 DB01 06 00 64 3A 98 98 DB
Modbus TCP00 1E 00 00 00 06 01 06 00 64 3A 9800 1E 00 00 00 06 01 06 00 64 3A 98

Note: The PDU part of each request and response is shown in Blue.

Modbus Write Multiple Registers (16)

Modbus Write Multiple Registers, function code 16, writes between 1 and 123 registers to the PLC.

The request PDU consists of between 8 and 252 bytes:

OffsetLengthDescriptionValues
0ByteFunction Code10h
2WordFirst register address0000h - FFFFh
4WordRegister Count0000h - 007Bh
5ByteByte Count0000h - 007Bh
6N WordsRegister values..

The normal response consists of 5 bytes:

OffsetLengthDescriptionValues
0ByteFunction Code10h
2WordFirst register address0000h - FFFFh
4WordRegister Count0000h - 007Bh

If the PLC detects an error in the request, for example an address that is not available, an error response will be sent:

OffsetLengthDescriptionValues
0ByteFunction Code90h
1ByteException CodeSee Exception Codes

Example: In the PLC at address 28, set register 40101 to 1000 and register 40102 to 2000.

RequestResponse
Modbus ASCII3A 31 43 31 30 30 30 36 34 30 30 30 32 30 34 30 33 45 38 30 37 44 38 41 30 0D 0A3A 31 43 31 30 30 30 36 34 30 30 30 32 36 45 0D 0A
Modbus RTU1C 10 00 64 00 02 04 03 E8 07 D8 19 021C 10 00 64 00 02 03 9A
Modbus TCP00 23 00 00 00 0B 1C 10 00 64 00 02 04 03 E8 07 D800 23 00 00 00 06 1C 10 00 64 00 02

Labview Modbus Library

Note: The PDU part of each request and response is shown in Blue.

Modbus Exception Codes

Query

An exception code is a single byte providing an explanation of an error:

CodeDescription
01hIllegal function
02hIllegal data address
03hIllegal data value
04hSlave device failure

Modbus Programming Examples

Further Information

To learn how modbus data addresses are presented in human readable form.

To learn about Modbus Register Block Tags.

For an overview of the Modbus Driver.

For the meaning of terms used in Fernhill SCADA.

Fernhill SCADA Version 3.62. Copyright © 2012-2020 Fernhill Software Ltd: All rights reserved.