A master-slave communication method and system based on RS485 bus

By distinguishing between real-time and extended fields on the RS485 bus, the communication problems of MODBUS-RTU protocol in large data transmission, such as packet sticking and bandwidth limitation, are solved, achieving more efficient and reliable master-slave communication.

CN116016011BActive Publication Date: 2025-09-16FUJIAN NEBULA ELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211438451.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-16
Publication Date
2025-09-16
Estimated Expiration
2042-11-16

AI Technical Summary

Technical Problem

The existing MODBUS-RTU protocol based on RS485 bus is prone to communication packet sticking when transmitting large amounts of data, affecting reliability. In addition, the communication bandwidth is limited in complex environments, which restricts the number of slave stations.

Method used

By setting the master station request frame format, the slave station response frame format and the field priority, the field types are divided into real-time fields and extended fields. Real-time fields are queried in real time, and extended fields are queried in polling mode, which shortens the total transmission frame length and improves communication efficiency.

Benefits of technology

It improves the real-time, scalability and reliability of master-slave communication, avoids communication packet sticking errors, supports on-demand setting of extension fields, and expands the number of slave stations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116016011B_ABST
    Figure CN116016011B_ABST
Patent Text Reader

Abstract

The present invention provides a master-slave communication method and system based on RS485 bus in the field of industrial network control technology. The method includes: step S10, setting a master station request frame format, a slave station response frame format, and a field priority; step S20, the master station generates a data acquisition request based on the master station request frame format and the field priority, and sends the data acquisition request to the corresponding slave station based on the RS485 bus; step S30, the slave station receives and parses the data acquisition request, obtains real-time field parameters, extended field parameters, and a first check code, and uses the first check code to check the real-time field parameters and the extended field parameters; step S40, the slave station generates real-time field data and extended field data based on the real-time field parameters and the extended field parameters, and generates a data response based on the real-time field data, the extended field data, and the slave station response frame format and sends it to the master station. The advantages of the present invention are: greatly improving the real-time performance, scalability, and reliability of master-slave communication.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of industrial network control, and in particular to a master-slave communication method and system based on RS485 bus. Background Art

[0002] Industrial networks are generally controlled using the MODBUS-RTU protocol based on the RS485 bus. The RS485 interface uses differential transmission, has relatively high noise suppression capabilities, a maximum transmission distance of approximately 1200 meters, a maximum transmission rate of 10Mb / s, and supports multi-point, two-way communication. Therefore, it is adopted as a standard interface for a large number of industrial devices. The MODBUS-RTU protocol is a master-slave protocol. There can only be one master and several slaves on the bus at any one time. Modbus communication is always initiated by the master. A slave will not send data if it does not receive a request from the master, and slaves cannot communicate with each other. The master can only initiate one Modbus transaction at a time.

[0003] Based on the above characteristics, the MODBUS-RTU protocol based on the RS485 bus can only adopt a question-and-answer communication method, that is, the master station periodically queries the slave station status, and the slave station responds with corresponding data after receiving the master station's polling command. However, there are the following disadvantages:

[0004] 1. When a large amount of data needs to be transmitted (or the average communication volume is low but bursty), the master station requests data from the corresponding slave station through the RS485 bus. Since the number of data packets sent by the slave station is large and the speed is fast, the data packets received by the master station at the same time may exceed the bandwidth of the RS485 bus, and may cause communication packet sticking, resulting in communication response errors, which directly affects communication reliability; 2. The industrial field environment is harsh. Due to the complexity of the site environment and the application of the RS485 bus, the communication bandwidth of the RS485 bus cannot be increased indefinitely. For example, the network composed of the RS485 bus can only be wired in serial, which makes the actual wiring design and construction in complex occasions very difficult, thus affecting the actual communication bandwidth. In addition, the MODBUS-RTU protocol can only process 247 addresses on a data link, which limits the number of slave stations that can be connected to the master station.

[0005] Therefore, how to provide a master-slave communication method and system based on RS485 bus to improve the real-time performance, scalability and reliability of master-slave communication has become a technical problem that needs to be solved urgently. Summary of the Invention

[0006] The technical problem to be solved by the present invention is to provide a master-slave communication method and system based on RS485 bus, so as to improve the real-time performance, scalability and reliability of master-slave communication.

[0007] In a first aspect, the present invention provides a master-slave communication method based on RS485 bus, comprising the following steps:

[0008] Step S10, setting a master station request frame format, a slave station response frame format and a field priority;

[0009] Step S20: The master station generates a data acquisition request based on the master station request frame format and field priority, and sends the data acquisition request to the corresponding slave station based on the RS485 bus;

[0010] Step S30: The slave station receives and parses the data acquisition request, obtains the real-time field parameters, the extended field parameters, and the first verification code, and verifies the real-time field parameters and the extended field parameters using the first verification code;

[0011] Step S40: The slave station generates real-time field data and extended field data based on the real-time field parameters and extended field parameters, generates a data response based on the real-time field data, extended field data and the slave station response frame format and sends it to the master station, completing the communication between the master station and the slave station.

[0012] Furthermore, in step S10, the master station request frame format includes the slave station address, function code, first data and first check code; the slave station response frame format includes the slave station address, function code, second data and second check code;

[0013] The length of the slave address is 1 byte; the length of the function code is 1 byte; the length range of the first data and the second data are both 0 to 252 bytes; the length of the first check code and the second check code are both 2 bytes; the first data includes the real-time field starting address, the number of real-time fields, the extension field starting address, and the number of extension fields; the number of real-time fields is greater than the number of extension fields; the second data includes the number of bytes read in the real-time field, the value of the real-time field, the number of bytes read in the extension field, and the value of the number of extension fields; the first check code and the second check code are the CRC16 calculated values ​​of the first data and the second data respectively;

[0014] The field priority is used to distinguish whether the field type is a real-time field or an extended field.

[0015] Furthermore, the step S20 is specifically as follows:

[0016] The master station distinguishes the field types of the fields to be acquired based on the field priority, generates a data acquisition request based on the master station request frame format and field type, and sends the data acquisition request to the corresponding slave station based on the RS485 bus.

[0017] Furthermore, the step S30 is specifically as follows:

[0018] The slave station receives and parses the data acquisition request, obtains real-time field parameters including the real-time field starting address and the number of real-time fields, extended field parameters including the extended field starting address and the number of extended fields, and a first check code, performs CRC16 calculation on the real-time field parameters and the extended field parameters to obtain a third check code, and determines whether the third check code is equal to the first check code. If so, the check is successful and enters step S40; if not, the check fails and the process ends.

[0019] Furthermore, the step S40 is specifically as follows:

[0020] The slave station generates, based on the real-time field parameters and the extended field parameters, real-time field data including the number of bytes read in the real-time field and the real-time field value, and extended field data including the number of bytes read in the extended field and the extended field number value, and performs a CRC16 calculation on the real-time field data and the extended field data to obtain a second check code;

[0021] A data response is generated based on the real-time field data, the extended field data, the second check code and the slave station response frame format, and the data response is sent to the master station based on the RS485 bus to complete the communication between the master station and the slave station.

[0022] In a second aspect, the present invention provides a master-slave communication system based on RS485 bus, comprising the following modules:

[0023] A format setting module, used to set a master station request frame format, a slave station response frame format and a field priority;

[0024] A data acquisition request sending module is used for the master station to generate a data acquisition request based on the master station request frame format and field priority, and send the data acquisition request to the corresponding slave station based on the RS485 bus;

[0025] a data acquisition request verification module, configured to receive and parse the data acquisition request from the station, obtain the real-time field parameters, the extended field parameters, and a first verification code, and verify the real-time field parameters and the extended field parameters using the first verification code;

[0026] The data response sending module is used for the slave station to generate real-time field data and extended field data based on the real-time field parameters and extended field parameters, and to generate a data response based on the real-time field data, extended field data and the slave station response frame format and send it to the master station to complete the communication between the master station and the slave station.

[0027] Furthermore, in the format setting module, the master station request frame format includes a slave station address, a function code, a first data, and a first check code; the slave station response frame format includes a slave station address, a function code, a second data, and a second check code;

[0028] The length of the slave address is 1 byte; the length of the function code is 1 byte; the length range of the first data and the second data are both 0 to 252 bytes; the length of the first check code and the second check code are both 2 bytes; the first data includes the real-time field starting address, the number of real-time fields, the extension field starting address, and the number of extension fields; the number of real-time fields is greater than the number of extension fields; the second data includes the number of bytes read in the real-time field, the value of the real-time field, the number of bytes read in the extension field, and the value of the number of extension fields; the first check code and the second check code are the CRC16 calculated values ​​of the first data and the second data respectively;

[0029] The field priority is used to distinguish whether the field type is a real-time field or an extended field.

[0030] Furthermore, the data acquisition request sending module is specifically used to:

[0031] The master station distinguishes the field types of the fields to be acquired based on the field priority, generates a data acquisition request based on the master station request frame format and field type, and sends the data acquisition request to the corresponding slave station based on the RS485 bus.

[0032] Furthermore, the data acquisition request verification module is specifically used to:

[0033] The slave station receives and parses the data acquisition request, obtains real-time field parameters including the real-time field starting address and the number of real-time fields, extended field parameters including the extended field starting address and the number of extended fields, and a first check code, performs CRC16 calculation on the real-time field parameters and the extended field parameters to obtain a third check code, and determines whether the third check code is equal to the first check code. If so, the check is successful and enters the data response sending module; if not, the check fails and the process ends.

[0034] Furthermore, the data response sending module is specifically used to:

[0035] The slave station generates, based on the real-time field parameters and the extended field parameters, real-time field data including the number of bytes read in the real-time field and the real-time field value, and extended field data including the number of bytes read in the extended field and the extended field number value, and performs a CRC16 calculation on the real-time field data and the extended field data to obtain a second check code;

[0036] A data response is generated based on the real-time field data, the extended field data, the second check code and the slave station response frame format, and the data response is sent to the master station based on the RS485 bus to complete the communication between the master station and the slave station.

[0037] The advantages of the present invention are:

[0038] By setting the master station request frame format, the slave station response frame format and the field priority, the field types of the fields to be obtained are divided into real-time fields and extended fields. Real-time fields are queried in real time, and extended fields are queried in polling, thereby shortening the length of the total transmission frame (data acquisition request, data response), shortening the communication cycle, improving the message transmission efficiency, avoiding communication response errors caused by communication packet sticking, and the extended fields can be set on demand, which ultimately greatly improves the real-time, scalability and reliability of master-slave communication. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0040] Figure 1 The present invention is a flow chart of a master-slave communication method based on RS485 bus.

[0041] Figure 2 The present invention is a schematic structural diagram of a master-slave communication system based on RS485 bus.

[0042] Figure 3 It is a flow chart of the interaction between the master station and the slave station of the present invention.

[0043] Figure 4 It is a signaling diagram of the interaction between the master station and the slave station of the present invention. DETAILED DESCRIPTION

[0044] The technical solution in the embodiments of the present application has the following overall idea: the field types of the fields to be obtained are divided into real-time fields and extended fields, the real-time fields are queried in real time, and the extended fields are queried in polling mode to shorten the length of the total transmission frame and avoid communication packet sticking. The extended fields can be set on demand to improve the real-time, scalability and reliability of master-slave communication.

[0045] Please refer to Figures 1 to 4 As shown, a preferred embodiment of the master-slave communication method based on RS485 bus of the present invention comprises the following steps:

[0046] Step S10, setting a master station request frame format, a slave station response frame format and a field priority;

[0047] Step S20: The master station generates a data acquisition request based on the master station request frame format and field priority, and sends the data acquisition request to the corresponding slave station based on the RS485 bus; that is, the master station divides the fields to be acquired into real-time fields and extended fields based on the field priority, performs real-time query on each of the real-time fields simultaneously, and performs polling query on each of the extended fields in sequence;

[0048] Step S30: The slave station receives and parses the data acquisition request, obtains the real-time field parameters, the extended field parameters, and the first verification code, and verifies the real-time field parameters and the extended field parameters using the first verification code;

[0049] Step S40: The slave station generates real-time field data and extended field data based on the real-time field parameters and extended field parameters, generates a data response based on the real-time field data, extended field data and the slave station response frame format and sends it to the master station, completing the communication between the master station and the slave station.

[0050] In step S10, the master station request frame format includes the slave station address, function code, first data and first check code; the slave station response frame format includes the slave station address, function code, second data and second check code;

[0051] The length of the slave address is 1 byte; the length of the function code is 1 byte; the length range of the first data and the second data are both 0 to 252 bytes; the length of the first check code and the second check code are both 2 bytes; the first data includes the real-time field starting address, the number of real-time fields, the extension field starting address, and the number of extension fields; the number of real-time fields is greater than the number of extension fields to ensure real-time performance; the second data includes the number of bytes read in the real-time field, the value of the real-time field, the number of bytes read in the extension field, and the value of the number of extension fields; the first check code and the second check code are the CRC16 calculated values ​​of the first data and the second data, respectively;

[0052] The field priority is used to distinguish whether the field type is a real-time field or an extended field.

[0053] The frame format of the traditional MODBUS-RTU protocol does not distinguish between the real-time field and the extended field. The format is as follows:

[0054] Slave address Function code data CRC check 1 byte 1 byte 0-252 bytes 2 bytes

[0055] The step S20 is specifically as follows:

[0056] The master station distinguishes the field types of the fields to be acquired based on the field priority, generates a data acquisition request based on the master station request frame format and field type, and sends the data acquisition request to the corresponding slave station via the RS485 bus. For fields with extended field types, the master station only polls and queries one field at a time, that is, the data acquisition request only queries one field with extended field type at a time to ensure real-time communication. For example, fields such as voltage and current have high real-time requirements and require real-time queries, while fields such as temperature, capacity, and energy have low real-time requirements and can be polled and queried, that is, only querying temperature first, only querying capacity second, and so on.

[0057] The step S30 is specifically as follows:

[0058] The slave station receives and parses the data acquisition request, obtains real-time field parameters including the real-time field starting address and the number of real-time fields, extended field parameters including the extended field starting address and the number of extended fields, and a first check code, performs CRC16 calculation on the real-time field parameters and the extended field parameters to obtain a third check code, and determines whether the third check code is equal to the first check code. If so, the check is successful and enters step S40; if not, the check fails and the process ends.

[0059] The step S40 is specifically as follows:

[0060] The slave station generates, based on the real-time field parameters and the extended field parameters, real-time field data including the number of bytes read in the real-time field and the real-time field value, and extended field data including the number of bytes read in the extended field and the extended field number value, and performs a CRC16 calculation on the real-time field data and the extended field data to obtain a second check code;

[0061] A data response is generated based on the real-time field data, the extended field data, the second check code and the slave station response frame format, and the data response is sent to the master station based on the RS485 bus to complete the communication between the master station and the slave station.

[0062] A preferred embodiment of the master-slave communication system based on RS485 bus of the present invention includes the following modules:

[0063] A format setting module, used to set a master station request frame format, a slave station response frame format and a field priority;

[0064] A data acquisition request sending module is configured for the master station to generate a data acquisition request based on the master station request frame format and field priority, and to send the data acquisition request to the corresponding slave station based on the RS485 bus; that is, the master station divides the fields to be acquired into real-time fields and extended fields based on the field priority, performs real-time query on each of the real-time fields simultaneously, and performs polling query on each of the extended fields in sequence;

[0065] a data acquisition request verification module, configured to receive and parse the data acquisition request from the station, obtain the real-time field parameters, the extended field parameters, and a first verification code, and verify the real-time field parameters and the extended field parameters using the first verification code;

[0066] The data response sending module is used for the slave station to generate real-time field data and extended field data based on the real-time field parameters and extended field parameters, and to generate a data response based on the real-time field data, extended field data and the slave station response frame format and send it to the master station to complete the communication between the master station and the slave station.

[0067] In the format setting module, the master station request frame format includes the slave station address, function code, first data and first check code; the slave station response frame format includes the slave station address, function code, second data and second check code;

[0068] The length of the slave address is 1 byte; the length of the function code is 1 byte; the length range of the first data and the second data are both 0 to 252 bytes; the length of the first check code and the second check code are both 2 bytes; the first data includes the real-time field starting address, the number of real-time fields, the extension field starting address, and the number of extension fields; the number of real-time fields is greater than the number of extension fields to ensure real-time performance; the second data includes the number of bytes read in the real-time field, the value of the real-time field, the number of bytes read in the extension field, and the value of the number of extension fields; the first check code and the second check code are the CRC16 calculated values ​​of the first data and the second data, respectively;

[0069] The field priority is used to distinguish whether the field type is a real-time field or an extended field.

[0070] The frame format of the traditional MODBUS-RTU protocol does not distinguish between the real-time field and the extended field. The format is as follows:

[0071] Slave address Function code data CRC check 1 byte 1 byte 0-252 bytes 2 bytes

[0072] The data acquisition request sending module is specifically used to:

[0073] The master station distinguishes the field types of the fields to be acquired based on the field priority, generates a data acquisition request based on the master station request frame format and field type, and sends the data acquisition request to the corresponding slave station via the RS485 bus. For fields with extended field types, the master station only polls and queries one field at a time, that is, the data acquisition request only queries one field with extended field type at a time to ensure real-time communication. For example, fields such as voltage and current have high real-time requirements and require real-time queries, while fields such as temperature, capacity, and energy have low real-time requirements and can be polled and queried, that is, only querying temperature first, only querying capacity second, and so on.

[0074] The data acquisition request verification module is specifically used to:

[0075] The slave station receives and parses the data acquisition request, obtains real-time field parameters including the real-time field starting address and the number of real-time fields, extended field parameters including the extended field starting address and the number of extended fields, and a first check code, performs CRC16 calculation on the real-time field parameters and the extended field parameters to obtain a third check code, and determines whether the third check code is equal to the first check code. If so, the check is successful and enters the data response sending module; if not, the check fails and the process ends.

[0076] The data response sending module is specifically used for:

[0077] The slave station generates, based on the real-time field parameters and the extended field parameters, real-time field data including the number of bytes read in the real-time field and the real-time field value, and extended field data including the number of bytes read in the extended field and the extended field number value, and performs a CRC16 calculation on the real-time field data and the extended field data to obtain a second check code;

[0078] A data response is generated based on the real-time field data, the extended field data, the second check code and the slave station response frame format, and the data response is sent to the master station based on the RS485 bus to complete the communication between the master station and the slave station.

[0079] To facilitate understanding of the present invention, an example of interaction between a master station and a slave station is given below:

[0080] When the host initiates a data acquisition request, the slave communicates in real time according to the master request frame format and the slave response frame format to ensure that the data response to the host complies with the MODBUS-RTU protocol, as follows:

[0081] S001: [voltage 1, voltage 2, current] [extension 1: temperature]

[0082] S002: [Voltage 1, Voltage 2, Current] [Extension 2: Capacity]

[0083]

[0084] SOOn: [voltage 1, voltage 2, current] [extended n: energy]

[0085] Among them, [Voltage 1], [Voltage 2], and [Current] are real-time fields and should be included in each query and reply process. [Temperature], [Capacity], and [Energy] are extended fields. When the master station queries non-real-time fields, it only queries one extended field per round (the number of extended fields can be configured as needed in actual applications). After the query is completed, the query is restarted.

[0086] When the data acquisition request sent by the host is a register query request, the first round of query requests can be: the host ID is 1 (corresponding to byte 0x01), and the real-time field and extended field are read respectively (function code is 0x03). It is assumed that the real-time fields [voltage 1], [voltage 2], and [current] to be read are the data stored in three consecutive registers, with the starting address 0x00 0x01, and the starting addresses of the extended fields [temperature], [capacity], and [energy] are 0x00 0x10, 0x00 0x11, and 0x00 0x12 respectively.

[0087] During S001, the data acquisition request sent by the host is "0x01 0x03 0x00 0x01 0x00 0x03 0x00 0x10 0x00 0x01 0x** 0x**". The meaning of this data acquisition request is "to read the three consecutive register data starting at address 0x00 0x01 (real-time fields [voltage 1], [voltage 2], [current]) and the one register data starting at 0x00 0x10 (extended field [temperature]). The last two bytes are the checksum calculated by CRC16.

[0088] Similarly, the data acquisition request sent by the host during S002 is "Ox01 0x03 0x00 0x01 0x000x03 0x00 0x11 0x00 0x01 0x** 0x**". The meaning of this data acquisition request is "to read the three consecutive register data starting at address 0x00 0x01 (real-time fields [voltage 1], [voltage 2], [current]) and the one register data starting at address 0x00 0x11 (extended field [capacity]). The last two bytes are the checksum calculated by CRC16.

[0089] The data response sent by the slave is a register data reply instruction. In the first round of reply instructions, the data of [voltage 1], [voltage 2], and [current] are "0x1E 0x1F", "0x2E 0x2F", and "0x3E 0x3F" respectively, and the data of the extended field [temperature] is "0x4E 0x4F". The instruction can be: "0x01 0x03 0x06 0x1E 0x1F 0x2E 0x2F 0x3E 0x3F 0x020x4E 0x4F 0x** 0x**", "0x06" is the number of bytes read in the real-time field, and the three real-time field registers have a total of 6 bytes; "0x1E 0x1F 0x2E 0x2F 0x3E 0x3F" is the real-time field data; "0x02" is the number of bytes read in the extended field, and one extended field register has a total of 2 bytes; "0x4E 0x4F" is the extended field data.

[0090] Similarly, in the second round of reply instructions, the data of [voltage 1], [voltage 2], and [current] are "0x5E 0x5F", "0x6E 0x6F", and "0x7E 0x7F" respectively, and the data of the extended field [capacity] is "0x8E 0x8F". The instruction can be: "0x01 0x03 0x06 0x5E 0x5F 0x6E 0x6F 0x7E 0x7F 0x02 0x8E 0x8F 0x** 0x**", "0x06" is the number of bytes of the real-time field read, and the three real-time field registers have a total of 6 bytes; "0x5E 0x5F 0x6E 0x6F 0x7E 0x7F" is the real-time field data; "0x02" is the number of bytes of the extended field read, and one extended field register has a total of 2 bytes; "0x8E 0x8F" is the extended field data.

[0091] The S00n process polling is analogous to the above content. It should be noted that the register addresses applied above cannot be repeated, otherwise the values ​​of the transferred registers will be confused.

[0092] In summary, the advantages of the present invention are:

[0093] By setting the master station request frame format, the slave station response frame format and the field priority, the field types of the fields to be obtained are divided into real-time fields and extended fields. Real-time fields are queried in real time, and extended fields are queried in polling, thereby shortening the length of the total transmission frame (data acquisition request, data response), shortening the communication cycle, improving the message transmission efficiency, avoiding communication response errors caused by communication packet sticking, and the extended fields can be set on demand, which ultimately greatly improves the real-time, scalability and reliability of master-slave communication.

[0094] Although the specific embodiments of the present invention are described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included within the scope of protection of the claims of the present invention.

Claims

1. A master-slave communication method based on RS485 bus, characterized in that: The steps include: Step S10, setting a master station request frame format, a slave station response frame format and a field priority; The master station request frame format includes the slave station address, function code, first data and first check code; the slave station response frame format includes the slave station address, function code, second data and second check code; The length of the slave address is 1 byte; the length of the function code is 1 byte; the length range of the first data and the second data are both 0 to 252 bytes; the length of the first check code and the second check code are both 2 bytes; the first data includes the real-time field starting address, the number of real-time fields, the extension field starting address, and the number of extension fields; the number of real-time fields is greater than the number of extension fields; the second data includes the number of bytes read in the real-time field, the value of the real-time field, the number of bytes read in the extension field, and the value of the number of extension fields; the first check code and the second check code are the CRC16 calculated values ​​of the first data and the second data respectively; The field priority is used to distinguish whether the field type is a real-time field or an extended field; Step S20: The master station distinguishes the field type of the field to be acquired based on the field priority, generates a data acquisition request based on the master station request frame format and field type, and sends the data acquisition request to the corresponding slave station based on the RS485 bus; Step S30: The slave station receives and parses the data acquisition request, obtains real-time field parameters including a real-time field starting address and a number of real-time fields, extended field parameters including an extended field starting address and a number of extended fields, and a first check code, performs a CRC16 calculation on the real-time field parameters and the extended field parameters to obtain a third check code, and determines whether the third check code is equal to the first check code. If so, the check is successful, and the process proceeds to step S40. If not, the verification fails and the process ends; Step S40: The slave station generates, based on the real-time field parameters and the extended field parameters, real-time field data including the number of bytes read in the real-time field and the real-time field value, and extended field data including the number of bytes read in the extended field and the extended field value, and performs a CRC16 calculation on the real-time field data and the extended field data to obtain a second check code. A data response is generated based on the real-time field data, the extended field data, the second check code and the slave station response frame format, and the data response is sent to the master station based on the RS485 bus to complete the communication between the master station and the slave station.

2. A master-slave communication system based on RS485 bus, characterized by: Includes the following modules: A format setting module, used to set a master station request frame format, a slave station response frame format and a field priority; The master station request frame format includes the slave station address, function code, first data and first check code; the slave station response frame format includes the slave station address, function code, second data and second check code; The length of the slave address is 1 byte; the length of the function code is 1 byte; the length range of the first data and the second data are both 0 to 252 bytes; the length of the first check code and the second check code are both 2 bytes; the first data includes the real-time field starting address, the number of real-time fields, the extension field starting address, and the number of extension fields; the number of real-time fields is greater than the number of extension fields; the second data includes the number of bytes read in the real-time field, the value of the real-time field, the number of bytes read in the extension field, and the value of the number of extension fields; the first check code and the second check code are the CRC16 calculated values ​​of the first data and the second data respectively; The field priority is used to distinguish whether the field type is a real-time field or an extended field; A data acquisition request sending module is used for the master station to distinguish the field type of the field to be acquired based on the field priority, generate a data acquisition request based on the master station request frame format and field type, and send the data acquisition request to the corresponding slave station based on the RS485 bus; a data acquisition request verification module, configured to receive and parse the data acquisition request from the station, obtain real-time field parameters including a real-time field starting address and a number of real-time fields, extended field parameters including an extended field starting address and a number of extended fields, and a first check code, perform a CRC16 calculation on the real-time field parameters and the extended field parameters to obtain a third check code, determine whether the third check code is equal to the first check code, and if so, determine that the verification is successful, and enter the data response sending module; If not, the verification fails and the process ends; a data response sending module, configured to generate, from the station, real-time field data including the number of bytes read in the real-time field and the value of the real-time field, and extended field data including the number of bytes read in the extended field and the value of the extended field number, based on the real-time field parameters and the extended field parameters, and perform CRC16 calculation on the real-time field data and the extended field data to obtain a second check code; A data response is generated based on the real-time field data, the extended field data, the second check code and the slave station response frame format, and the data response is sent to the master station based on the RS485 bus to complete the communication between the master station and the slave station.

Citation Information

Patent Citations

  • Multifunctional communication method for integrated variable frequency motor

    CN105404181A

  • High-efficiency and high-bandwidth communication method and system

    CN111478838A