Explorar as diferenças entre os protocolos Modbus RTU e Modbus TCP

O que são os protocolos Modbus RTU e Modbus TCP?

In the 1970s, the field of industrial automation was undergoing rapid development. The rapid development of the industry also brought some problems. At that time, different equipment manufacturers used different protocols, preventing their equipment from communicating with each other.

Para resolver este problema, foi criado o protocolo Modbus. É um protocolo aberto e normalizado que pode suportar uma variedade de tipos de dados e códigos de função para satisfazer diferentes necessidades de comunicação. Protocolo Modbus tem 3 tipos, incluindo ASCII, RTU e TCP.

Quando o protocolo Modbus utiliza a transmissão por porta série, podem ser selecionados os dois primeiros tipos, mas os dados têm de ser verificados. Quando é utilizada a transmissão Ethernet, é utilizado o tipo TCP, que não necessita de somas de controlo. O Modbus ASCII é menos utilizado devido à ineficiência da transmissão de dados utilizando principalmente códigos ASCII. Em contrapartida, o Modbus RTU e o Modbus TCP são mais adequados para utilização em ambientes industriais modernos que exigem uma maior eficiência de transmissão. Neste artigo, analisaremos estes dois protocolos, apresentaremos os seus princípios de funcionamento e cenários de aplicação, e esperamos ser-lhe úteis.

modBus1/diferenças entre os protocolos Modbus RTU e Modbus TCP

Princípio de comunicação Modbus

Modbus communication is the principle that it uses a master-slave communication mode. It means that there are master and slave devices, and the master device can initiate the transmission and then send a request to the slave device. The slave device cannot answer the request actively, but can only answer according to the request of the master device. The slave device then performs the requested operation and then sends a response to the master device. The master device receives the response and parses it, thus completing the communication process.

Um dispositivo mestre pode ser ligado a um ou mais dispositivos escravos ao mesmo tempo, mas só pode haver um dispositivo mestre e um dispositivo escravo numa comunicação. Se um dispositivo principal se ligar a um dispositivo secundário, estes comunicam entre si em modo unicast. No entanto, se o dispositivo principal estiver ligado a mais do que um dispositivo secundário, é necessário selecionar o modo de difusão para a comunicação.

Como funciona o Modbus RTU

modbusRTU/diferenças entre os protocolos Modbus RTU e Modbus TCP

Modbus RTU supports a variety of electrical interfaces, such as RS-232, RS 485 and RS-422. It transmits data in binary form, and each byte contains two 4-bit hexadecimal numbers. RTU protocol commands consist of 5 parts: address code, function code, start address, data, and check code. For example, send instruction: 01 03 76 83 00 0C AE 6F, where 01 is the address code, on behalf of the slave address; 03 is the function code, which means “read”; 76 83 is the address of the register; 00 0C is the number of read registers; AE 6F represents the CRC checksum.

Modbus RTU Cenários de aplicação

Because Modbus RTU is simple and stable in binary form for data transmission, it is very suitable for long-distance communication, difficult wiring scenarios, or scenarios with a wide distribution of devices. For example, industrial automation scenarios, small control systems, etc.

Princípio de funcionamento do Modbus TCP

modbusTCP/diferenças entre os protocolos Modbus RTU e Modbus TCP

Modbus TCP is created so that Modbus data can be transmitted on Ethernet, using the TCP502 port. Modbus TCP is based on Modbus RTU, plus the MBAP header. Since TCP is based on a reliable connection service, it no longer uses CRC checksums but relies on TCP’s own error detection and correction mechanisms. For example, send the command: 68 68 00 00 00 06 01 03 33 65 00 04. Among them, 68 68 is the message sequence number; 00 00 indicates that it is the Modbus TCP protocol is used; 00 06 indicates the number of subsequent bytes; 01 is the slave address; 03 is the function code; 33 65 indicates the register address; 00 04 is the number of registers.

Modbus TCP Cenários de aplicação

O Modbus TCP é frequentemente utilizado em cenários mais complexos devido à sua elevada velocidade de transmissão e fiabilidade. Por exemplo, grandes sistemas de controlo, sistemas de controlo de edifícios, etc.

In practice, we need to consider whether to use the Modbus RTU or Modbus TCP protocol. If you have an existing network infrastructure and need to exchange large amounts of data with a fast response, TCP is a good choice. If you need simple, low-cost, long-distance communication, then using RTU is a wise choice.

Modbus RTU and Modbus TCP are like a pair of good friends; they each have their advantages, and together they help effective data exchange between devices. With the development of Industry 4.0, they will be integrated into more new technologies. Let’s look forward to the future; they will create more value for the development of industrial automation!

About Me
db6893fd1d3e314ac461fa240068dc06?s=150&d=mp&r=g
IoT Solutions Specialist ~ Web ~  More Posts

Agnes Wang is an IoT Solutions Specialist at IOTRouter, focusing on industrial IoT gateways, edge computing, and industrial automation solutions.

She specializes in industrial communication technologies, including Modbus, IEC 60870-5-104, MQTT, OPC UA, PLC integration, and remote monitoring applications. She contributes to technical articles and application guides covering industrial IoT solutions, protocol conversion, and edge computing.