Modbus Tutorials | Modbus protocol, ASCII and RTU frame, Modbus work

Reprinted from: https: //www.rfwireless-world.com/Tutorials/Modbus-Protocol-tutorial.html

The Modbus tutorial covers the basic modbus protocol, ASCII and RTU frame structure, Modbus protocol work. Modbus protocol described tutorial application example.

What is Modbus?

Description :
"Modbus" terms are trademarks of Modicon Inc., maintaining the standard. It is an application layer protocol that the connection between the client based on different types of bus or network device client / server architecture. The Modbus protocol is used for communication between the network device SCADA style.

Modbus protocol

Modbus protocol runs over RS232, RS422 and RS485. For Modbus frame, based on the IP link layer defines the Modbus / TCP specification. There are many industrial automation and measurement protocols. Modbus protocol-based query / response model. "POLLING MESSAGE" and "response message" and its field (i.e., content) as shown in enlarged view of FIG.

Modbus message format, Modbus frame structure

• As shown, the query and response message contains the start (0x3A) and end (0x0D0A) delimiter.
• query message from the field, including device address, function code, data, and error checking of query composition.
• the response message comprises a field device address, function code, the response data and error checking composition.

Modbus protocol work

•Modbus协议通常遵循基于主从架构。主设备向从设备发送请求消息并等待响应消息。该架构为主站提供了完整的信息流控制。与以前使用RS422 / RS485等的多点网络相比,这具有很大的优点

•如图所示,Modbus请求消息是一组分层数据。控制器可以设置为使用两种传输模式之一在标准Modbus网络上进行通信:ASCII或RTU。在配置每个控制器期间,用户可以选择所需的模式以及串行端口通信参数(波特率,奇偶校验模式等)。对于Modbus网络上的所有设备,模式和串行参数必须相同。
•ASCII或RTU(远程终端单元)模式的选择仅适用于标准Modbus网络。它定义了在这些网络上串行传输的消息字段的位内容。它确定如何将信息打包到消息字段中并进行解码。
•当控制器设置为使用ASCII模式在Modbus网络上通信时,消息中的每个8位字节将作为两个ASCII字符发送。此模式的主要优点是它允许在字符之间发生长达一秒的时间间隔而不会导致错误。

•当控制器设置为使用RTU模式在Modbus网络上通信时,消息中的每个8位字节都包含两个四位十六进制字符。这种模式的主要优点是,对于相同的波特率,其更大的字符密度可以比ASCII更好的数据吞吐量。每条消息必须以连续的流方式传输。
•在两种串行传输模式(ASCII或RTU)中的任何一种模式下,发送设备将Modbus消息放入具有已知起点和终点的帧中。这允许接收设备在消息开始时开始,读取地址部分并确定寻址哪个设备,以及知道消息何时完成。可以检测到部分消息,并且可以设置错误。
•如图所示,Modbus协议适用于主从模型。总线或网络上的一个设备可以启动事务(称为查询),该事务可以寻址单个从设备或广播到所有从设备。从设备根据收到的Modbus帧执行操作,并在需要时以“响应帧”的形式进行响应。 
•传输模式定义要在Modbus网络上传输的消息的成帧和位编码。

Modbus ASCII模式

Modbus mode frame structure -ASCII

该图描绘了Modbus帧的ASCII模式。如ASCII模式所示,每个字节在串行链路上编码为2个ASCII字符。每个ASCII字符作为1个起始位,7个数据位,0或1个奇偶校验位,一个或两个停止位发送

Modbus RTU模式

Modbus mode frame structure -RTU

该图描绘了Modbus帧的RTU模式。如RTU(远程终端单元)模式所示,消息以连续流格式传输。每个8位字节由1个起始位,8个数据位,0或1个奇偶校验位,1或2个停止位构成。消息本身在至少3.5个字符时间的静默期后开始。

Modbus消息字段

➤让我们了解在ASCII模式和RTU模式下使用的主要字段。
Modbus地址: Modbus消息以8位目标地址开始。这可以取0到247之间的任何值。这里0用作广播地址,其余用作唯一设备地址。


Modbus功能:功能代码包含2个字符(ASCII模式)和8位(RTU模式)/它取1到255之间的任何值,并根据应用程序配置文件选择。
Modbus数据字段:该数据字段根据需要通过不同的Modbus功能传送应用程序级别信息。如果函数包含可变大小的数据,则在此位置以“字节计数”开头。
Modbus错误检查字段:此字段用作错误检测。它也被称为“校验和”。

 

Modbus TCP模式

与RS232和RS485不同,Modbus TCP使用TCP / IP协议传输Modbus消息。该图描绘了TCP / IP和OSI协议栈中Modbus协议的映射。

Modbus TCP / IP stack

•Modbus TCP提供对Modbus功能的TCP / IP访问。
•使用众所周知的端口502,通过主站和从站之间建立的TCP连接发送每个Modbus请求/响应。
•TCP连接可以重复用于多个查询/响应交换。

Modbus TCP

•modbus请求/响应帧的字节内容(即没有特定于串行物理层的帧起始 - 停止 - 奇偶校验位)仅通过TCP连接以大印度顺序传输。Modbus TCP的唯一补充是添加一个7字节的消息前缀。

➤Refref00 00 00 len unit 

•“ref”字节简单地由从服务器从请求中复制,并且可以由主服务器用作句柄。消息前缀中的长度信息允许在多个IP数据包中分割Modbus消息时正确重新组装。 
•从站地址已重命名为“单元标识符”并包含在单元中。消息的其余部分符合常规Modbus结构,但出于显而易见的原因,可能会省略错误检查字段。

Profibus与Modbus

下表提到了Profibus和Modbus之间在各种参数方面的比较。

特征 现场总线 MODBUS
操作模式 使用RS485在多主模式下运行。 仅使用ASCII / RTI在单主模式下运行。
使用以太网 无法在以太网上运行,但profinet在以太网上运行,与profibus不同。 可以使用TCP / IP协议在以太网上运行。
物理媒介 双绞线,光纤 Modbus没有定义物理介质。它定义了可以在任何物理介质上使用的消息结构。然而,Modbus RS485在所有人中都很受欢迎。
传输速度 以1.2 Kbps至12 Mbps的不同传输速度运行。 Modbus RS485支持高达115 Kbps或高达19.2 Kbps的传输种子。
距离覆盖 32个站使用profibus距离可达1200米,而2个站以500 kbps的速度通信,距离可达400米。低速传输支持更高的距离,而高速传输支持更低的距离。 Modbus RS485电缆应小于700米。
主设备和从设备的数量 单个profibus网络上最多连接126个设备(主设备和从设备)。 Modbus master device from actually supports 247. Since the RS485 protocol limits the number of master devices connected to the main cable (including the master) is 32. Support the use of more than 32 repeaters.
Future use Alone profibus good, but it's a combination of professional features and RS485 will be obsolete. However, professional sensor / actor fieldbus devices have increased their current and future market penetration in the automation industry Because of its simple protocol, it has become one of the major automation industry Ethernet protocol. Other older versions are RS232, RS422, RS485 and so on. And apparatus for bus without address.
application It is a very powerful protocol that can be used to automate the entire plant. It used to have more points and multiple regional suppliers of automation equipment. This is a very simple protocol, it can be used to connect a single controller in a point to point configuration mode. It is used for small-scale factory automation.

 

Modbus application examples

modbus protocol may be implemented in various systems RS485 / RS422 and the like.
• Zigbee to Modbus RTU / TCP gateway
• Real-time inventory control, such as picking, lighting and so on.
• Industrial automation
• Smart Metering

The Modbus protocol Modbus tutorial for beginners to learn the basis of very useful. For more information, please refer to ASCII, RTU or TCP mode corresponding modbus protocol specification.

Guess you like

Origin www.cnblogs.com/CodeWorkerLiMing/p/11333125.html