CN113676280A - Multi-device clock synchronization method based on Modbus protocol - Google Patents
Multi-device clock synchronization method based on Modbus protocol Download PDFInfo
- Publication number
- CN113676280A CN113676280A CN202110999588.6A CN202110999588A CN113676280A CN 113676280 A CN113676280 A CN 113676280A CN 202110999588 A CN202110999588 A CN 202110999588A CN 113676280 A CN113676280 A CN 113676280A
- Authority
- CN
- China
- Prior art keywords
- time
- master device
- slave
- slave device
- master
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
- H04J3/0658—Clock or time synchronisation among packet nodes
- H04J3/0661—Clock or time synchronisation among packet nodes using timestamps
- H04J3/0667—Bidirectional timestamps, e.g. NTP or PTP for compensation of clock drift and for compensation of propagation delays
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/40006—Architecture of a communication node
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/12—Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02P—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
- Y02P90/00—Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
- Y02P90/02—Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]
Abstract
The invention discloses a multi-device clock synchronization method based on a Modbus protocol, which is used for an Internet of things system in which at least one slave device communicates with a master device through the Modbus protocol, and comprises the following steps: the master device sends the current time stamp to the slave device, and receives the time stamp sent by the slave device to the master device; calculating a time offset between the master device and the slave device; the master device sends the time offset to the slave device, and the slave device corrects the current timestamp according to the time offset after receiving the time offset to complete time synchronization; the time synchronization between the devices without Ethernet connection is realized, and the application range is wide.
Description
Technical Field
The invention relates to the technical field of time synchronization of the Internet of things, in particular to a multi-device clock synchronization method based on a Modbus protocol.
Background
In the data acquisition process of the internet of things, different data are acquired by different data acquisition units, but the time of the data is often required to be aligned when the acquired data are processed; in the prior art, protocols such as ntp and ptp are used for time synchronization, but the protocols are all implemented based on ethernet, most data collectors do not have an ethernet communication interface, and how to perform time synchronization on the devices is difficult.
Disclosure of Invention
In view of the existing defects, the invention provides a multi-device clock synchronization method based on a Modbus protocol, which realizes time synchronization among devices without Ethernet connection and has wide application range.
In order to achieve the above purpose, the embodiment of the invention adopts the following technical scheme:
a multi-device clock synchronization method based on a Modbus protocol is used for an Internet of things system with at least one slave device communicating with a master device through the Modbus protocol, and comprises the following steps:
the master device sends the current time stamp to the slave device, and receives the time stamp sent by the slave device to the master device;
calculating a time offset between the master device and the slave device;
and the master equipment sends the time offset to the slave equipment, and the slave equipment corrects the current timestamp according to the time offset after receiving the time offset to finish time synchronization.
According to one aspect of the invention, the steps of the Modbus protocol-based multi-device clock synchronization method are performed by specific commands.
According to an aspect of the present invention, the specific command includes an offset estimation command for estimating a communication delay between the master device and the slave device and a time synchronization command for synchronizing the slave device clock to the master device clock by the master device.
According to an aspect of the invention, the master device sends the current time stamp to the slave device, while the step of receiving the time stamp sent by the slave device to the master device is performed a plurality of times.
In accordance with an aspect of the invention, the calculating the time offset between the master device and the slave device comprises:
the master device transmits the current time mt1 to the slave device;
the slave device transmits a charging time st1 to the master device;
the master device transmits a charging time mt2 to the slave device after receiving st 1;
the slave device transmits a charging time st2 to the master device after receiving mt 2;
the master device records the receiving time as mt3 after receiving st2, and calculates the time offset between the master device and the slave device;
the time offset is [ st1+ st2-mt2- (mt1+ mt3)/2 ]/2.
According to one aspect of the present invention, the master device transmits a time offset to the slave device, and the slave device corrects the current timestamp according to the time offset after receiving the time offset, and the time synchronization is performed by:
the master device transmits the time offset to the slave device;
the slave device calculates a set timestamp st3-offset from the current timestamp st3 and the received time offset, and sets the current timestamp to st.
According to one aspect of the invention, the Modbus protocol-based multi-device clock synchronization method comprises the following steps: and the master device is respectively time-synchronized with the plurality of slave devices according to the device IDs of different slave devices Modbus protocols.
In accordance with an aspect of the invention, the calculating the time offset between the master device and the slave device comprises:
the master device transmits the current time mt1 to the slave device through an offset measurement command;
after receiving the offset measurement command, the slave device sends a receiving time st1 to the master device;
the master device transmits a charging time mt2 to the slave device after receiving st 1;
the slave device transmits a charging time st2 to the master device after receiving mt 2;
the master device records the receiving time as mt3 after receiving st2, and calculates the time offset between the master device and the slave device;
the time offset is [ st1+ st2-mt2- (mt1+ mt3)/2 ]/2.
The implementation of the invention has the advantages that: the invention discloses a multi-device clock synchronization method based on a Modbus protocol, which is used for an Internet of things system in which at least one slave device communicates with a master device through the Modbus protocol, and comprises the following steps: the master device sends the current time stamp to the slave device, and receives the time stamp sent by the slave device to the master device; calculating a time offset between the master device and the slave device; the master device sends the time offset to the slave device, and the slave device corrects the current timestamp according to the time offset after receiving the time offset to complete time synchronization; the time synchronization between the devices without Ethernet connection is realized, and the application range is wide.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without creative efforts.
FIG. 1 is a schematic diagram of a method for synchronizing clocks of multiple devices according to a Modbus protocol;
fig. 2 is a schematic diagram of time stamp transmission and reception between a master device and a slave device according to the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example one
As shown in fig. 1 and 2, a Modbus protocol-based multi-device clock synchronization method for an internet of things system in which at least one slave device communicates with a master device via a Modbus protocol includes the following steps:
step S1: the master device sends the current time stamp to the slave device, and receives the time stamp sent by the slave device to the master device;
the master device sends the current time stamp to the slave device, and the step of receiving the time stamp sent by the slave device to the master device is performed for a plurality of times, namely, the master device and the slave device perform transmission and reception for a plurality of times.
Step S2: calculating a time offset between the master device and the slave device;
as shown in fig. 2, the calculating the time offset between the master device and the slave device includes:
the master device transmits the current time mt1 to the slave device;
the slave device transmits a charging time st1 to the master device;
the master device transmits a charging time mt2 to the slave device after receiving st 1;
the slave device transmits a charging time st2 to the master device after receiving mt 2;
the master device records the receiving time as mt3 after receiving st2, and calculates the time offset between the master device and the slave device;
the time offset is [ st1+ st2-mt2- (mt1+ mt3)/2 ]/2.
Step S3: and the master equipment sends the time offset to the slave equipment, and the slave equipment corrects the current timestamp according to the time offset after receiving the time offset to finish time synchronization.
The master device sends the time offset to the slave device, the slave device corrects the current timestamp according to the time offset after receiving the time offset, and the time synchronization is completed by the following steps:
the master device transmits the time offset to the slave device;
the slave device calculates a set timestamp st3-offset from the current timestamp st3 and the received time offset, and sets the current timestamp to st.
In practical application, the method for synchronizing the clocks of the multiple devices based on the Modbus protocol may further include the following steps: and the master device is respectively time-synchronized with the plurality of slave devices according to the device IDs of different slave devices Modbus protocols.
Example two
As shown in fig. 1 and fig. 2, a multi-device clock synchronization method based on a Modbus protocol is used for an internet of things system in which at least one slave device communicates with a master device through the Modbus protocol;
the communication process between the master device and the slave device is carried out through a specific command, the specific command comprises an offset measuring and calculating command and a time synchronization command, the offset measuring and calculating command is used for measuring and calculating communication delay between the master device and the slave device, and the time synchronization command is used for synchronizing a slave device clock to a master device clock by the master device;
the multi-device clock synchronization method based on the Modbus protocol comprises the following steps:
step S1: the master device sends the current time stamp to the slave device, and receives the time stamp sent by the slave device to the master device;
the master device sends the current time stamp to the slave device, and the step of receiving the time stamp sent by the slave device to the master device is performed for a plurality of times, namely, the master device and the slave device perform transmission and reception for a plurality of times.
Step S2: calculating a time offset between the master device and the slave device;
as shown in fig. 2, the calculating the time offset between the master device and the slave device includes:
the master device transmits the current time mt1 to the slave device through an offset measurement command;
after receiving the offset measurement command, the slave device sends a receiving time st1 to the master device;
the master device transmits a charging time mt2 to the slave device after receiving st 1;
the slave device transmits a charging time st2 to the master device after receiving mt 2;
the master device records the receiving time as mt3 after receiving st2, and calculates the time offset between the master device and the slave device;
the time offset is [ st1+ st2-mt2- (mt1+ mt3)/2 ]/2.
Step S3: and the master equipment sends the time offset to the slave equipment, and the slave equipment corrects the current timestamp according to the time offset after receiving the time offset to finish time synchronization.
The master device sends the time offset to the slave device, the slave device corrects the current timestamp according to the time offset after receiving the time offset, and the time synchronization is completed by the following steps:
the master device transmits the time offset to the slave device;
the slave device calculates a set timestamp st3-offset from the current timestamp st3 and the received time offset, and sets the current timestamp to st.
In practical application, the method for synchronizing the clocks of the multiple devices based on the Modbus protocol may further include the following steps: and the master device is respectively time-synchronized with the plurality of slave devices according to the device IDs of different slave devices Modbus protocols.
The implementation of the invention has the advantages that: the invention discloses a multi-device clock synchronization method based on a Modbus protocol, which is used for an Internet of things system in which at least one slave device communicates with a master device through the Modbus protocol, and comprises the following steps: the master device sends the current time stamp to the slave device, and receives the time stamp sent by the slave device to the master device; calculating a time offset between the master device and the slave device; the master device sends the time offset to the slave device, and the slave device corrects the current timestamp according to the time offset after receiving the time offset to complete time synchronization; the time synchronization between the devices without Ethernet connection is realized, and the application range is wide.
The above description is only an embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention disclosed herein are intended to be covered by the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.
Claims (8)
1. A multi-device clock synchronization method based on a Modbus protocol is used for an Internet of things system with at least one slave device communicating with a master device through the Modbus protocol, and is characterized by comprising the following steps:
the master device sends the current time stamp to the slave device, and receives the time stamp sent by the slave device to the master device;
calculating a time offset between the master device and the slave device;
and the master equipment sends the time offset to the slave equipment, and the slave equipment corrects the current timestamp according to the time offset after receiving the time offset to finish time synchronization.
2. The Modbus protocol-based multi-device clock synchronization method according to claim 1, wherein the steps of the Modbus protocol-based multi-device clock synchronization method are performed by specific commands.
3. The Modbus protocol-based multi-device clock synchronization method according to claim 2, wherein the specific command comprises an offset measurement command and a time synchronization command, the offset measurement command is used for measuring communication delay between the master device and the slave device, and the time synchronization command is used for synchronizing the slave device clock to the master device clock by the master device.
4. The Modbus protocol-based multi-device clock synchronization method of claim 1, wherein the master device sends a current timestamp to the slave device while the step of receiving the timestamp sent by the slave device to the master device is performed a plurality of times.
5. The Modbus protocol-based multi-device clock synchronization method according to any one of claims 1 to 4, wherein the calculating the time offset between the master device and the slave device comprises:
the master device transmits the current time mt1 to the slave device;
the slave device transmits a charging time st1 to the master device;
the master device transmits a charging time mt2 to the slave device after receiving st 1;
the slave device transmits a charging time st2 to the master device after receiving mt 2;
the master device records the receiving time as mt3 after receiving st2, and calculates the time offset between the master device and the slave device;
the time offset is [ st1+ st2-mt2- (mt1+ mt3)/2 ]/2.
6. The Modbus protocol-based multi-device clock synchronization method according to claim 5, wherein the master device sends a time offset to the slave device, the slave device corrects the current timestamp according to the time offset after receiving the time offset, and completing the time synchronization comprises:
the master device transmits the time offset to the slave device;
the slave device calculates a set timestamp st3-offset from the current timestamp st3 and the received time offset, and sets the current timestamp to st.
7. The Modbus protocol-based multi-device clock synchronization method according to claim 6, comprising: and the master device is respectively time-synchronized with the plurality of slave devices according to the device IDs of different slave devices Modbus protocols.
8. The Modbus protocol-based multi-device clock synchronization method of claim 3, wherein calculating the time offset between the master device and the slave device comprises:
the master device transmits the current time mt1 to the slave device through an offset measurement command;
after receiving the offset measurement command, the slave device sends a receiving time st1 to the master device;
the master device transmits a charging time mt2 to the slave device after receiving st 1;
the slave device transmits a charging time st2 to the master device after receiving mt 2;
the master device records the receiving time as mt3 after receiving st2, and calculates the time offset between the master device and the slave device;
the time offset is [ st1+ st2-mt2- (mt1+ mt3)/2 ]/2.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110999588.6A CN113676280B (en) | 2021-08-29 | 2021-08-29 | Multi-device clock synchronization method based on Modbus protocol |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110999588.6A CN113676280B (en) | 2021-08-29 | 2021-08-29 | Multi-device clock synchronization method based on Modbus protocol |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113676280A true CN113676280A (en) | 2021-11-19 |
CN113676280B CN113676280B (en) | 2023-02-03 |
Family
ID=78547199
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110999588.6A Active CN113676280B (en) | 2021-08-29 | 2021-08-29 | Multi-device clock synchronization method based on Modbus protocol |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113676280B (en) |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102035639A (en) * | 2009-09-30 | 2011-04-27 | 华为技术有限公司 | Time synchronization method, device and system |
WO2011076066A1 (en) * | 2009-12-25 | 2011-06-30 | 华为技术有限公司 | Method, device and system for clock synchronization |
JP2014165582A (en) * | 2013-02-22 | 2014-09-08 | Nippon Telegraph & Telephone East Corp | Time synchronization system, time synchronization method, slave node and computer program |
CN107682247A (en) * | 2017-09-15 | 2018-02-09 | 广东芬尼克兹节能设备有限公司 | A kind of high efficiency communication method of main frame and multiple slaves |
CN110401505A (en) * | 2019-07-19 | 2019-11-01 | 深圳大学 | A kind of wireless network accurate time synchronization method |
CN110649984A (en) * | 2019-09-26 | 2020-01-03 | 北京和利时系统工程有限公司 | Clock synchronization method and device, computer storage medium and electronic equipment |
CN111918261A (en) * | 2020-08-13 | 2020-11-10 | 南京中感微电子有限公司 | Bluetooth audio equipment synchronous playing method and system and Bluetooth audio master and slave equipment |
-
2021
- 2021-08-29 CN CN202110999588.6A patent/CN113676280B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102035639A (en) * | 2009-09-30 | 2011-04-27 | 华为技术有限公司 | Time synchronization method, device and system |
WO2011076066A1 (en) * | 2009-12-25 | 2011-06-30 | 华为技术有限公司 | Method, device and system for clock synchronization |
JP2014165582A (en) * | 2013-02-22 | 2014-09-08 | Nippon Telegraph & Telephone East Corp | Time synchronization system, time synchronization method, slave node and computer program |
CN107682247A (en) * | 2017-09-15 | 2018-02-09 | 广东芬尼克兹节能设备有限公司 | A kind of high efficiency communication method of main frame and multiple slaves |
CN110401505A (en) * | 2019-07-19 | 2019-11-01 | 深圳大学 | A kind of wireless network accurate time synchronization method |
CN110649984A (en) * | 2019-09-26 | 2020-01-03 | 北京和利时系统工程有限公司 | Clock synchronization method and device, computer storage medium and electronic equipment |
CN111918261A (en) * | 2020-08-13 | 2020-11-10 | 南京中感微电子有限公司 | Bluetooth audio equipment synchronous playing method and system and Bluetooth audio master and slave equipment |
Also Published As
Publication number | Publication date |
---|---|
CN113676280B (en) | 2023-02-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN100581164C (en) | Accurate time synchronization method and system facing measurement and control | |
CN101478358B (en) | Method and device for optimized time synchronization correction | |
CN101217330B (en) | A method and device for time synchronism calibration | |
CN111711948B (en) | Method and system for acquiring high-precision time from 5G base station through air interface | |
EP2101439A1 (en) | Synchronization system and method of time information and related equipment | |
CN102638324B (en) | Method and device for realizing precise time synchronization | |
CN102006159A (en) | Multi-slave clock sampling value multi-interface synchronizing system based on IEEE1588 | |
CN102315985A (en) | Time synchronization precision test method for intelligent device adopting IEEE1588 protocols | |
WO2012088931A1 (en) | Method and device for monitoring time synchronization | |
CN111294132B (en) | Absolute time synchronization method and device and electronic equipment | |
CN103647614A (en) | Method for reliably improving time synchronization precision based on IEEE1588 protocol | |
CN113676280B (en) | Multi-device clock synchronization method based on Modbus protocol | |
CN103178920A (en) | Multi-channel synchronization method in test system of digital transformer substation | |
CN108666990A (en) | A kind of power grid differential protecting method and system | |
CN107645768B (en) | Time synchronization method and device for intra-office distribution | |
CN212181272U (en) | Time service device applied to aviation multi-target remote measurement ground station | |
KR20090089097A (en) | Irig-b time syncronization device and method there of | |
CN112532472B (en) | Method for testing uploading delay of phasor measurement unit | |
US11343007B2 (en) | Time synchronization method and device | |
CN111338204B (en) | Decentralized integrated atomic time system and establishing method thereof | |
CN110138487B (en) | Time noise transfer characteristic measurement method and network node | |
CN110430614B (en) | Base station signal synchronization method, device, equipment and storage medium based on GPS signal | |
CN111917503A (en) | Method and apparatus for providing a clock signal | |
CN109981204B (en) | Multi-machine synchronization method of BMS (battery management system) simulation system | |
CN115379491A (en) | Time service compensation method, wireless time service terminal, electronic device and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |