Smart Gateway Communication Protocol Conversion Implementation Method and System

By combining static and dynamic programming languages, using Lua to define device variables and communication protocols, and dynamically loading communication protocol programs, the problem of hard-coding complexity in industrial communication gateways is solved, and the program's versatility and module reusability are improved.

CN119449909BActive Publication Date: 2026-01-30GUODIAN LONGYUAN ELECTRICAL
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411741725.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2026-01-30
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

The development of existing industrial communication gateway programs requires recompiling the entire program source code for different devices, resulting in high hard-coding complexity and insufficient reusability of functional modules.

Method used

A combination of static and dynamic programming languages ​​is used. Device variables and communication protocols are defined using the Lua dynamic language, and communication protocol packing and unpacking programs are dynamically loaded, reducing hard coding and improving module reusability.

Benefits of technology

It reduces the coupling between program modules, improves the versatility of communication gateway programs and the reusability of functional modules, and simplifies the handling of device variables and protocol changes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119449909B_ABST
    Figure CN119449909B_ABST
Patent Text Reader

Abstract

This invention provides a method and system for implementing communication protocol conversion in an intelligent gateway, belonging to the field of industrial communication gateways. The method includes: loading the corresponding communication protocol packing / unpacking program and registering the corresponding communication protocol packing / unpacking interface according to the communication protocols of each device; loading the device variable definition file and the device communication instance definition file for each device; wherein the device variable definition file and the device communication instance definition file are both defined using a preset dynamic programming language; and executing the communication instance for each device based on the device variable definition file, the device communication instance definition file, and the communication protocol packing / unpacking program to perform data transmission between the devices. This reduces the coupling between various modules of the program, reduces the complexity of hard coding, and thus improves the reusability of each functional module of the program, making the communication gateway program more versatile.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial communication gateways, specifically to a method for implementing intelligent gateway communication protocol conversion, a system for implementing intelligent gateway communication protocol conversion, a machine-readable storage medium, and an electronic device. Background Technology

[0002] Industrial communication gateways are installed between various industrial devices to handle data exchange. In practical applications, industrial communication gateways often need to connect to multiple devices via interfaces such as CAN, RS485, and Ethernet, and the communication protocols and variable definitions of these devices vary greatly.

[0003] Industrial communication gateway programs are typically developed using static programming languages ​​such as C / C++. Since different projects use different equipment, this static C / C++ development approach requires recompiling the entire source code according to actual needs for each project, in order to develop a dedicated communication program for the communication gateway.

[0004] Therefore, how to reduce the complexity of hard coding, improve the reusability of functional modules, and make the communication gateway program more versatile are urgent problems to be solved. Summary of the Invention

[0005] The purpose of this invention is to provide a method and system for implementing intelligent gateway communication protocol conversion, so as to at least solve the above-mentioned problems of how to reduce the complexity of hard coding and improve the reusability of functional modules.

[0006] To achieve the above objectives, a first aspect of the present invention provides a method for implementing intelligent gateway communication protocol conversion, executed by a communication gateway, the method being applied to communication protocol conversion between devices connected to the communication gateway, the method comprising:

[0007] When responding to a communication request between devices, the corresponding communication protocol packing and unpacking program is loaded according to the communication protocol of each device, and the corresponding communication protocol packing and unpacking interface is registered.

[0008] The loading of device variable definition files and device communication instance definition files for each device is performed separately; both the device variable definition files and the device communication instance definition files are defined using a preset dynamic programming language.

[0009] Based on the device variable definition file, device communication instance definition file, and communication protocol packing / unpacking program for each device, the corresponding communication protocol packing / unpacking interface is called to execute the communication instance for each device in order to perform data transmission between devices.

[0010] Optionally, the definition rules for the above device variable definition files include:

[0011] Based on the data transmission of device variables, the mapping relationship between device variables and communication protocol data frames, and the data conversion relationship of device variables between multiple devices, the device variables are defined using a preset dynamic programming language to obtain the corresponding device variable definition file.

[0012] Optionally, the definition rules for the above device communication instance definition file include:

[0013] Based on the transmitted data of the device variables, the mapping relationship between the device variables and the communication protocol data frames, and the device's communication transmission method, the device communication instance is defined using a preset dynamic programming language to obtain the corresponding device communication instance definition file.

[0014] Optionally, the design rules for the above communication protocol packing and unpacking procedures include:

[0015] According to the data frame format requirements of the communication protocol, write the communication protocol packing and unpacking program using a preset static programming language and / or a preset dynamic programming language; wherein, the communication protocol packing and unpacking program includes a packing program and an unpacking program;

[0016] The logic of the packetization process is to convert the device communication data to be transmitted into data frames that meet the data frame format requirements of the communication protocol.

[0017] The unpacking process involves extracting the transmitted device communication data from data frames that meet the data frame format requirements of the communication protocol.

[0018] Optionally, the above-mentioned preset static programming language includes C or C++, and the preset dynamic programming language includes Lua.

[0019] The program uses a pre-defined static programming language to write communication protocol packing and unpacking programs, including:

[0020] Design a communication protocol packing and unpacking program using C or C++ language to implement the logic of the packing and unpacking process.

[0021] After the communication protocol packing and unpacking program is compiled into a dynamic library by the compiler, it is saved to the corresponding device file system directory;

[0022] The program uses a pre-defined dynamic programming language to write communication protocol packing and unpacking programs, including:

[0023] Using the Lua language, obtain a Lua script file containing the logic processes of the packing and unpacking programs;

[0024] The communication protocol packaging and unpacking program obtained from the Lua script file is saved to the corresponding device file system directory.

[0025] Optionally, the communication method for the communication instances corresponding to each device is inter-thread communication.

[0026] Optionally, when loading the device variable definition files corresponding to each device, based on the device variable definition files corresponding to each device, establish the communication data storage space corresponding to each device, the mapping relationship between the device variables and the corresponding communication protocol data frames, and the data conversion relationship between the device variables and multiple devices.

[0027] A second aspect of the present invention provides a smart gateway communication protocol conversion implementation system, deployed on a communication gateway. This system is used for communication protocol conversion between devices connected to the communication gateway. The system includes:

[0028] The request and response module is used to load the corresponding communication protocol packing and unpacking program according to the communication protocol of each device when responding to the communication request between devices, and to register the corresponding communication protocol packing and unpacking interface.

[0029] The definition file loading module is used to load the device variable definition files and the device communication instance definition files corresponding to each device, respectively; the device variable definition files and the device communication instance definition files are defined by a preset dynamic programming language.

[0030] The communication instance startup module is used to call the corresponding communication protocol packing and unpacking interface based on the device variable definition file, device communication instance definition file and communication protocol packing and unpacking program for each device, and execute the communication instance corresponding to each device to carry out data transmission between devices.

[0031] In a third aspect, the present invention provides a machine-readable storage medium storing instructions that, when executed by a processor, configure the processor to perform the aforementioned smart gateway communication protocol conversion implementation method.

[0032] In a fourth aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described smart gateway communication protocol conversion method.

[0033] The above technical solution provides a method and system for implementing communication protocol conversion in a smart gateway. When responding to communication requests between devices, it loads the corresponding communication protocol packing / unpacking programs and registers the corresponding communication protocol packing / unpacking interfaces based on the communication protocols of each device. It loads the device variable definition files and device communication instance definition files for each device, both defined using a preset dynamic programming language. Based on the device variable definition files, device communication instance definition files, and communication protocol packing / unpacking programs, it calls the corresponding communication protocol packing / unpacking interfaces to start the communication instances for each device, enabling data transmission between devices. This method and system employ a combination of static and dynamic programming languages. Dynamic programming languages ​​(i.e., Lua) are used to integrate various logical modules such as communication protocols, device variable definitions, and communication transmission methods, eliminating the need for static programming languages ​​(i.e., C / C++ static code) to define the calling relationships between these logical modules. If the device variable definition changes, or the variable's address in the communication protocol changes, or the logical relationship of the mapping between device variables changes, only the Lua script defining the device variables needs to be modified, without recompiling the entire program's C / C++ implementation. If the communication protocol needs to be expanded, only the new communication protocol packing / unpacking program needs to be added, along with the new packing / unpacking program in the Lua script, without recompiling the C / C++ implementation. This greatly reduces the coupling between program modules, reduces hard-coding complexity, and thus improves the reusability of program modules, making the communication gateway program more versatile.

[0034] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description section. Attached Figure Description

[0035] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings:

[0036] Figure 1 This is a flowchart of a smart gateway communication protocol conversion implementation method provided by one embodiment of the present invention;

[0037] Figure 2 This is a flowchart of another intelligent gateway communication protocol conversion implementation method provided by one embodiment of the present invention:

[0038] Figure 3 This is a schematic diagram of a communication protocol packing and unpacking program provided in one embodiment of the present invention:

[0039] Figure 4 This is a schematic diagram illustrating the implementation of device variable definition according to one embodiment of the present invention;

[0040] Figure 5 This is a schematic diagram illustrating the implementation of inter-device variable mapping according to one embodiment of the present invention;

[0041] Figure 6 This is a schematic diagram illustrating the implementation of a communication instance definition according to one embodiment of the present invention;

[0042] Figure 7 This is a flowchart of a communication instance execution provided by one embodiment of the present invention;

[0043] Figure 8 This is a hardware block diagram of a communication gateway provided in one embodiment of the present invention;

[0044] Figure 9 This is a block diagram of a smart gateway communication protocol conversion implementation system provided by one embodiment of the present invention;

[0045] Figure 10 This is a schematic diagram of an electronic device structure provided by a preferred embodiment of the present invention.

[0046] Explanation of reference numerals in the attached figures

[0047] 10 - Electronic device, 100 - Processor, 101 - Memory, 102 - Computer program. Detailed Implementation

[0048] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.

[0049] Example 1

[0050] Figure 1 This is a flowchart illustrating a method for implementing intelligent gateway communication protocol conversion according to one embodiment of the present invention. Figure 1 As shown, this embodiment of the invention provides a method for implementing intelligent gateway communication protocol conversion, executed by the communication gateway. This method is applied to communication protocol conversion between devices connected to the communication gateway, and includes:

[0051] S110: When responding to a communication request between devices, load the corresponding communication protocol packing and unpacking program according to the communication protocol of each device, and register the corresponding communication protocol packing and unpacking interface.

[0052] The communication gateway may include communication gateways for wind power converters, energy storage converters, and intelligent lighting systems.

[0053] Specifically, in response to a communication request between devices, the main program of the communication gateway starts, loads the necessary communication protocol packing and unpacking programs, and registers the required communication protocol packing and unpacking interfaces with the main program. It loads the variable definition files for each device, and uses the interfaces provided by the main program to establish communication data storage spaces for each device, the mapping relationship between device variables and device communication protocol packets, and the conversion relationship between variables between devices. It then loads the device communication instance definition files for each device, and finally starts the communication instances of each device to begin data transmission operations between the devices.

[0054] In some embodiments of this example, the design rules for the communication protocol packing and unpacking program include: writing the communication protocol packing and unpacking program using a preset static programming language and / or a preset dynamic programming language according to the data frame format requirements of the communication protocol; wherein, the communication protocol packing and unpacking program includes a packing program and an unpacking program; the logical process of the packing program is to convert the device communication data to be transmitted into a data frame that meets the data frame format requirements of the communication protocol; the logical process of the unpacking program is to extract the transmitted device communication data from the data frame that meets the data frame format requirements of the communication protocol.

[0055] In some embodiments of this example, the preset static programming language includes C or C++, and the preset dynamic programming language includes Lua.

[0056] Specifically, according to the data frame format requirements of the communication protocol, a communication protocol packing and unpacking program should be written using C / C++ or Lua. The data frame format requirements of the communication protocol refer to the byte stream rules for transmitted data frames specified by the communication protocol. Packing refers to the logical process of converting the data to be transmitted into data frames as specified by the communication protocol. Unpacking refers to the logical process of extracting the transmitted data from the data frames specified by the communication protocol.

[0057] The process of writing a communication protocol packing and unpacking program using a preset static programming language includes: designing the logical processes of the packing and unpacking programs using C or C++ to obtain the communication protocol packing and unpacking program; compiling the communication protocol packing and unpacking program into a dynamic library using a compiler and saving it to the corresponding device file system directory.

[0058] Specifically, writing a communication protocol packing / unpacking program using C / C++ refers to implementing the logic process of packing and unpacking communication protocols using C or C++. This is then compiled into a dynamic library and downloaded to a specific file system directory on the communication gateway device for the main program to call. This dynamic library-based communication protocol packing / unpacking program is written according to the rules for writing C / C++ modules in Lua. It can be loaded into the main program from a Lua script using the `require` function provided by Lua, and the Lua language can then call the communication protocol packing / unpacking logic within it.

[0059] The communication protocol packing and unpacking program is written using a preset dynamic programming language, including: using the Lua language to obtain a Lua script file containing the logic processes of the packing and unpacking programs; and saving the communication protocol packing and unpacking program obtained from the Lua script file to the corresponding device file system directory.

[0060] Specifically, writing a communication protocol packing and unpacking program using Lua refers to using the Lua language to implement the logic process of packing and unpacking communication protocols. This Lua script file is then downloaded to a specific file system directory on the communication gateway device for the main program to call. The communication protocol packing and unpacking program implemented in the aforementioned Lua script file can be loaded into the main program using the `require` function provided by the Lua language, and the Lua language can then call the communication protocol packing and unpacking logic within it.

[0061] The specific file system directory of the communication gateway device refers to the path where the Lua language script configured in the system searches for dynamic C / C++ dynamic library modules or Lua script package files.

[0062] In some embodiments of this example, the aforementioned communication protocol packing and unpacking program can provide the same calling interface to the main program for different communication protocols. By providing the same calling interface to the main program, the main program can use a unified calling operation for packing and unpacking different communication protocols, without having to use different calling interfaces for different communication protocols. Therefore, when a new communication protocol is added, only the new communication protocol packing and unpacking program package needs to be added, without changing the main program, thus making the expansion of communication protocols more convenient.

[0063] S120: Load the device variable definition file and the device communication instance definition file for each device respectively; the device variable definition file and the device communication instance definition file are both defined by a preset dynamic programming language;

[0064] In some embodiments of this example, the definition rules of the above-mentioned device variable definition file include: defining the device variables using a preset dynamic programming language according to the transmission data of the device variables, the mapping relationship between the device variables and the communication protocol data frames, and the data conversion relationship of the device variables between multiple devices, so as to obtain the corresponding device variable definition file.

[0065] Specifically, based on the definitions of device variables, communication protocols, and the conversion relationships between device variables, the device variable definitions are implemented using the Lua language, resulting in a device variable definition file. The device variable definitions refer to the various parameters and variables of the device transmitted through the communication protocol. This data is transmitted between the communication gateway and the device, using the device's communication protocol frame format as the carrier. The aforementioned communication protocol definition also includes the rules for mutual conversion of variables between devices connected to the communication gateway (for example, data A1 transmitted from device A needs to be multiplied by ab1 to obtain data B1 transmitted to device B). Implementing the communication protocol definition using Lua means describing the names, data types, rules for packing and unpacking communication protocol frames, and conversion rules between device variables transmitted through the communication protocol using Lua.

[0066] In some implementations of this embodiment, the definition rules of the above-mentioned device communication instance definition file include: defining the device communication instance using a preset dynamic programming language according to the transmission data of the device variables, the mapping relationship between the device variables and the communication protocol data frames, and the communication transmission method of the device, so as to obtain the corresponding device communication instance definition file.

[0067] Specifically, based on the device's communication transmission method, communication protocol definition, and device variable definition, the device communication instance definition is implemented using the Lua language, resulting in a device communication instance definition file. The device's communication transmission method refers to the communication interface between the device and the communication gateway (e.g., Ethernet port, UART port, CAN port, etc.) and its configuration information (e.g., via Ethernet port eth0, using a TCP server, port number 502; e.g., serial port / dev / ttyS0, baud rate 9600, no parity, 8 data bits).

[0068] In this application, the definitions of device variables (referring to the storage format, unit, and name of variables), the mapping relationship between device variables and communication protocol data frames, and the data conversion relationships between these variables across multiple devices (e.g., data A1 from device A needs to be multiplied by ab1 and then sent to device B as data B1) are implemented using Lua script files. These Lua script files are downloaded to a specific folder on the communication gateway and read and loaded by the main program. On the one hand, the main program allocates memory for each device variable according to its format definition; on the other hand, the main program calls the communication protocol packing and unpacking program to complete the reading or writing of device data frames and the packing and unpacking of data frames according to the mapping relationship between variables and the communication protocol; the main program can also complete the conversion between data from multiple devices according to the data conversion relationships between variables.

[0069] S130: Based on the device variable definition file, device communication instance definition file and communication protocol packing and unpacking program corresponding to each device, call the corresponding communication protocol packing and unpacking interface to execute the communication instance corresponding to each device in order to perform data transmission between devices.

[0070] Specifically, when responding to communication requests between devices, this method loads the corresponding communication protocol packing / unpacking programs and registers the corresponding communication protocol packing / unpacking interfaces based on the communication protocols of each device. It also loads the device variable definition files and device communication instance definition files, both defined using a preset dynamic programming language. Based on these files, the method calls the corresponding communication protocol packing / unpacking interfaces to initiate the communication instances for each device, enabling data transmission between them. This method employs a combination of static and dynamic programming languages. It uses a dynamic programming language (i.e., Lua) to integrate the various logical modules, such as communication protocols, device variable definitions, and communication transmission methods, eliminating the need for a static programming language (i.e., C / C++ static code) to define the calling relationships between these modules. If the device variable definition changes, or the variable's address in the communication protocol changes, or the logical relationship of the mapping between device variables changes, only the Lua script defining the device variables needs to be modified, without recompiling the entire program's C / C++ implementation. If the communication protocol needs to be expanded, only the new communication protocol packing / unpacking program needs to be added, along with the new packing / unpacking program in the Lua script, without recompiling the C / C++ implementation. This greatly reduces the coupling between program modules, reduces hard-coding complexity, and thus improves the reusability of program modules, making the communication gateway program more versatile.

[0071] In some implementations of this embodiment, the communication method of the communication instances corresponding to each device is inter-thread communication. Specifically, the communication instance of each device is implemented as a thread in the main program.

[0072] In some implementations of this embodiment, when loading the device variable definition file corresponding to each device, a communication data storage space corresponding to each device, a mapping relationship between the device's variables and the corresponding communication protocol data frame, and a data conversion relationship between the device's variables and multiple devices are established based on the device variable definition file corresponding to each device.

[0073] It should be noted that each communication protocol has a unique name in the system, corresponding to the communication protocol's packing and unpacking program file. This name can be simply called the communication protocol name, which is defined by the communication protocol packing and unpacking program when the main program loads it. Device variables are defined by the device variable definition file. Each device has a unique device variable definition file corresponding to it, and a unique name corresponding to it. This name can be called the device name, which is provided by the device variable definition file and obtained by the main program from the device variable definition file when it loads it.

[0074] In some implementations of this embodiment, the communication instance definition of the device includes the communication protocol name, the device name, and the device's communication transmission method.

[0075] In some implementations of this embodiment, the main program provides a communication protocol packing and unpacking interface; the main program provides a device variable registration interface.

[0076] In some implementations of this embodiment, the communication instance can find the communication protocol packing and unpacking interface registered in the main program according to the communication protocol name; the communication instance can find the device variable definition registered in the main program according to the device name; the communication method of the device can be obtained through the communication transmission method; therefore, the communication instance can obtain all the necessary information to communicate with the device, and based on this information, the communication instance can realize communication with the device.

[0077] Example 2

[0078] Figure 2 This is a flowchart of another intelligent gateway communication protocol conversion implementation method provided by one embodiment of the present invention, such as... Figure 2 As shown, this invention provides a method for implementing communication protocol conversion in a smart gateway. Taking a communication gateway operating system using Linux 3.10.108 armv5tejl architecture and Lua version 5.4.6 as an example, the specific process is as follows:

[0079] Step S1: According to the requirements of the communication protocol, use C / C++ or Lua language to write a communication protocol packing and unpacking program;

[0080] Step S2: According to the definition of the device variables, implement the device variable definition using the Lua language;

[0081] Step S3: According to the device's communication transmission method, communication protocol definition, and device variable definition, use the Lua language to implement the device communication instance definition;

[0082] Step S4: The gateway main program starts, loads the required communication packing and unpacking programs, registers the required communication protocol packing and unpacking interfaces with the main program, loads the device variable definition Lua program file implemented in S2, establishes the storage space for variables of each device, the mapping relationship between device variables and communication protocol packets, and the conversion relationship between variables between devices in the main program, and loads the communication instance definition Lua program file implemented in S3.

[0083] Step S5: Start the communication instance of each device and begin data transmission operations to the devices.

[0084] Please refer to Figure 3 , Figure 3 This is a schematic diagram illustrating the implementation of a communication protocol packing and unpacking program according to one embodiment of the present invention. The communication protocol implemented in this embodiment is in C++, and its name is ModbusTCPServer.

[0085] The packing function is:

[0086] int enpack(vector <u8>data, vector <var>vars)

[0087] {

[0088] ...

[0089] }

[0090] The unpacking function is:

[0091] in depack(vector <u8>data, vector <var>vars)

[0092] {

[0093] ...

[0094] }

[0095] The C++ source code implemented above still needs to be encapsulated into a program that can be loaded in Lua scripts according to the rules for writing C / C++ modules in Lua. It is loaded into the main program by the require function provided by Lua, and the communication protocol packing and unpacking logic can be called by Lua.

[0096] Please refer to Figure 4 , Figure 4 This is a schematic diagram illustrating the implementation of device variable definition according to one embodiment of the present invention. The device variable definition consists of a name, variables, and a variable mapping table. In this embodiment, the name is pcs, and the variables are UA, UB, ..., CntrW, ...

[0097] In this embodiment, each variable has members in sequence: name, type, address, class, readmode, writemode, and unit. name represents the variable's name, type represents the variable's storage type, class represents the variable's category definition in the communication protocol, readmode represents the variable's read mode, writemode represents the variable's write mode, and uint represents the unit. Here, readmode / writemode never indicates no read / write, 0 indicates asynchronous read / write, and a time interval (e.g., 20ms) indicates a 20ms interval for read / write. The variable mapping table consists of an array of inter-device variable mapping entries, implemented as follows: Figure 5 As shown, Figure 5 This is a schematic diagram illustrating the implementation of inter-device variable mapping according to one embodiment of the present invention. Inter-device variable mapping consists of `from`, `to`, and `function`. Here, `from` represents the source variable, indicating the variable to be transformed; `to` represents the target variable, indicating the variable to be generated; and `function` represents the generating function. Figure 5 This implements a variable conversion from pcs.UA to ems.UA, meaning that ems.UA is obtained by pcs.UA * 100, where pcs.UA represents the UA variable of device pcs and ems.UA represents the UA variable of device ems (in this implementation, "device a.variable1" represents variable1 of device a. This invention does not limit this representation method, as long as it can represent the subordinate relationship).

[0098] Please refer to Figure 6 , Figure 6 This is a schematic diagram illustrating the implementation of a communication instance definition according to one embodiment of the present invention. The communication instance definition consists of a communication protocol name, a device name, and a communication method. Specifically, the communication protocol name corresponds one-to-one with the communication protocol packing / unpacking program, the device name corresponds one-to-one with the device variable definition, and the communication method corresponds to the communication method table. In this embodiment, the communication method table consists of dev, para, ..., where dev represents the device file of the system to which the communication instance is located, and para represents the communication parameters. Figure 6 This indicates that the communication device is / dev / ttyS0. The parameters 9600,8,n,1 represent a baud rate of 9600, 8 data bits with no parity, and 1 stop bit. The communication instance records all information related to the communication with the corresponding device. By loading the communication instance into the main program, the communication information for the corresponding device is imported, and subsequent communication with the device can be established to achieve data transmission.

[0099] Figure 7 This is a flowchart illustrating the execution of a communication instance according to one embodiment of the present invention. Figure 7 The diagram illustrates two communication scenarios: the flowchart on the left represents the Master / Client mode, and the flowchart on the right represents the Slave / Server mode. In Master / Client mode, the communication gateway acts as the master, actively sending data to the device and then waiting for a response. In Slave / Server mode, the gateway acts as the slave, waiting to receive data frames from the device, processing the data frames, and then sending a response.

[0100] It should be noted that in practice, there may be more than just these two communication instance modes. Figure 7 This only demonstrates the implementation methods of two of the communication examples.

[0101] For Master / Client communication mode, the communication instance thread first creates, initializes, and opens the communication device S according to the communication method obtained by the main program. Then, based on the device variable definition, it finds the variable that needs to be read from the device, creates a variable read data frame, sends it to the device via the device communication interface S, and waits for the device's response. Upon receiving the response, it unpacks the device variable value from the response data frame and stores it in the device variable's storage location. After reading the variable value, it converts the read variable into the variable required by other devices according to the inter-device variable mapping information mentioned above and stores it in the other device's variable location. Then, based on the device variable definition, it finds the variable that needs to be written to the device, reads the variable value from the variable's storage location, creates a variable write data frame, sends it to the device via the device communication interface S, and waits for the device's response.

[0102] For Slave / Sever communication mode, the communication instance thread first creates, initializes, and opens the communication device S according to the communication mode obtained by the main program. Then, it waits to receive data from S. After receiving the data from S, it parses whether it is a variable read / write or write command. If it is a variable write command, it unpacks the variable value, writes it to the corresponding storage location of the variable, converts the read variable into the variable required by other devices according to the above inter-device variable mapping information, stores it in the variable location of other devices, and then creates a variable write return command data frame and sends the return command to the device through S. If it is a variable read command, it unpacks the variable to be read, reads the value of the variable from the variable's storage location, packages it into a variable read return command frame, and sends the return command to the device through S.

[0103] Figure 8 This is a hardware block diagram of a communication gateway provided in one embodiment of the present invention. Figure 8 As shown, the communication gateway hardware uses a NUC972 core board, 64M RAM, 128M NandFlash, three external RS485 communication interfaces, two CAN communication interfaces and two Ethernet communication interfaces, and is powered by 24V DC.

[0104] This embodiment demonstrates that this implementation method, combining static and dynamic languages, uses Lua to integrate various logical modules such as communication protocols, device variable definitions, and communication transmission methods, eliminating the need for hard-coding the calling relationships between these modules. If a device variable definition or its address within the communication protocol changes, or if the logical mapping between device variables changes, only the Lua script defining the device variables needs modification; the entire C / C++ program needs to be recompiled. Similarly, if a new communication protocol is needed, only a communication protocol packing / unpacking program needs to be added, modifying the Lua script defining the communication instances, without recompiling the C / C++ program. This significantly reduces the coupling between program modules, decreases the complexity of hard-coding, improves the reusability of functional modules, and makes the communication gateway program more versatile.

[0105] Example 3

[0106] Figure 9 This is a block diagram of a smart gateway communication protocol conversion implementation system provided by one embodiment of the present invention. Figure 9 As shown, this embodiment of the invention provides a smart gateway communication protocol conversion implementation system, deployed on a communication gateway. This system is used for communication protocol conversion between devices connected to the communication gateway. The system includes:

[0107] The request and response module is used to load the corresponding communication protocol packing and unpacking program according to the communication protocol of each device when responding to the communication request between devices, and to register the corresponding communication protocol packing and unpacking interface.

[0108] The definition file loading module is used to load the device variable definition files and the device communication instance definition files corresponding to each device, respectively; the device variable definition files and the device communication instance definition files are defined by a preset dynamic programming language.

[0109] The communication instance startup module is used to call the corresponding communication protocol packing and unpacking interface based on the device variable definition file, device communication instance definition file and communication protocol packing and unpacking program for each device, and execute the communication instance corresponding to each device to carry out data transmission between devices.

[0110] Specifically, when responding to communication requests between devices, the system loads the corresponding communication protocol packing / unpacking programs and registers the corresponding communication protocol packing / unpacking interfaces based on the communication protocols of each device. It also loads the device variable definition files and communication instance definition files for each device, both defined using a preset dynamic programming language. Based on these files, the system calls the corresponding communication protocol packing / unpacking interfaces to initiate the communication instances for each device, enabling data transmission between them. This system employs a combination of static and dynamic programming languages. Dynamic programming languages ​​(i.e., Lua) are used to integrate the various logical modules, such as communication protocols, device variable definitions, and communication transmission methods, eliminating the need for static programming languages ​​(i.e., C / C++ static code) to define the calling relationships between these modules. If the device variable definition changes, or the variable's address in the communication protocol changes, or the logical relationship of the mapping between device variables changes, only the Lua script defining the device variables needs to be modified, without recompiling the entire program's C / C++ implementation. If the communication protocol needs to be expanded, only the new communication protocol packing / unpacking program needs to be added, along with the new packing / unpacking program in the Lua script, without recompiling the C / C++ implementation. This greatly reduces the coupling between program modules, reduces hard-coding complexity, and thus improves the reusability of program modules, making the communication gateway program more versatile.

[0111] Example 4

[0112] The present invention also provides a machine-readable storage medium storing instructions that, when executed by a processor 100, configure the processor 100 to perform the above-described smart gateway communication protocol conversion implementation method.

[0113] Machine-readable storage media include both permanent and non-permanent, removable and non-removable media, which can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0114] The present invention also provides an electronic device 10, which includes a memory 101, a processor 100, and a computer program 102 stored in the memory 101 and executable on the processor 100. When the processor 100 executes the computer program 102, it implements the above-described intelligent gateway communication protocol conversion method.

[0115] like Figure 10 The diagram shown is a schematic representation of an electronic device according to an embodiment of the present invention. Figure 10 As shown, the electronic device 10 of this embodiment includes a processor 100, a memory 101, and a computer program 102 stored in the memory 101 and executable on the processor 100. When the processor 100 executes the computer program 102, it implements the steps in the method embodiment described above. Alternatively, when the processor 100 executes the computer program 102, it implements the functions of each module / unit in the device embodiment described above.

[0116] For example, computer program 102 can be divided into one or more modules / units, one or more of which are stored in memory 101 and executed by processor 100 to complete the present invention. One or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of computer program 102 in electronic device 10. For example, computer program 102 can be divided into a request-response module, a definition file loading module, and a communication instance initiation module.

[0117] Electronic device 10 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. Electronic device 10 may include, but is not limited to, processor 100 and memory 101. Those skilled in the art will understand that... Figure 10 This is merely an example of electronic device 10 and does not constitute a limitation on electronic device 10. It may include more or fewer components than shown, or combine certain components, or different components. For example, electronic device may also include input / output devices, network access devices, buses, etc.

[0118] The processor 100 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0119] The memory 101 can be an internal storage unit of the electronic device 10, such as a hard disk or RAM of the electronic device 10. The memory 101 can also be an external storage device of the electronic device 10, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, FlashCard, etc., equipped on the electronic device 10. Furthermore, the memory 101 can include both internal and external storage units of the electronic device 10. The memory 101 is used to store computer programs and other programs and data required by the electronic device 10. The memory 101 can also be used to temporarily store data that has been output or will be output.

[0120] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments 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. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0121] Those skilled in the art will understand that embodiments of this application can be provided as a method, system, or computer program 102 product. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program 102 product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0122] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program 102 products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program 102 instructions. These computer program 102 instructions can be provided to a processor 100 of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor 100 of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0123] These computer program 102 instructions may also be stored in a computer-readable storage medium 101 that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium 101 produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0124] These computer program 102 instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable apparatus for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0125] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0126] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.< / var> < / var>

Claims

1. A method for implementing intelligent gateway communication protocol conversion, characterized in that, The method is applied to communication protocol conversion between devices connected with the communication gateway, and comprises the following steps: When responding to a communication request between devices, loading of corresponding communication protocol packing and unpacking procedures and registration of corresponding communication protocol packing and unpacking interfaces are performed according to respective communication protocols of the devices; Loading of device variable definition files corresponding to the devices and loading of device communication instance definition files corresponding to the devices are respectively performed; wherein the device variable definition files and the device communication instance definition files are defined by a preset dynamic programming language; Based on the device variable definition files, the device communication instance definition files and the communication protocol packing and unpacking procedures, corresponding communication protocol packing and unpacking interfaces are called to perform communication instances corresponding to the devices for data transmission between the devices; wherein The definition rule of the device variable definition file comprises: According to transmission data of a variable of a device, a mapping relationship between the variable of the device and a communication protocol data frame and a data conversion relationship between the variable of the device and multiple devices, a variable definition of the device is performed using a preset dynamic programming language to obtain a corresponding device variable definition file; The definition rule of the device communication instance definition file comprises: According to transmission data of a variable of a device, a mapping relationship between the variable of the device and a communication protocol data frame and a communication transmission mode of the device, a device communication instance definition is performed using a preset dynamic programming language to obtain a corresponding device communication instance definition file.

2. The intelligent gateway communication protocol conversion implementation method of claim 1, wherein, The design rule of the communication protocol packing and unpacking procedure comprises: According to a data frame format requirement of a communication protocol, a communication protocol packing and unpacking procedure is written using a preset static programming language and / or a preset dynamic programming language; wherein the communication protocol packing and unpacking procedure comprises a packing procedure and an unpacking procedure; The logic process of the packing procedure is to convert device communication data to be transmitted into a data frame satisfying a data frame format requirement of a communication protocol; The logic process of the unpacking procedure is to extract transmitted device communication data from a data frame satisfying a data frame format requirement of a communication protocol.

3. The intelligent gateway communication protocol conversion implementation method of claim 2, wherein, The preset static programming language comprises C language or C++ language, and the preset dynamic programming language comprises lua language; The writing of the communication protocol packing and unpacking procedure using the preset static programming language comprises: The program design of the logic process of the packing procedure and the logic process of the unpacking procedure is performed using C language or C++ language to obtain a communication protocol packing and unpacking procedure; After the communication protocol packing and unpacking procedure is compiled into a dynamic library form by a compiler, it is saved into a corresponding device file system directory; The writing of the communication protocol packing and unpacking procedure using the preset dynamic programming language comprises: The lua script file containing the logic process of the packing procedure and the logic process of the unpacking procedure is obtained using lua language; The communication protocol packing and unpacking procedure obtained from the lua script file is saved into a corresponding device file system directory.

4. The intelligent gateway communication protocol conversion implementation method of claim 1, wherein, The communication mode of the communication instance corresponding to each device is a thread intercommunication mode.

5. The intelligent gateway communication protocol conversion implementation method of claim 1, wherein, When loading the device variable definition file corresponding to each device, a communication data storage space corresponding to each device, a mapping relationship between the variable of the device and the communication protocol data frame, and a data conversion relationship between the variable of the device among multiple devices are established based on the device variable definition file corresponding to each device.

6. An intelligent gateway communication protocol conversion implementation system, characterized by, The system is deployed in a communication gateway, and is applied to communication protocol conversion among devices connected with the communication gateway. The system comprises: A request response module is configured to, when responding to a communication request among the devices, load a corresponding communication protocol packing and unpacking program according to each communication protocol of each device, and register a corresponding communication protocol packing and unpacking interface; A definition file loading module is configured to load a device variable definition file corresponding to each device and a device communication instance definition file corresponding to each device respectively; wherein the device variable definition file and the device communication instance definition file are defined by a preset dynamic programming language; A communication instance starting module is configured to, based on the device variable definition file corresponding to each device, the device communication instance definition file, and the communication protocol packing and unpacking program, call a corresponding communication protocol packing and unpacking interface, and execute a communication instance corresponding to each device to perform data transmission among the devices; wherein The definition rule of the device variable definition file comprises: The variable of the device is defined by using the preset dynamic programming language according to the transmission data of the variable of the device, the mapping relationship between the variable of the device and the communication protocol data frame, and the data conversion relationship between the variable of the device among multiple devices, so as to obtain the corresponding device variable definition file; The definition rule of the device communication instance definition file comprises: The device communication instance is defined by using the preset dynamic programming language according to the transmission data of the variable of the device, the mapping relationship between the variable of the device and the communication protocol data frame, and the communication transmission mode of the device, so as to obtain the corresponding device communication instance definition file.

7. A machine-readable storage medium having stored thereon instructions, the instructions being executable by a machine to cause the machine to perform operations comprising: The instruction, when executed by the processor, causes the processor to be configured to perform the intelligent gateway communication protocol conversion implementation method of any one of claims 1 to 5.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor performs the computer program to implement the intelligent gateway communication protocol conversion implementation method of any one of claims 1 to 5.

Citation Information

Patent Citations

  • Script generation method and device, message analysis method and device, medium and equipment

    CN117762416A

  • Protocol converter for communication between IoT-based device and server and its protocol conversion method

    KR102346793B1