Methods, devices, and media for remote serial communication between gateway devices
By working in tandem with cloud servers and smart gateways, remote communication between different serial communication devices is achieved, solving the problems of device adaptation and parameter configuration in existing technologies, and providing flexible operating space and efficient remote management capabilities.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2026-03-10
AI Technical Summary
Existing smart gateways lack flexible operating space, cannot adapt to serial communication devices with different protocol types, and require different serial communication devices to be configured with the same serial communication parameters in advance to communicate, resulting in communication difficulties.
By cooperating with cloud servers and multiple smart gateways, one-to-one, one-to-many, many-to-one, or many-to-many communication modes can be realized. The smart gateways are configured with all types of serial communication parameters and perform a handshake process before data transmission to establish a data forwarding service and shield the parameter differences between devices.
It enables remote communication between serial communication devices in different locations, allowing users to operate remote devices locally through a smart gateway, eliminating the hassle of frequent on-site operations. It adapts to the differences in serial communication parameters of different devices, providing flexible operating space.
Smart Images

Figure CN119172204B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer communication technology, and in particular to a method, device and medium for realizing remote serial communication between gateway devices. Background Technology
[0002] The common existing solutions for connecting two first serial communication devices are:
[0003] 1. Because existing smart gateways only implement some general functions, they can only perform simple data acquisition and value setting on the first serial communication device, and cannot perform other functions (such as scanning local PLC devices, burning programs in specified devices, and real-time monitoring of certain data of the local first serial communication device), lacking more flexible operating space.
[0004] 2. Because smart gateways need to accommodate multiple serial communication devices with different protocol types, existing smart gateways only implement some general functions. That is, they can only perform simple data acquisition and settings for communication devices. When users need to perform comprehensive functional management of specific types of serial communication devices (e.g., program download, online programming, configuration, online debugging, etc.), users can only go to the device site to use management software to connect the serial communication devices and achieve direct connection between two serial communication devices through the serial port, which brings great inconvenience.
[0005] 3. Since the serial communication parameters of different first serial communication devices are different, the first serial communication devices that are directly connected need to be configured with the same serial communication parameters (e.g., baud rate, data bits, stop bits, etc.) in advance in order to achieve mutual communication between the first serial communication devices. However, since some first serial communication devices have limited support for serial communication parameter configuration or do not support the modification of serial communication parameters at all, it is impossible for the two parties to communicate with each other. Summary of the Invention
[0006] In view of this, the purpose of this invention is to propose a method for realizing remote serial communication between gateway devices.
[0007] To achieve the above-mentioned technical objectives, the technical solution adopted by this invention is as follows:
[0008] This invention provides a method for implementing remote serial communication between gateway devices, applicable to a cloud server, multiple smart gateways, at least one first serial communication device running in the field, and at least one second serial communication device running locally, comprising the following steps:
[0009] Step 1: Adapt the communication mode of multiple smart gateways on the cloud server according to the number of the first serial communication device and the second serial communication device.
[0010] Step 2: Establish channels between the cloud server and multiple smart gateways;
[0011] Step 3: Connect multiple smart gateways to the cloud server, and the cloud server manages all connected smart gateways in groups according to the communication mode;
[0012] Step 4: Connect each of the smart gateways to the corresponding first serial communication device and second serial communication device, wherein the smart gateway connected to the first serial communication device is used as the field gateway, and the smart gateway connected to the second serial communication device is used as the local gateway.
[0013] Step 5: All types of serial communication parameters are configured on each of the field gateways and local gateways. The field gateways match the serial communication parameters corresponding to the first serial communication device to establish a serial connection, and the local gateways match the serial communication parameters corresponding to the second serial communication device to establish a serial connection.
[0014] Step 6: Connect the field gateway with the corresponding first serial communication device and the local gateway with the corresponding second serial communication device;
[0015] Step 7: The second serial communication device transmits the data acquisition request to the first serial communication device in sequence through the local gateway, the cloud server, and the field gateway; after receiving the data acquisition request, the first serial communication device transmits the corresponding data information to the second serial communication device in sequence through the field gateway, the cloud server, and the local gateway.
[0016] Furthermore, step 1 specifically includes:
[0017] Step 11: The remote device management platform obtains the number of the first serial communication device and the second serial communication device that need to transmit data.
[0018] Step 12: Determine the number of smart gateways to be connected based on the number of the first serial communication devices and the second serial communication devices. The total number of the first serial communication devices and the second serial communication devices is consistent with the number of smart gateways.
[0019] Step 13: Set the communication modes between multiple smart gateways, including one-to-one mode, one-to-many mode, many-to-one mode, and many-to-many mode;
[0020] Step 14: The remote device management platform selects one communication mode from the communication modes based on the number of the first serial communication device and the second serial communication device, and configures it as the target mode for multiple smart gateways on the cloud server.
[0021] If there is only one first serial communication device and one second serial communication device, a one-to-one configuration mode is used; if there is only one first serial communication device and multiple second serial communication devices, a one-to-many configuration mode is used; if there are multiple first serial communication devices and only one second serial communication device, a many-to-one configuration mode is used; if there are multiple first serial communication devices and multiple second serial communication devices, a many-to-many configuration mode is used.
[0022] Furthermore, step 2 specifically includes:
[0023] Step 21: Select the same number of smart gateways for the first serial communication device and the second serial communication device that need to transmit data.
[0024] Step 22: Register each of the smart gateways to the remote device management platform, and pre-configure the gateway ID and parameters for connecting to the cloud server on each smart gateway through the remote device management platform;
[0025] Step 23: Configure the parameters and data forwarding rules for connecting to each smart gateway on the cloud server through the remote device management platform, and start the listening port of the TCP server on the cloud server to listen.
[0026] Step 24: The remote device management platform sends a command to open the transmission channel to the corresponding smart gateway. After receiving the command, the smart gateway connects to the listening port of the TCP server on the cloud server using the TCP client connection method, and registers the smart gateway information to the cloud server by sending a registration packet.
[0027] Step 25: After the listening port of the TCP server on the cloud server detects the TCP client access, it receives the information of the registered smart gateway and performs legality verification. After successful verification, it performs forwarding service management on the legally registered smart gateway.
[0028] Step 26: Legally register each smart gateway on the cloud server. After passing the data forwarding rules of the cloud server, establish a communication channel between the cloud server and multiple smart gateways.
[0029] Furthermore, step 3 specifically includes:
[0030] Step 31: Connect multiple smart gateways to the cloud server;
[0031] Step 32: The cloud server manages all connected smart gateways in groups according to the selected target mode;
[0032] If the target mode is one-to-one, the two connected smart gateways are divided into a first group and a second group, each containing one smart gateway. If the target mode is one-to-many, the multiple connected smart gateways are divided into a first group and a second group, the first group containing one smart gateway and the second group containing multiple smart gateways. If the target mode is many-to-one, the multiple connected smart gateways are divided into a first group and a second group, the first group containing multiple smart gateways and the second group containing one smart gateway. If the target mode is many-to-many, the multiple connected smart gateways are divided into a first group and a second group, the first group containing multiple smart gateways and the second group containing multiple smart gateways. The specific number of smart gateways in the first and second groups is allocated according to the number of the first and second serial communication devices.
[0033] Step 33: The cloud server uses the group information as the basis for data forwarding rules.
[0034] Furthermore, step 4 specifically involves:
[0035] Based on the grouping of the multiple smart gateways, each smart gateway is connected to a corresponding first serial communication device and a second serial communication device. If a one-to-one grouping mode is used, one smart gateway from the first group is connected as a field gateway to a first serial communication device, and one smart gateway from the second group is connected as a local gateway to a second serial communication device. If a one-to-many grouping mode is used, one smart gateway from the first group is connected as a field gateway to a first serial communication device, and multiple smart gateways from the second group are connected as local gateways to multiple second serial communication devices. If a many-to-one grouping mode is used, multiple smart gateways from the first group are connected as field gateways to multiple first serial communication devices, and one smart gateway from the second group is connected as a local gateway to a second serial communication device. If a many-to-many grouping mode is used, multiple smart gateways from the first group are connected as field gateways to multiple first serial communication devices, and multiple smart gateways from the second group are connected as local gateways to multiple second serial communication devices.
[0036] Furthermore, step 5 specifically includes:
[0037] Step 51: Configure all types of serial communication parameters on each of the field gateways and local gateways;
[0038] Step 52: When the field gateway connects to the corresponding first serial communication device for the first time, the field gateway selects the first parameter from all the configured serial communication parameters as the current parameter;
[0039] Step 53: Match the current parameter with the serial communication parameter corresponding to the first serial communication device. If the match is successful, proceed to step 54; if the match is unsuccessful, select the next parameter as the current parameter and return to step 53, until all serial communication parameters have been traversed.
[0040] Step 54: Connect the field gateway and the first serial communication device via a serial port. The field gateway records the model and serial communication parameters of the first serial communication device.
[0041] Step 55: When the field gateway reconnects to the first serial communication device, the field gateway calls the matching serial communication parameters to connect to the first serial communication device according to the recorded model and serial communication parameters.
[0042] Step 56: When the local gateway first connects to the corresponding second serial communication device, the local gateway selects the first parameter from all configured serial communication parameters as the current parameter.
[0043] Step 57: Match the current parameter with the serial communication parameter corresponding to the second serial communication device. If the match is successful, proceed to step 58; if the match is unsuccessful, select the next parameter as the current parameter and return to step 57, until all serial communication parameters have been traversed.
[0044] Step 58: Connect the local gateway and the second serial communication device via serial port. The local gateway records the model and serial communication parameters of the second serial communication device.
[0045] Step 59: When the local gateway reconnects to the second serial communication device, the local gateway calls the matching serial communication parameters to establish a serial connection with the second serial communication device based on the recorded model and serial communication parameters.
[0046] Furthermore, step 6 specifically includes:
[0047] Step 61: The remote device management platform simultaneously sends a pass-through start command to both the field gateway and the local gateway;
[0048] Step 62: After receiving the pass-through enable command, the field gateway sends a request message to the first serial communication device. If the field gateway receives the response message returned by the first serial communication device within the set time threshold, the handshake process between the field gateway and the first serial communication device is completed.
[0049] Step 63: After receiving the pass-through enable command, the local gateway sends a request message to the second serial communication device. If the local gateway receives a response message from the second serial communication device within a set time threshold, the handshake process between the local gateway and the second serial communication device is completed.
[0050] Furthermore, step 7 specifically includes:
[0051] Step 71: The remote device management platform simultaneously sends data forwarding instructions to both the field gateway and the local gateway;
[0052] Step 72: After receiving the data forwarding instruction, the field gateway and the local gateway enable the data forwarding function;
[0053] Step 73: The second serial communication device sends a data acquisition request to the local gateway. After receiving the data acquisition request, the local gateway forwards the data acquisition request to the cloud server through the data forwarding function.
[0054] Step 74: After receiving the data acquisition request, the cloud server sends it to the field gateway. After receiving the data acquisition request, the field gateway forwards the data acquisition request to the first serial communication device through the data forwarding function.
[0055] Step 75: After receiving the data acquisition request, the first serial communication device returns the corresponding data information to the field gateway, and the field gateway forwards the data information to the cloud server through the data forwarding function.
[0056] Step 76: After receiving the data information, the cloud server sends it to the local gateway. After receiving the data information, the local gateway forwards the data information to the second serial communication device through the data forwarding function.
[0057] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement a method for remote serial communication between gateway devices as described above.
[0058] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described above for remote serial communication between gateway devices.
[0059] By adopting the above technical solution, the present invention has the following beneficial effects compared with the prior art:
[0060] First, based on the establishment of data transmission channels between smart gateways in different locations and cloud servers, smart gateways in different locations can be interconnected through cloud servers;
[0061] Secondly, it adapts to the group management of cloud servers to realize one-to-one, one-to-many, many-to-one, or many-to-many communication modes between the first serial communication device and the second serial communication device.
[0062] Next, the smart gateway connects to the first and second serial communication devices via a serial cable. All types of serial communication parameters are configured on the smart gateway to ensure that both the first and second serial communication devices can successfully connect to the smart gateway via serial port. This adapts to the differences in serial communication parameters between the first and second serial communication devices, so that the current serial communication parameters do not need to be modified between the first and second serial communication devices. The smart gateway adapts to each serial communication device with different serial communication parameters.
[0063] Then, based on certain special serial communication protocols, a handshake proxy service is established to perform a handshake process before data transmission, which can ensure normal network connection.
[0064] Finally, a data forwarding service is established between the cloud server and the first serial communication device within the on-site gateway, and a data forwarding service is established between the cloud server and the second serial communication device within the local gateway; ultimately, the first and second serial communication devices located under the remote smart gateway can also perform remote communication.
[0065] 1. The method of the present invention enables users to perform more business operations on the first serial communication device connected to the remote field smart gateway through the local smart gateway. Through the access of the second serial communication device (PC or HMI), a series of operations such as program download, online programming, configuration, and online debugging can be realized on the first serial communication device in the remote field, which has a more flexible operating space.
[0066] 2. With the improved smart gateway, the local second serial communication device and the remote first serial communication device can communicate over long distances via serial port. Users can access the remote second serial communication device at any time through the local smart gateway via the second serial communication device in different locations, saving the trouble of frequent on-site visits.
[0067] 3. This invention configures all types of serial communication parameters in the smart gateway, shielding the differences in serial communication parameters between the first and second serial communication devices. Users can operate the remote first serial communication device as if it were connected locally, which brings great convenience to users. Attached Figure Description
[0068] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0069] Figure 1 This is an execution flowchart of a method for implementing remote serial communication between gateway devices provided in an embodiment of the present invention.
[0070] Figure 2 This is a schematic diagram of the one-to-one communication mode provided in the embodiments of the present invention.
[0071] Figure 3 This is a schematic diagram of a one-to-many communication mode provided in the embodiments of the present invention.
[0072] Figure 4 This is a schematic diagram of the many-to-one communication mode provided in the embodiments of the present invention.
[0073] Figure 5 This is a schematic diagram of the many-to-many communication mode provided in the embodiments of the present invention.
[0074] Figure 6 This is a schematic diagram illustrating the configuration of serial communication parameters between the smart gateway and the serial communication device provided in this embodiment of the invention.
[0075] Figure 7 This is a schematic diagram of the communication protocol conversion method on the smart gateway provided in an embodiment of the present invention.
[0076] Figure 8 This is a schematic diagram of the handshake process between the smart gateway and the serial communication device provided in an embodiment of the present invention.
[0077] Figure 9 This is a schematic diagram of configuring data forwarding service on a smart gateway provided in an embodiment of the present invention.
[0078] Figure 10 This is a schematic diagram of an electronic device provided in an embodiment of the present invention.
[0079] Figure 11 This is a schematic diagram of a computer-readable storage medium provided in an embodiment of the present invention. Detailed Implementation
[0080] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be particularly noted that the following embodiments are for illustrative purposes only and do not limit the scope of the invention. Similarly, the following embodiments are only some, not all, embodiments of the present invention, and all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0081] The purpose of this invention is to improve the functionality of the smart gateway (data forwarding function, configuration of all types of serial communication parameters) to enhance the efficiency of convenient and efficient management of first and second serial communication devices (also belonging to the first serial communication device, realizing serial port connection) at different sites. Users can access the cloud server through the smart gateway directly connected to the first serial communication device to perform all functions of the first and second serial communication devices at different sites, eliminating the trouble of frequently going to the device sites for access. At the same time, through improvements, it can adapt to the differences in serial communication parameters between different devices. Users only need to configure the serial communication parameters on the smart gateway to realize communication between the first and second serial communication devices.
[0082] Please see Figures 1-9 The present invention provides a method for realizing remote serial communication between gateway devices, which is applied to a cloud server, multiple smart gateways, at least one first serial communication device running in the field and at least one second serial communication device running locally.
[0083] Cloud servers: provide access management services for a large number of smart gateways;
[0084] Intelligent gateway: It connects to multiple different types of first and second serial communication devices downstream, and connects to the cloud server upstream;
[0085] First serial communication device (PLC): The first serial communication device running in the field, which is connected to the smart gateway via a serial port;
[0086] The second serial communication device (PC or HMI touch screen): runs locally and connects to the smart gateway via a serial port, managing the first serial communication device through the serial port access.
[0087] This embodiment uses a first serial communication device (serial sub-device a), a second serial communication device (client terminal), a field gateway (gateway A), and a local gateway (gateway B) as examples for illustration.
[0088] The method specifically includes the following steps:
[0089] Step 1: Adapt the communication mode of multiple smart gateways on the cloud server according to the number of the first serial communication device and the second serial communication device.
[0090] In this embodiment, step 1 specifically includes:
[0091] Step 11: The remote device management platform (cloud-based, which can control the opening and closing of corresponding functions of the cloud server and smart gateway) obtains the number of the first serial communication device and the second serial communication device that need to transmit data; in this embodiment, the number of the first serial communication device is 1 and the number of the second serial communication device is 1.
[0092] Step 12: Determine the number of smart gateways to be connected based on the number of the first serial communication devices and the second serial communication devices. The total number of the first serial communication devices and the second serial communication devices is the same as the number of smart gateways. In this embodiment, since the number of the first serial communication devices and the second serial communication devices is 1, the number of smart gateways to be connected later is calculated to be 2.
[0093] Step 13: Set the communication modes between multiple smart gateways, including one-to-one, one-to-many, many-to-one, and many-to-many modes; for example... Figures 2-5 As shown;
[0094] Step 14: The remote device management platform selects one communication mode from the communication modes based on the number of the first serial communication device and the second serial communication device, and configures it as the target mode for multiple smart gateways on the cloud server.
[0095] If there is only one first serial communication device and one second serial communication device, a one-to-one configuration is used; if there is only one first serial communication device and multiple second serial communication devices, a one-to-many configuration is used; if there are multiple first serial communication devices and only one second serial communication device, a many-to-one configuration is used; if there are multiple first and second serial communication devices, a many-to-many configuration is used. In this embodiment, since there is only one first serial communication device and one second serial communication device, a one-to-one configuration is used.
[0096] Step 2: Establish a channel between the cloud server and multiple smart gateways; the purpose of this step is to establish a channel that enables the smart gateways to communicate with each other through the connection relationship between the cloud server and multiple smart gateways.
[0097] For example, a transparent transmission channel is established between a smart gateway running on-site (hereinafter referred to as Gateway A), a cloud server, and a smart gateway running locally (hereinafter referred to as Gateway B). This channel serves as a channel for serial communication between Gateway A and Gateway B.
[0098] In this embodiment, step 2 specifically includes:
[0099] Step 21: Select the same number of smart gateways as the number of the first serial communication device and the second serial communication device that need to transmit data. In this embodiment, since the number of the first serial communication device and the second serial communication device is 1, two smart gateways are selected for access.
[0100] Step 22: Register each smart gateway to the remote device management platform, and pre-configure its own gateway ID and parameters for connecting to the cloud server (such as server address, port, token, etc.) on each smart gateway through the remote device management platform;
[0101] Step 23: Configure the parameters and data forwarding rules for connecting to each smart gateway on the cloud server through the remote device management platform, and start the listening port of the TCP server on the cloud server to listen.
[0102] Step 24: The remote device management platform sends a command to open the transmission channel to the corresponding smart gateway. After receiving the command, the smart gateway connects to the listening port of the TCP server on the cloud server using the TCP client connection method, and registers the smart gateway information to the cloud server by sending a registration packet.
[0103] Step 25: After the listening port of the TCP server on the cloud server detects the TCP client access, it receives the information of the registered smart gateway and performs legality verification. After successful verification, it performs forwarding service management on the legally registered smart gateway.
[0104] Step 26: Legally register each smart gateway on the cloud server. After passing the data forwarding rules of the cloud server, establish a communication channel between the cloud server and multiple smart gateways.
[0105] Step 3: Connect multiple smart gateways to the cloud server. The cloud server manages all connected smart gateways in groups according to the communication mode. The purpose of group management in this step is to realize one-to-one, one-to-many, many-to-one, or many-to-many functions. Users can manage them flexibly according to their needs to achieve the desired functions.
[0106] In this embodiment, step 3 specifically includes:
[0107] Step 31: Connect multiple smart gateways to the cloud server;
[0108] Step 32: The cloud server manages all connected smart gateways in groups according to the selected target mode;
[0109] If the target mode is a one-to-one mode, the two connected smart gateways are divided into a first group and a second group, each including one smart gateway. If the target mode is a one-to-many mode, the multiple connected smart gateways are divided into a first group and a second group, the first group including one smart gateway and the second group including multiple smart gateways. If the target mode is a many-to-one mode, the multiple connected smart gateways are divided into a first group and a second group, the first group including multiple smart gateways and the second group including one smart gateway. If the target mode is a many-to-many mode, the multiple connected smart gateways are divided into a first group and a second group, the first group including multiple smart gateways and the second group including multiple smart gateways. The specific number of smart gateways in the first and second groups is allocated according to the number of the first serial communication device and the second serial communication device. In this embodiment, the target mode is a one-to-one mode, and the two smart gateways are divided into a first group and a second group, each including one smart gateway.
[0110] Step 33: The cloud server uses the group information as the basis for data forwarding rules.
[0111] Step 4: Connect each of the smart gateways to the corresponding first serial communication device and second serial communication device, wherein the smart gateway connected to the first serial communication device is used as the field gateway, and the smart gateway connected to the second serial communication device is used as the local gateway.
[0112] For example, gateway A and the first serial communication device (referred to here as serial port sub-device a) are connected via a RS-232 / RS-485 serial cable, enabling communication between gateway A and its connected first serial communication device. The serial communication is implemented as follows: after connecting via a RS-232 / RS-485 serial cable and configuring the same serial communication parameters on both sides, they can communicate with each other by opening the serial port. In this step, the serial cable is used for initial connection, but communication is not yet possible.
[0113] Similarly, gateway B is connected to the second serial communication device (PC or HMI) via a RS-232 / RS-485 serial cable, enabling communication between gateway B and the connected second serial communication device. Serial communication is achieved by connecting via a RS-232 / RS-485 serial cable. After both devices are configured with the same serial communication parameters, they can communicate with each other by opening the serial port. In this step, the serial cable is used for initial connection, but communication is not yet possible.
[0114] In this embodiment, step 4 specifically includes:
[0115] Based on the grouping of the multiple smart gateways, each smart gateway is connected to a corresponding first serial communication device and a second serial communication device. If a one-to-one grouping mode is used, one smart gateway from the first group is connected as a field gateway to a first serial communication device, and one smart gateway from the second group is connected as a local gateway to a second serial communication device. If a one-to-many grouping mode is used, one smart gateway from the first group is connected as a field gateway to a first serial communication device, and multiple smart gateways from the second group are connected as local gateways to multiple second serial communication devices. If a many-to-one grouping mode is used, multiple smart gateways from the first group are connected as field gateways to multiple first serial communication devices, and one smart gateway from the second group is connected as a local gateway to a second serial communication device. If a many-to-many grouping mode is used, multiple smart gateways from the first group are connected as field gateways to multiple first serial communication devices, and multiple smart gateways from the second group are connected as local gateways to multiple second serial communication devices.
[0116] Step 5: All types of serial communication parameters are configured on each of the field gateways and local gateways. The field gateways match the serial communication parameters corresponding to the first serial communication device for serial connection, and the local gateways match the serial communication parameters corresponding to the second serial communication device for serial connection. The purpose of this step is to enable the smart gateways to support the configuration of numerous types of serial communication parameters, which can mask the differences in serial communication parameters between different first and second serial communication devices. Users only need to configure the serial communication parameters on each smart gateway to achieve remote communication between each first and second serial communication device.
[0117] In this embodiment, step 5 specifically includes:
[0118] Step 51: Configure all types of serial communication parameters on each of the field gateways and local gateways;
[0119] Step 52: When the field gateway connects to the corresponding first serial communication device for the first time, the field gateway selects the first parameter from all the configured serial communication parameters as the current parameter;
[0120] Step 53: Match the current parameter with the serial communication parameter corresponding to the first serial communication device. If the match is successful, proceed to step 54; if the match is unsuccessful, select the next parameter as the current parameter and return to step 53, until all serial communication parameters have been traversed.
[0121] Step 54: Connect the field gateway and the first serial communication device via a serial port. The field gateway records the model and serial communication parameters of the first serial communication device.
[0122] Step 55: When the field gateway reconnects to the first serial communication device, the field gateway calls the matching serial communication parameters to connect to the first serial communication device according to the recorded model and serial communication parameters.
[0123] Step 56: When the local gateway first connects to the corresponding second serial communication device, the local gateway selects the first parameter from all configured serial communication parameters as the current parameter.
[0124] Step 57: Match the current parameter with the serial communication parameter corresponding to the second serial communication device. If the match is successful, proceed to step 58; if the match is unsuccessful, select the next parameter as the current parameter and return to step 57, until all serial communication parameters have been traversed.
[0125] Step 58: Connect the local gateway and the second serial communication device via serial port. The local gateway records the model and serial communication parameters of the second serial communication device.
[0126] Step 59: When the local gateway reconnects to the second serial communication device, the local gateway calls the matching serial communication parameters to establish a serial connection with the second serial communication device based on the recorded model and serial communication parameters.
[0127] Automatic serial port parameter matching is implemented for some special communication protocols:
[0128] Taking the Modbus protocol as an example, if it is known that the serial port device communicates using the Modbus protocol, under normal circumstances, when the gateway sends a query message a, the serial port device will immediately reply with message b.
[0129] In situations where the serial port device's communication parameters are unknown in advance (taking different baud rates as an example, assuming the actual serial port baud rate is 38400), the smart gateway will select parameters sequentially from the supported parameter set (assuming the supported baud rate set is [1200, 4800, 9600, 38400, 115200]), starting from baud rate 1200, to attempt to establish communication with the serial communication device and send message 'a' to the serial communication device. This continues until a correct message 'b' is received when using a baud rate of 38400. At this point, the serial communication parameters match the corresponding serial communication parameters of the serial communication device. The smart gateway records and saves the serial communication parameters and the serial communication device model at this time. Upon the next power-on restart, it will use these serial communication parameters to communicate with the serial communication device, achieving a convenient, fast, and accurate result, eliminating the hassle of manual configuration.
[0130] like Figure 6 As shown, when the second serial communication device is directly connected to the first serial communication device, establishing normal communication requires modifying the serial communication parameters on either the first or second serial communication device. If the serial communication parameters on both devices cannot be modified—for example, the first device only supports serial communication parameters (baud rate: 9600, data bits: 8, parity: N, stop bits: 1), while the second device only supports parameters (baud rate: 115200, data bits: 7, parity: N, stop bits: 1)—then normal communication will be impossible. In this case, using two smart gateways can adapt to the different serial communication parameters and communicate with the first and second serial communication devices respectively. By connecting to a cloud server, bidirectional communication between the first and second serial communication devices can be achieved.
[0131] Step 6: Connect the field gateway with the corresponding first serial communication device and the local gateway with the corresponding second serial communication device. This step is to provide handshake connection proxies for some communication protocols with high latency requirements.
[0132] When the first and second serial communication devices communicate, they need to follow certain protocol rules. For example, a handshake is required when establishing a connection. This handshake usually needs to be completed in a short time. However, sometimes the network quality is too poor and the latency is too high, which can lead to a failure to connect normally.
[0133] In this scenario, the remote device management platform simultaneously sends a command to enable transparent transmission to both gateway A and gateway B. Upon receiving this command, gateway A, acting as the second serial communication device, sends a request message to the first serial communication device on-site. It then quickly receives a response message from the first serial communication device, completing the handshake process between gateway A and the first serial communication device (serial sub-device a). Similarly, upon receiving this command, gateway B, acting as the first serial communication device, sends a request message to the local second serial communication device. It then quickly receives a response message from the second serial communication device, completing the handshake process. By establishing a communication connection through this handshake proxy method—with gateway A completing the handshake with the directly connected serial sub-device a, and the second serial communication device completing the handshake with gateway B—the PLC management software can then enable subsequent operations on the first and second serial communication devices in different locations.
[0134] In this embodiment, step 6 specifically includes:
[0135] Step 61: The remote device management platform simultaneously sends a pass-through start command to both the field gateway and the local gateway;
[0136] Step 62: After receiving the pass-through enable command, the field gateway sends a request message to the first serial communication device. If the field gateway receives the response message returned by the first serial communication device within the set time threshold, the handshake process between the field gateway and the first serial communication device is completed.
[0137] Step 63: After receiving the pass-through enable command, the local gateway sends a request message to the second serial communication device. If the local gateway receives a response message from the second serial communication device within a set time threshold, the handshake process between the local gateway and the second serial communication device is completed.
[0138] For example, a second serial communication device sends a request message to a first serial communication device (PLC). Upon receiving this message, the first serial communication device replies with an acknowledgment message to the second. This process needs to be completed within a specified time. Because this time is very short, and the latency between the second and first serial communication devices is significant, the probability of a successful handshake is very low. In this case, the first serial communication device will terminate communication with the second. Therefore, some handshake connection proxy is needed. At this point, since the communication latency between gateway A and serial sub-device a, and between gateway B and the second serial communication device, can be ignored, the handshake process is completed separately between gateway A and serial sub-device a, and between gateway B and the second serial communication device. This ultimately satisfies the prerequisite for smooth communication with serial sub-device a, allowing the second serial communication device to perform subsequent business operations, such as... Figure 8 As shown.
[0139] After steps 1-6, the second serial communication device and the first serial communication device can communicate smoothly. At this time, the user can perform a series of management operations anytime and anywhere through the local second serial communication device and the remote first serial communication device, just as if the first serial communication device were deployed locally.
[0140] Step 7: The second serial communication device transmits the data acquisition request to the first serial communication device in sequence through the local gateway, the cloud server, and the field gateway; after receiving the data acquisition request, the first serial communication device transmits the corresponding data information to the second serial communication device in sequence through the field gateway, the cloud server, and the local gateway.
[0141] like Figure 9 As shown, for example: a data forwarding service is added inside the smart gateway (gateway A and gateway B) to forward data between the cloud server and the first serial communication device (or the second serial communication device); a data forwarding service is enabled in gateway A, so that when gateway A receives data from the cloud server, it forwards it to serial sub-device a, and when gateway A receives data from serial sub-device a, it forwards it to the cloud server; a data forwarding service is enabled inside gateway B, so that when gateway B receives data from the cloud server, it forwards it to the second serial communication device, and when gateway B receives data from the second serial communication device, it forwards it to the cloud server.
[0142] In this embodiment, step 7 specifically includes:
[0143] Step 71: The remote device management platform simultaneously sends data forwarding instructions to both the field gateway and the local gateway;
[0144] Step 72: After receiving the data forwarding instruction, the field gateway and the local gateway enable the data forwarding function;
[0145] Step 73: The second serial communication device sends a data acquisition request to the local gateway. After receiving the data acquisition request, the local gateway forwards the data acquisition request to the cloud server through the data forwarding function.
[0146] Step 74: After receiving the data acquisition request, the cloud server sends it to the field gateway. After receiving the data acquisition request, the field gateway forwards the data acquisition request to the first serial communication device through the data forwarding function.
[0147] Step 75: After receiving the data acquisition request, the first serial communication device returns the corresponding data information to the field gateway, and the field gateway forwards the data information to the cloud server through the data forwarding function.
[0148] Step 76: After receiving the data information, the cloud server sends it to the local gateway. After receiving the data information, the local gateway forwards the data information to the second serial communication device through the data forwarding function.
[0149] Perform message format conversion for some special communication protocols.
[0150] like Figure 7 As shown, for example, in the Modbus protocol, the first serial communication device (serial sub-device A) can only communicate via the Modbus ASCII protocol, while the second serial communication device can only communicate via the Modbus RTU protocol. Since the actual content of the two protocols is similar, only the communication format is different. Based on this situation, since the smart gateway adapts to both formats, it communicates with the first serial communication device via the Modbus ASCII protocol through gateway A. Then, after converting the Modbus ASCII format into a Modbus RTU format message, it is forwarded to gateway B through the cloud server. After gateway B replies with a Modbus RTU format message to the second serial communication device, the second serial communication device can then interact normally with the first serial communication device.
[0151] like Figure 10 As shown, this embodiment of the invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the above-described method for remote serial communication between gateway devices.
[0152] like Figure 11As shown, this embodiment of the invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the above-described method for remote serial communication between gateway devices.
[0153] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0154] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods of various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0155] The above description is only a part of the embodiments of the present invention and does not limit the scope of protection of the present invention. Any equivalent device or equivalent process transformation made based on the content of the present invention specification and drawings, or direct or indirect application in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for implementing remote serial communication between gateway devices, the method comprising: The application is applied to a cloud server, a plurality of intelligent gateways, at least one first serial communication device running on site and at least one second serial communication device running locally, and comprises the following steps: Step 1: adapting the communication mode of the plurality of intelligent gateways on the cloud server according to the number of the first serial communication device and the second serial communication device; the communication mode comprises one-to-one mode, one-to-many mode, many-to-one mode and many-to-many mode; Step 2: establishing the channel between the cloud server and the plurality of intelligent gateways; Step 3: connecting the plurality of intelligent gateways to the cloud server, and grouping and managing all the connected intelligent gateways according to the communication mode; Step 4: connecting the plurality of intelligent gateways to the corresponding first serial communication device and second serial communication device respectively, wherein the intelligent gateway connected to the first serial communication device is regarded as a site gateway, and the intelligent gateway connected to the second serial communication device is regarded as a local gateway; Step 5: configuring all types of serial communication parameters on each site gateway and local gateway, matching the serial communication parameters corresponding to the first serial communication device for serial connection on the site gateway, and matching the serial communication parameters corresponding to the second serial communication device for serial connection on the local gateway; specifically comprising: Step 51: configuring all types of serial communication parameters on each site gateway and local gateway; Step 52: when the site gateway is connected to the corresponding first serial communication device for the first time, the site gateway selects the first parameter from all the configured serial communication parameters as the current parameter; Step 53: matching the current parameter with the serial communication parameter corresponding to the first serial communication device, if the matching is successful, entering step 54; if the matching is unsuccessful, selecting the next parameter as the current parameter and returning to step 53 until all the serial communication parameters are traversed; Step 54: connecting the site gateway and the first serial communication device by serial connection, and the site gateway records the model and serial communication parameter corresponding to the first serial communication device; Step 55: when the site gateway is connected to the first serial communication device again, the site gateway calls the matching serial communication parameter according to the recorded model and serial communication parameter to connect to the first serial communication device by serial connection; Step 56: when the local gateway is connected to the corresponding second serial communication device for the first time, the local gateway selects the first parameter from all the configured serial communication parameters as the current parameter; Step 57: matching the current parameter with the serial communication parameter corresponding to the second serial communication device, if the matching is successful, entering step 58; if the matching is unsuccessful, selecting the next parameter as the current parameter and returning to step 57 until all the serial communication parameters are traversed; Step 58: connecting the local gateway and the second serial communication device by serial connection, and the local gateway records the model and serial communication parameter corresponding to the second serial communication device; Step 59, when the local gateway next time re-accesses the second serial communication device, the local gateway calls the matched serial communication parameters according to the recorded model and serial communication parameters to perform serial connection with the second serial communication device; Step 6, the field gateway and the corresponding first serial communication device and the local gateway and the corresponding second serial communication device are handshaked; Step 7, the second serial communication device transmits a data acquisition request to the first serial communication device through the local gateway, the cloud server and the field gateway in turn; after receiving the data acquisition request, the first serial communication device transmits corresponding data information to the second serial communication device through the field gateway, the cloud server and the local gateway in turn.
2. The method for implementing remote serial communication between gateway devices according to claim 1, wherein, The step 1 specifically comprises: Step 11, the remote device management platform acquires the number of the first serial communication device and the second serial communication device which need to perform data transmission; Step 12, the number of the smart gateway to be accessed is determined according to the number of the first serial communication device and the second serial communication device, and the total number of the first serial communication device and the second serial communication device is consistent with the number of the smart gateway; Step 13, the communication mode between the plurality of smart gateways is set; Step 14, the remote device management platform selects a mode from the communication mode as a target mode of the plurality of smart gateways on the cloud server according to the number of the first serial communication device and the second serial communication device; If the number of the first serial communication device and the second serial communication device is one, one-to-one mode is adopted for configuration; if the number of the first serial communication device is one and the number of the second serial communication device is multiple, one-to-many mode is adopted for configuration; if the number of the first serial communication device is multiple and the number of the second serial communication device is one, many-to-one mode is adopted for configuration; if the number of the first serial communication device and the number of the second serial communication device are both multiple, many-to-many mode is adopted for configuration.
3. The method for implementing remote serial communication between gateway devices according to claim 2, wherein, The step 2 specifically comprises: Step 21, a plurality of smart gateways with the same number are selected according to the number of the first serial communication device and the second serial communication device which need to perform data transmission; Step 22, each smart gateway is registered to the remote device management platform, and the gateway ID of each smart gateway and the parameters for connecting the cloud server are pre-configured on each smart gateway through the remote device management platform; Step 23, the parameters for connecting each smart gateway and the data forwarding rule are synchronously configured on the cloud server through the remote device management platform, and the listening port of the tcp server on the cloud server is opened to listen; Step 24, the remote device management platform sends an instruction to open a transmission channel to the corresponding smart gateway, and the smart gateway receives the instruction and connects the listening port of the tcp server on the cloud server in the connection mode of the tcp client, and registers the information of the smart gateway to the cloud server in the form of a registration packet; Step 25, after the listening port of the TCP server on the cloud server listens to the access of the TCP client, the information of the registered intelligent gateway is received and the legality is verified, and after the verification is successful, the forwarding service management of the legal registered intelligent gateway is performed; Step 26, after the legal registration of the cloud server of each intelligent gateway, the data forwarding rule of the cloud server is realized, and the communication channel between the cloud server and the multiple intelligent gateways is realized.
4. The method for implementing remote serial communication between gateway devices according to claim 3, wherein, The step 3 specifically comprises: Step 31, connecting multiple intelligent gateways to the cloud server; Step 32, the cloud server groups all the accessed intelligent gateways according to the selected target mode; If the selected target mode is one-to-one mode, the two accessed intelligent gateways are divided into first group and second group, and the first group and the second group each include one intelligent gateway; if the selected target mode is one-to-many mode, the multiple accessed intelligent gateways are divided into first group and second group, the first group includes one intelligent gateway, and the second group includes multiple intelligent gateways; if the selected target mode is many-to-one mode, the multiple accessed intelligent gateways are divided into first group and second group, the first group includes multiple intelligent gateways, and the second group includes one intelligent gateway; if the selected target mode is many-to-many mode, the multiple accessed intelligent gateways are divided into first group and second group, the first group includes multiple intelligent gateways, and the second group includes multiple intelligent gateways, and the specific number of intelligent gateways in the first group and the second group is allocated according to the number of the first serial communication device and the second serial communication device; Step 33, the cloud server takes the grouping information as the rule basis for data forwarding.
5. The method for implementing remote serial communication between gateway devices according to claim 4, wherein, The step 4 is specifically: According to the grouping of the multiple intelligent gateways, the multiple intelligent gateways are accessed to the corresponding first serial communication device and second serial communication device one by one; if the grouping under one-to-one mode is adopted, one intelligent gateway in the first group is accessed to one first serial communication device as a field gateway, and one intelligent gateway in the second group is accessed to one second serial communication device as a local gateway; If the grouping under one-to-many mode is adopted, one intelligent gateway in the first group is accessed to one first serial communication device as a field gateway, and multiple intelligent gateways in the second group are accessed to multiple second serial communication devices as local gateways; If the grouping under many-to-one mode is adopted, multiple intelligent gateways in the first group are accessed to multiple first serial communication devices as field gateways, and one intelligent gateway in the second group is accessed to one second serial communication device as a local gateway; If the grouping under many-to-many mode is adopted, multiple intelligent gateways in the first group are accessed to multiple first serial communication devices as field gateways, and multiple intelligent gateways in the second group are accessed to multiple second serial communication devices as local gateways.
6. The method for implementing remote serial communication between gateway devices according to claim 5, wherein, The step 6 specifically comprises: Step 61, the remote device management platform simultaneously issues a transparent transmission start instruction to the field gateway and the local gateway; Step 62, after receiving the transparent transmission start instruction, the field gateway sends a request message to the first serial communication device, and if the field gateway receives the response message returned by the first serial communication device within a set time threshold, the handshake process between the field gateway and the first serial communication device is completed. Step 63, after receiving the transparent transmission start instruction, the local gateway sends a request message to the second serial communication device, and if the local gateway receives the response message returned by the second serial communication device within a set time threshold, the handshake process between the local gateway and the second serial communication device is completed.
7. The method for implementing remote serial communication between gateway devices according to claim 6, wherein, The step 7 specifically comprises: Step 71, the remote device management platform simultaneously sends a data forwarding instruction to the field gateway and the local gateway; Step 72, after receiving the data forwarding instruction, the field gateway and the local gateway start the data forwarding function; Step 73, the second serial communication device sends a data acquisition request to the local gateway, and the local gateway receives the data acquisition request and forwards it to the cloud server through the data forwarding function; Step 74, after receiving the data acquisition request, the cloud server sends it to the field gateway, and the field gateway receives the data acquisition request and forwards it to the first serial communication device through the data forwarding function; Step 75, after receiving the data acquisition request, the first serial communication device returns the corresponding data information to the field gateway, and the field gateway forwards the data information to the cloud server through the data forwarding function; Step 76, after receiving the data information, the cloud server sends it to the local gateway, and the local gateway receives the data information and forwards it to the second serial communication device through the data forwarding function.
8. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the program to realize the method for realizing remote serial communication between gateway devices according to any one of claims 1 to 7.
9. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to realize the method for realizing remote serial communication between gateway devices according to any one of claims 1 to 7.
Citation Information
Patent Citations
Transparent transmission channel of power consumption acquisition system based on 4G and cloud service and method
CN108306975A