RS485 serial port data mapping device and method based on Modbus
By designing the RS485 serial port data mapping device in the Modbus protocol, using the microcontroller unit and data mapping program to collect communication data of the master and slave devices in real time, solving the problem of low debugging and maintenance efficiency in the existing technology, and realizing the communication situation Real-time monitoring and problem discovery have improved the efficiency of industrial control.
Patent Information
- Application Number
- CN202110344080.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-31
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2041-03-31
AI Technical Summary
In the field of industrial control and power communication, the existing RS485 serial communication method of the Modbus protocol has low debugging and maintenance efficiency due to the limitations of exclusiveness. It cannot understand the data communication between the master and slave devices in real time, and requires expensive data gateways. Hardware to support data extraction for multi-master devices.
Design a RS485 serial port data mapping device based on Modbus, using the microcontroller unit, RS485 communication interface and storage area, to collect communication data between master and slave devices in real time through data mapping and subcontracting programs, and provide data acquisition terminal reading and storage function to realize real-time monitoring of communication situation.
By collecting communication data from master and slave devices in real time, problems can be discovered in a timely manner, debugging and maintenance efficiency can be significantly improved, the dependence of expensive hardware is avoided, and the data exchange process is simplified.
Smart Images

Figure CN115145849B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of industrial communication, and in particular to a RS485 serial port data mapping device and method based on Modbus. Background Art
[0002] In the fields of industrial control, power communication, intelligent instruments, etc., serial communication is usually used for data exchange. The original method was the RS232 interface. In 1979, Schneider Electric developed a bus protocol Modbus protocol for industrial sites. The Modbus protocol is a universal language used in electronic controllers. Because the protocol is standard and open, users can use it for free and without paying license fees, and it will not infringe intellectual property rights. Therefore, it has become a universal industrial standard.
[0003] Modbus protocol data communication adopts master-slave mode. The master device sends a data request message. After receiving the correct message, the slave device replies to the master device in response to the request. Each slave device has an independent ID. Modbus can support multiple electrical interfaces, such as RS-232, RS-485, etc. The standard value of the maximum transmission distance of RS232 is 15 meters, and it can only communicate point-to-point. In theory, up to 247 slave devices can be supported in the RS-485 communication link, and the theoretical maximum wireless transmission distance of RS485 is 1200 meters. Therefore, most of the Modbus protocol used in industry now uses the RS485 interface.
[0004] In actual use, since the serial port is used exclusively, that is, there is only one application instance that can open, read and write to a serial port. Under normal circumstances, a slave device can only respond to one master device. If two master devices need to extract data information from a slave device, expensive data gateway hardware needs to be configured separately. Moreover, when debugging and maintaining link communication, it is impossible to understand the data communication status between the master device and the slave device in order to diagnose the problem, which greatly affects the debugging and maintenance efficiency. Summary of the invention
[0005] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a RS485 serial port data mapping device and method based on Modbus, which can accurately understand the data communication situation between the master device and the slave device by real-time acquisition of communication data between the master and slave devices, so as to find problems, thereby greatly improving the debugging and maintenance efficiency.
[0006] The technical solution of the present invention is as follows:
[0007] A RS485 serial port data mapping device based on Modbus, the device is applied to data mapping of data communication between master and slave devices in Modbus protocol data communication, the device is composed of a micro control unit, a first RS485 communication interface and a second RS485 communication interface, the first RS485 communication interface is connected to the micro control unit and is used to access a communication network that needs to be mapped with data, the second RS485 communication interface is connected to the micro control unit and is used to connect to an external data acquisition terminal, the micro control unit includes a processor, and the processor is divided into a plurality of storage areas, namely, area 0, area 1, area 3 and area 4;
[0008] The 4 areas are holding registers, which are used to store the Modbus address, Modbus area, register address and data type of the device requiring data mapping;
[0009] The 3rd area is an input register, which is used to store mapping data for reading by the data acquisition terminal;
[0010] The zone 1 is a discrete input register, which is used to initialize and judge whether the set parameters can perform data mapping normally;
[0011] The zone 0 is the coil, which is the read-write protection bit of zone 0 and zone 4, and is used to control whether the corresponding register enables data mapping.
[0012] Furthermore, the microcontroller unit also includes a flash memory, an electrically erasable programmable read-only memory and a static random access memory;
[0013] The flash memory is connected to the processor and is used for program storage;
[0014] The electrically erasable programmable read-only memory is connected to the processor and is used for storing setting parameters and storing collected data after power failure;
[0015] The static random access memory is connected to the processor and is used for storing mapping data.
[0016] Furthermore, the device uses an external power source to provide power to the micro control unit.
[0017] Furthermore, the device also includes a super capacitor, which is connected to the power supply circuit of the external power supply and the micro control unit, and is used to provide power for the electrically erasable programmable read-only memory to save data after the external power supply is powered off.
[0018] A data mapping method based on the above-mentioned Modbus-based RS485 serial port data mapping device:
[0019] According to the holding registers in zone 4:
[0020] 40001: Set the Modbus address of the second RS485 communication interface;
[0021] 40002: Set the baud rate of the second RS485 communication interface;
[0022] 40003: Set the parity check of the second RS485 communication interface;
[0023] 40004: Set the baud rate of the first RS485 communication interface;
[0024] 40005: Set the parity check of the first RS485 communication interface;
[0025] 41001~41100: 100, used to store the Modbus addresses of devices that need data mapping;
[0026] 41101~41200: 100, used to store the Modbus area of the device that needs data mapping;
[0027] 41201~41300: 100, used to store the register address of the device that needs data mapping;
[0028] 41301~41400: 100, used to store data types;
[0029] According to the input register of zone 3:
[0030] 30001~30200: 2 registers are grouped together, each group has 4 bytes. The data type of each group in this area is determined by the settings of 41301~41400 in area 4. When it is 32-bit data, the default is that the lower 16 bytes are in front. If it is a single bit or 16-bit data, it is stored in the lower bit of the group by default.
[0031] According to the discrete input registers in Area 1:
[0032] 11001~11100: 100, the default value is 0. When data mapping can be performed normally, the corresponding bit will be set to 1 to initialize and determine whether the set parameters can perform data mapping normally;
[0033] According to the coil in zone 0:
[0034] 00001: Read / write protection bit of area 0 and area 4. When it is 1, area 4 and area 0 are readable and writable. When it is 0, area 4 and area 0 are read-only.
[0035] 01001~01100: Whether the corresponding register enables data mapping control bit. When it is 1, data mapping is enabled, and when it is 0, data mapping is not enabled;
[0036] The Modbus address, Modbus area, register address and data type of the device that needs data mapping are defined as a setting group. When the master device sends a data request to the slave device and the slave device responds, the data mapping device stores the mapped data in the registers of Zone 3 through the data packetization program for the data acquisition terminal to read. Through the request and response process between the master device and the slave device, the data in the registers of Zone 3 will be continuously updated. The data acquisition terminal can collect the data of the device that needs data mapping in real time through the data reading program.
[0037] Among them, the settings of 40002 and 40004 in zone 4 are 0:1200, 1:2400, 2:4800, 3:9600; 4:14400; 5:19200, and the default is 9600.
[0038] Among them, the settings of 40003 and 40005 in zone 4 are 0: no check, 1: odd check, 2: even check, and the default is no check.
[0039] Among them, the 100 settings of 41001 to 41100, 41101 to 41200, 41201 to 41300, and 41301 to 41400 in zone 4 are 16-bit unsigned integers.
[0040] Among them, the settings of 41101~41200 in zone 4 can be set to 0, 1, 3, 4, and the default is 0.
[0041] Among them, the default setting for zone 4, 41201~41300 and 41301~41400, is 0.
[0042] Compared with the prior art, the beneficial effect of the present invention is that the present invention is used in Modbus protocol data communication, and the communication data between the master and slave devices is collected in real time through data mapping of data communication between the master and slave devices. The present invention can be used to understand the data communication situation between the master and slave devices at any time, so as to find problems, thereby greatly improving the debugging and maintenance efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 A block diagram of a Modbus-based RS485 serial port data mapping device provided by the present invention;
[0045] Figure 2 One of the application block diagrams of the RS485 serial port data mapping device based on Modbus provided by the present invention;
[0046] Figure 3 The second application block diagram of the RS485 serial port data mapping device based on Modbus provided by the present invention;
[0047] Figure 4 The third application block diagram of the RS485 serial port data mapping device based on Modbus provided by the present invention. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0049] In order to illustrate the technical solution of the present invention, a specific embodiment is provided below for illustration.
[0050] The present invention provides a Modbus-based RS485 serial port data mapping device, which is applied to Modbus protocol data communication, and collects the communication data between the master and slave devices in real time through data mapping of data communication between the master and slave devices. Figure 1 , which is mainly composed of a micro control unit, a first RS485 communication interface, a second RS485 communication interface and a super capacitor. The micro control unit includes a processor, a flash memory, a powered erasable programmable read-only memory and a static random access memory. Figure 2 As shown, the first RS485 communication interface is connected to the micro control unit for accessing the communication network that needs data mapping, and the second RS485 communication interface is connected to the micro control unit for connecting to an external data acquisition terminal.
[0051] The processor is divided into several storage areas, namely area 0, area 1, area 3 and area 4.
[0052] The 4 areas are holding registers for storing the Modbus address, Modbus area, register address and data type of the device requiring data mapping.
[0053] The 3rd area is an input register, which is used to store mapping data for reading by the data acquisition terminal.
[0054] The zone 1 is a discrete input register, which is used to initialize and determine whether the set parameters can perform data mapping normally.
[0055] The zone 0 is the coil, which is the read / write protection bit of zone 0 and zone 4, and is used to control whether the corresponding register enables data mapping.
[0056] The flash memory is connected to the processor and is used for program storage.
[0057] The electrically erasable programmable read-only memory is connected to the processor and is used for storing setting parameters and storing collected data after power failure.
[0058] The static random access memory is connected to the processor and is used for storing mapping data.
[0059] The device uses an external power supply to provide power to a microcontroller unit. The supercapacitor is connected to a power supply circuit between the external power supply and the microcontroller unit to provide power to a powered erasable programmable read-only memory for data storage after the external power supply is turned off.
[0060] The following is the data mapping method for this device:
[0061] According to the holding registers in zone 4:
[0062] 40001: Set the Modbus address of the second RS485 communication interface;
[0063] 40002: Set the baud rate of the second RS485 communication interface, 0: 1200, 1: 2400, 2: 4800, 3: 9600; 4: 14400; 5: 19200, the default is 9600;
[0064] 40003: Set the parity check of the second RS485 communication interface, 0: no check, 1: odd check, 2: even check, the default is no check;
[0065] 40004: Set the baud rate of the first RS485 communication interface, 0: 1200, 1: 2400, 2: 4800, 3: 9600; 4: 14400; 5: 19200, the default is 9600;
[0066] 40005: Set the parity check of the first RS485 communication interface, 0: no check, 1: odd check, 2: even check, the default is no check;
[0067] 41001~41100: 100, 16-bit unsigned integer, used to store the Modbus address of the device that needs data mapping;
[0068] 41101~41200: 100, 16-bit unsigned integer, used to store in the Modbus area of the device that needs data mapping, can be set to 0, 1, 3, 4, the default is 0;
[0069] 41201~41300: 100, 16-bit unsigned integer, used to store the register address of the device that needs data mapping, the default is 0;
[0070] 41301~41400: 100, 16-bit unsigned integer, used to store data types, default is 0;
[0071] The setting values correspond to the following:
[0072] 0: bit; 1: 16-bit unsigned integer; 2: 16-bit signed integer; 3: 32-bit unsigned integer; 4: 32-bit signed integer; 5: 32-bit floating point;
[0073] According to the input register of zone 3:
[0074] 30001~30200: 2 registers are grouped together, each group has 4 bytes. The data type of each group in this area is determined by the settings of 41301~41400 in Area 4. When it is 32-bit data, the default is that the lower 16 bytes are in front. If it is a single bit or 16-bit data, it is stored in the lower bit of the group by default. For example, address 0 and address 1 are a group. When it is 32-bit data, both registers 0 and 1 need to be used; if it is 16-bit data, only register 0 is used;
[0075] According to the discrete input registers in Area 1:
[0076] 11001~11100: 100, the default value is 0. When data mapping can be performed normally, the corresponding bit will be set to 1 to initialize and determine whether the set parameters can perform data mapping normally;
[0077] According to the coil in zone 0:
[0078] 00001: Read / write protection bit of area 0 and area 4. When it is 1, area 4 and area 0 are readable and writable. When it is 0, area 4 and area 0 are read-only.
[0079] 01001~01100: Whether the corresponding register enables data mapping control bit. When it is 1, data mapping is enabled, and when it is 0, data mapping is not enabled;
[0080] The Modbus address, Modbus area, register address and data type of the device that needs data mapping are defined as a setting group. When the master device sends a data request to the slave device and the slave device responds, the data mapping device stores the mapped data in the registers of Zone 3 through the data packetization program for the data acquisition terminal to read. Through the request and response process between the master device and the slave device, the data in the registers of Zone 3 will be continuously updated. The data acquisition terminal can collect the data of the device that needs data mapping in real time through the data reading program.
[0081] Example: The slave device is a smart meter, the Modbus address of the meter is set to 3, and the register address and register content of the meter are as follows:
[0082] Zone 4
[0083] 40101: Phase A voltage, 16-bit unsigned integer;
[0084] 40201, 40202: active energy, 32-bit unsigned integer;
[0085] Zone 3
[0086] 30301, 30302: power factor, 32-bit floating point number;
[0087] The data mapping device makes the following parameter settings:
[0088] Zone 4:
[0089] 41001: set to 3; (Modbus address)
[0090] 41101: Set to 4; (Modbus zone 4)
[0091] 41201: set to 100; (A phase voltage register address)
[0092] 41301: set to 1; (16-bit unsigned)
[0093] 41002: Set to 3; (Modbus address)
[0094] 41102: Set to 4; (Modbus zone 4)
[0095] 41202: set to 200; (active energy register address)
[0096] 41302: set to 3; (32-bit unsigned integer)
[0097] 41003: set to 3; (Modbus address)
[0098] 41103: Set to 3; (Modbus zone 3)
[0099] 41203: Set to 300; (Power factor register address)
[0100] 41303: set to 5; (32-bit floating point number)
[0101] Zone 0:
[0102] 01001: Set to 1; (enable data mapping of phase A voltage)
[0103] 01002: Set to 1; (Enable data mapping of active energy)
[0104] 01003: Set to 1; (Enable data mapping of power factor)
[0105] A data mapping device can be configured with a total of 100 registers. When the registers of a data mapping device are not enough, you can Figure 3 , Figure 4 To increase the number of devices, just set the data mapping device to a different address; it also supports multiple terminals to collect data separately.
[0106] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A RS485 serial port data mapping device based on Modbus, Features: The device is applied to data mapping of data communication between master and slave devices in Modbus protocol data communication, and is composed of a micro control unit, a first RS485 communication interface and a second RS485 communication interface, wherein the first RS485 communication interface is connected to the micro control unit and is used to access a communication network that needs to be mapped with data, and the second RS485 communication interface is connected to the micro control unit and is used to connect to an external data acquisition terminal, and the micro control unit includes a processor, and the processor is divided into a plurality of storage areas, namely, area 0, area 1, area 3 and area 4; The 4 areas are holding registers, which are used to store the Modbus address, Modbus area, register address and data type of the device requiring data mapping; The 3rd area is an input register for storing mapping data. When the master device sends a data request to the slave device and the slave device responds, the data mapping device stores the mapped data in the registers of the 3rd area respectively through a data packetization program for the data acquisition terminal to read. The zone 1 is a discrete input register, which is used to initialize and judge whether the set parameters can perform data mapping normally; The zone 0 is the coil, which is the read-write protection bit of zone 0 and zone 4, and is used to control whether the corresponding register enables data mapping.
2. The RS485 serial port data mapping device based on Modbus according to claim 1, Features: The microcontroller unit also includes a flash memory, an electrically erasable programmable read-only memory and a static random access memory; The flash memory is connected to the processor and is used for program storage; The electrically erasable programmable read-only memory is connected to the processor and is used for storing setting parameters and storing collected data after power failure; The static random access memory is connected to the processor and is used for storing mapping data.
3. The RS485 serial port data mapping device based on Modbus according to claim 2, Features: The device uses an external power source to provide power to the micro control unit.
4. The RS485 serial port data mapping device based on Modbus according to claim 3, Features: The device also includes a super capacitor, which is connected to the power supply circuit of the external power supply and the micro control unit, and is used to provide power for the electrically erasable programmable read-only memory to save data after the external power supply is powered off.
5. A data mapping method based on the RS485 serial port data mapping device based on Modbus according to any one of claims 1 to 4, Features: According to the holding registers in zone 4: 40001: Set the Modbus address of the second RS485 communication interface; 40002: Set the baud rate of the second RS485 communication interface; 40003: Set the parity check of the second RS485 communication interface; 40004: Set the baud rate of the first RS485 communication interface; 40005: Set the parity check of the first RS485 communication interface; 41001~41100: 100, used to store the Modbus addresses of devices that need data mapping; 41101~41200: 100, used to store the Modbus area of the device that needs data mapping; 41201~41300: 100, used to store the register address of the device that needs data mapping; 41301~41400: 100, used to store data types; According to the input register of zone 3: 30001~30200: 2 registers are grouped together, each group has 4 bytes. The data type of each group in this area is determined by the settings of 41301~41400 in area 4. When it is 32-bit data, the default is that the lower 16 bytes are in front. If it is a single bit or 16-bit data, it is stored in the lower bit of the group by default. According to the discrete input registers in Area 1: 11001~11100: 100, the default value is 0. When data mapping can be performed normally, the corresponding bit will be set to 1 to initialize and determine whether the set parameters can perform data mapping normally; According to the coil in zone 0: 00001: Read / write protection bit of area 0 and area 4. When it is 1, area 4 and area 0 are readable and writable. When it is 0, area 4 and area 0 are read-only. 01001~01100: Whether the corresponding register enables data mapping control bit. When it is 1, data mapping is enabled, and when it is 0, data mapping is not enabled; The Modbus address, Modbus area, register address and data type of the device that needs data mapping are defined as a setting group. When the master device sends a data request to the slave device and the slave device responds, the data mapping device stores the mapped data in the registers of Zone 3 through the data packetization program for the data acquisition terminal to read. Through the request and response process between the master device and the slave device, the data in the registers of Zone 3 will be continuously updated. The data acquisition terminal can collect the data of the device that needs data mapping in real time through the data reading program.
6. The RS485 serial port data mapping method based on Modbus according to claim 5, Features: In the settings of 40002 and 40004 in zone 4, 0:1200, 1:2400, 2:4800, 3:9600; 4: 14400; 5: 19200, the default is 9600.
7. The RS485 serial port data mapping method based on Modbus according to claim 5, Features: In the settings of 40003 and 40005 in zone 4, 0: no check, 1: odd check, 2: even check, the default is no check.
8. The RS485 serial port data mapping method based on Modbus according to claim 5, Features: The 100 settings of 41001 to 41100, 41101 to 41200, 41201 to 41300, and 41301 to 41400 in zone 4 are 16-bit unsigned integers.
9. The RS485 serial port data mapping method based on Modbus according to claim 5, Features: In the settings of 41101 to 41200 in zone 4, you can set 0, 1, 3, or 4. The default setting is 0.
10. The RS485 serial port data mapping method based on Modbus according to claim 5, Features: The default setting for the settings of 41201 to 41300 and 41301 to 41400 in zone 4 is 0.
