Intelligent gateway communication protocol conversion implementation method and system
By adopting the intelligent gateway communication protocol conversion implementation method in industrial communication gateways, and using dynamic programming language to realize logical module bonding of protocols, variables and transmission methods, it solves the problem that the hard coding complexity and low functional module reuse capabilities in the prior art are high in the hard coding process and low in the reuse capability of functional modules in the prior art. The problem of this has improved the universality and reuse capabilities of communication gateway programs.
Patent Information
- Application Number
- CN202411741725.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2044-11-29
AI Technical Summary
When faced with differences in communication protocols and variable definitions of different devices, existing industrial communication gateways need to recompile the entire program source code, resulting in high hard coding complexity, low functional module reuse capability, and insufficient program universality.
Using the intelligent gateway communication protocol conversion implementation method, the unpacking program, device variable definition file and device communication instance definition file are loaded by loading the communication protocol of each device, and the logical module of protocol, variable and transmission method is implemented using dynamic programming language (such as lua) Glue to reduce the dependence of static programming languages (such as C/C++) in defining call relationships.
It reduces the coupling of each module of the program, reduces the complexity of hard coding, improves the reuse capability of functional modules, makes the communication gateway program more versatile, and can flexibly respond to the communication needs of different devices.
Smart Images

Figure CN119449909A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of industrial communication gateways, and in particular to an intelligent gateway communication protocol conversion implementation method, an intelligent gateway communication protocol conversion implementation system, a machine-readable storage medium and an electronic device. Background Art
[0002] Industrial communication gateways are installed between various industrial devices and are responsible for data exchange between them. In practical applications, industrial communication gateways often need to access multiple devices through interfaces such as CAN, RS485, and Ethernet ports, and the communication protocols and variable definitions of various devices vary greatly.
[0003] Static programming languages such as C / C++ are usually used to develop industrial communication gateway programs. Since different projects use different devices, different projects need to recompile the entire program source code according to actual needs to develop a dedicated communication program for the communication gateway.
[0004] Therefore, how to reduce the complexity of hard coding, improve the reuse capability of functional modules, and make the communication gateway program more versatile is an urgent problem that needs to be solved. Summary of the invention
[0005] The purpose of the embodiments of the present invention is to provide a method and system for implementing intelligent gateway communication protocol conversion, so as to at least solve the above-mentioned problem of how to reduce the complexity of hard coding and improve the reuse capability of functional modules.
[0006] In order to achieve the above-mentioned object, the first aspect of the present invention provides a method for implementing intelligent gateway communication protocol conversion, which is executed by a communication gateway and is applied to communication protocol conversion between devices connected to the communication gateway. The method comprises: When responding to a communication request between devices, according to each communication protocol of each device, the corresponding communication protocol packaging and unpacking program is loaded, and the corresponding communication protocol packaging and unpacking interface is registered; Respectively executing the loading of the device variable definition file corresponding to each device and the loading of the device communication instance definition file corresponding to each device; wherein the device variable definition file and the device communication instance definition file are both defined by a preset dynamic programming language; Based on the device variable definition file, device communication instance definition file and communication protocol packing and unpacking program corresponding to each device, the corresponding communication protocol packing and unpacking interface is called, and the communication instance corresponding to each device is executed to perform data transmission between the devices.
[0007] Optionally, the definition rules of the above device variable definition file include: According to the transmission data of the device variables, the mapping relationship between the device variables and the communication protocol data frame, and the data conversion relationship between the device variables between multiple devices, the device variables are defined using a preset dynamic programming language to obtain the corresponding device variable definition file.
[0008] Optionally, the definition rules of the above device communication instance definition file include: According to the transmission data of the device's variables, the mapping relationship between the device's variables and the communication protocol data frame, and the device's communication transmission mode, a device communication instance is defined using a preset dynamic programming language to obtain a corresponding device communication instance definition file.
[0009] Optionally, the design rules of the above communication protocol packaging and unpacking program include: According to the data frame format requirements of the communication protocol, a communication protocol packing and unpacking program is written 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; The logical process of the packaging 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.
[0010] Optionally, the preset static programming language includes C language or C++ language, and the preset dynamic programming language includes Lua language; Use the preset static programming language to write the communication protocol packaging and unpacking program, including: Use C language or C++ language to program the logical process of the packing program and the logical process of the unpacking program to obtain the communication protocol packing and unpacking program; After the communication protocol packaging and unpacking program is compiled into a dynamic library form by the compiler, it is saved in the corresponding device file system directory; Use the preset dynamic programming language to write the communication protocol packaging and unpacking program, including: Use Lua language to obtain Lua script files containing the logical process of the packaging program and the logical process of the unpacking program; The communication protocol packaging and unpacking program obtained from the lua script file is saved in the corresponding device file system directory.
[0011] Optionally, the communication mode of the communication instance corresponding to each device is an inter-thread communication mode.
[0012] Optionally, when loading the device variable definition files corresponding to each device, based on the device variable definition files corresponding to each device, 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 between multiple devices are established.
[0013] The second aspect of the present invention provides an intelligent gateway communication protocol conversion implementation system, which is deployed in a communication gateway. The system is applied to the communication protocol conversion between devices connected to the communication gateway. The system includes: A request response module, used for, when responding to a communication request between devices, executing the loading of the corresponding packaging and unpacking programs of each communication protocol according to each communication protocol of each device, and executing the registration of the corresponding packaging and unpacking interfaces of each communication protocol; A definition file loading module, used to respectively execute the loading of a device variable definition file corresponding to each device and the loading of a device communication instance definition file corresponding to each device; wherein the device variable definition file and the device communication instance definition file are both defined by a preset dynamic programming language; The communication instance startup module is used to call the corresponding communication protocol packaging and unpacking interface based on the device variable definition file, device communication instance definition file and communication protocol packaging and unpacking program corresponding to each device, and execute the communication instance corresponding to each device to perform data transmission between the devices.
[0014] In a third aspect of the present invention, a machine-readable storage medium is provided, on which instructions are stored, and when the instructions are executed by a processor, the processor is configured to execute the above-mentioned intelligent gateway communication protocol conversion implementation method.
[0015] In a fourth aspect of the present invention, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the intelligent gateway communication protocol conversion implementation method is implemented.
[0016] Through the above technical scheme, a smart gateway communication protocol conversion implementation method and system are provided. When responding to communication requests between devices, according to the communication protocols of each device, the corresponding communication protocol packaging and unpacking programs are loaded, and the corresponding communication protocol packaging and unpacking interfaces are registered. The loading of the device variable definition file corresponding to each device defined by the preset dynamic programming language and the loading of the device communication instance definition file corresponding to each device defined by the preset dynamic programming language are executed. Thus, according to the device variable definition file, device communication instance definition file and communication protocol packaging and unpacking program corresponding to each device, the corresponding communication protocol packaging and unpacking interface is called, and the communication instance corresponding to each device is started to perform data transmission between each device. The method and system adopt an implementation method combining static programming language and dynamic programming language, and use dynamic programming language (i.e., Lua dynamic language) to glue together various logic modules such as communication protocol, device variable definition, and communication transmission mode, and no longer need static programming language (i.e., C / C++ static language code) to define the calling relationship of each logic module. If the definition of device variables changes, or the address of variables in the communication protocol changes, or the logical relationship of the mapping of variables between devices changes, you only need to change the Lua script of the device variable definition, without recompiling the entire program implemented by C / C++; if you need to expand the communication protocol, you only need to add a new communication protocol packaging and unpacking program, and add the new communication protocol packaging and unpacking program in the Lua script, without recompiling the program implemented by C / C++. This greatly reduces the coupling of various modules of the program, reduces the complexity of hard coding, and then improves the reuse ability of various functional modules of the program, making the communication gateway program more versatile.
[0017] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the embodiments of the present invention, but do not constitute a limitation on the embodiments of the present invention. In the accompanying drawings: Figure 1 It is a flow chart of a method for implementing intelligent gateway communication protocol conversion provided by one embodiment of the present invention; Figure 2 This is a flow chart of another intelligent gateway communication protocol conversion implementation method provided by an embodiment of the present invention: Figure 3 This is a schematic diagram of a communication protocol packaging and unpacking program implementation provided by an embodiment of the present invention: Figure 4It is a schematic diagram of device variable definition implementation provided by one embodiment of the present invention; Figure 5 It is a schematic diagram of implementing variable mapping between devices provided by one embodiment of the present invention; Figure 6 It is a schematic diagram of a communication instance definition implementation provided by an embodiment of the present invention; Figure 7 is a flow chart of an execution of a communication example provided by an embodiment of the present invention; Figure 8 is a hardware block diagram of a communication gateway provided by an embodiment of the present invention; Fig. 9 It is a block diagram of an intelligent gateway communication protocol conversion implementation system provided by one embodiment of the present invention; Fig.10 It is a schematic diagram of the structure of an electronic device provided by a preferred embodiment of the present invention.
[0019] Description of Reference Numerals 10 - electronic device, 100 - processor, 101 - memory, 102 - computer program. DETAILED DESCRIPTION
[0020] The specific implementation of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the present invention, and is not used to limit the present invention.
[0021] Example 1 Figure 1 FIG. 1 is a flow chart of a method for implementing intelligent gateway communication protocol conversion provided by an embodiment of the present invention. Figure 1 As shown, an embodiment of the present invention provides a method for implementing intelligent gateway communication protocol conversion, which is executed by a communication gateway. The method is applied to the communication protocol conversion between devices connected to the communication gateway. The method includes: S110: When responding to a communication request between devices, according to each communication protocol of each device, executing loading of the corresponding communication protocol packaging and unpacking program, and executing registration of the corresponding communication protocol packaging and unpacking interface; Among them, the communication gateway may include communication gateways such as wind power converters, energy storage converters and intelligent lighting systems.
[0022] Specifically, when responding to a communication request between devices, the main program of the communication gateway starts, loads the required communication protocol packaging and unpacking programs, and calls the interface provided by the main program to register the required communication protocol packaging and unpacking interface with the main program. Loads the variable definition files of each device, calls the interface provided by the main program to establish the communication data storage space of each device, the mapping relationship between the device variables and the device communication protocol package, and the conversion relationship between the variables of the devices in the main program. Loads the device communication instance definition files of each device, and finally starts each device communication instance to start the data transmission operation on the device.
[0023] In some implementations of the present embodiment, the design rules of the above-mentioned communication protocol packaging and unpacking program include: according to the data frame format requirements of the communication protocol, using a preset static programming language and / or a preset dynamic programming language to write the communication protocol packaging and unpacking program; wherein the communication protocol packaging and unpacking program includes a packaging program and an unpacking program; the logical process of the packaging 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.
[0024] In some implementations of this embodiment, the preset static programming language includes C language or C++ language, and the preset dynamic programming language includes Lua language.
[0025] Specifically, according to the data frame format requirements of the communication protocol, the communication protocol packaging and unpacking program is written using C / C++ or Lua language. The data frame format requirements of the communication protocol refer to the byte stream rules of the transmission data frame specified by the communication protocol. Packing refers to the logical process of converting the data to be transmitted into the data frame specified by the communication protocol. Unpacking refers to the logical process of extracting the transmitted data from the data frame specified by the communication protocol.
[0026] The communication protocol packing and unpacking program is written using a preset static programming language, including: using C language or C++ language to program the logical process of the packing program and the logical process of the unpacking program to obtain the communication protocol packing and unpacking program; compiling the communication protocol packing and unpacking program into a dynamic library form through a compiler, and saving it to a corresponding device file system directory; Specifically, using C / C++ to implement the communication protocol packaging and unpacking program means using C or C++ language to implement the logical process of communication protocol packaging and unpacking, and finally compiling it into a dynamic library form through a compiler, and finally downloading it to a specific file system directory of the communication gateway device for the main program to call. The above-mentioned dynamic library form of communication protocol packaging and unpacking program is written according to the rules of writing C / C++ modules in Lua language, and can be loaded into the main program in the Lua script by the require function provided by Lua language, and the logical process of communication protocol packaging and unpacking can be called by Lua language.
[0027] The communication protocol packaging and unpacking program is written using a preset dynamic programming language, including: using the Lua language to obtain a Lua script file containing the logical process of the packaging program and the logical process of the unpacking program; and saving the communication protocol packaging and unpacking program obtained from the Lua script file to the corresponding device file system directory.
[0028] Specifically, using Lua to implement the communication protocol packaging and unpacking program writing refers to using the Lua language to implement the communication protocol packaging and unpacking logic process of the Lua script file, which is finally downloaded to the file system directory specific to the communication gateway device for the main program to call. The communication protocol packaging and unpacking program implemented by the above Lua script file can be loaded into the main program by the require function provided by the Lua language in the Lua script, and the communication protocol packaging and unpacking logic process therein can be called by the Lua language.
[0029] The file system directory specific to the communication gateway device refers to the path where the Lua language script configured in the system searches for a dynamic C / C++ dynamic library module or a package file in the form of a Lua script.
[0030] In some implementations of this embodiment, the communication protocol packaging 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, it is possible to implement a unified calling operation adopted by the main program for packaging and unpacking operations of different communication protocols without using different calling interfaces for different communication protocols. Therefore, when a new communication protocol is added, only the packaging and unpacking program package of the new communication protocol needs to be added without changing the main program, thereby making it more convenient to expand the communication protocol.
[0031] S120: respectively executing loading of a device variable definition file corresponding to each device and loading of a device communication instance definition file corresponding to each device; wherein both the device variable definition file and the device communication instance definition file are defined by a preset dynamic programming language; In some implementations of this embodiment, the definition rules of the above-mentioned device variable definition file include: 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 between the device variables between multiple devices, the device variables are defined using a preset dynamic programming language to obtain the corresponding device variable definition file.
[0032] Specifically, according to the definition of device variables, the definition of communication protocols and the conversion relationship between device variables, the Lua language is used to implement the device variable definition to obtain a device variable definition file. Among them, the definition of device variables refers to various parameters, variables and other data of the device transmitted through the communication protocol. These data are transmitted between the communication gateway and the device in the communication protocol frame format of the device. The definition of the above communication protocol also includes the mutual conversion rules 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). Using Lua language to implement the definition of the communication protocol means using Lua language to describe the various parameters of the device transmitted through the communication protocol, the name of the variable, the data type, the rules for packing and unpacking the communication protocol frame, and the conversion rules of the variables between devices.
[0033] In some implementations of this embodiment, the definition rules of the above-mentioned device communication instance definition file include: according to the transmission data of the device's variables, the mapping relationship between the device's 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 a corresponding device communication instance definition file.
[0034] Specifically, according to the communication transmission mode of the device, the definition of the communication protocol and the definition of the device variables, the Lua language is used to implement the definition of the device communication instance to obtain the device communication instance definition file. Among them, the communication transmission mode of the device refers to the communication interface between the device and the communication gateway (such as Ethernet port, UART port, CAN port, etc.) and its configuration information (such as through Ethernet port eth0, using TCP server, port number 502; for example: serial port / dev / ttyS0, baud rate 9600, no check, 8 data bits).
[0035] Among them, in this application, the definition of device variables (referring to the storage format, unit, name of the variable, etc.), the mapping relationship between the device variables and the communication protocol data frame, and the data conversion relationship between these variables among multiple devices (for example, the data A1 transmitted from device A needs to be multiplied by ab1 to be transmitted to the data B1 of device B) are implemented by lua script files. These lua script files are downloaded to a specific folder of 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 the format definition of the device variable; on the other hand, the main program calls the communication protocol packaging and unpacking program to complete the reading of the device data frame or the packaging and unpacking of the written data frame according to the mapping relationship between the variable and the communication protocol; the main program can also complete the conversion between multiple device data according to the data conversion relationship between the variables among multiple devices.
[0036] 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, execute the communication instance corresponding to each device, so as to perform data transmission between the devices.
[0037] Specifically, when responding to the communication request between devices, the method executes the loading of the corresponding communication protocol packaging and unpacking programs according to the communication protocols of each device, and executes the registration of the corresponding communication protocol packaging and unpacking interfaces. The loading of the device variable definition files corresponding to each device defined by the preset dynamic programming language and the loading of the device communication instance definition files corresponding to each device defined by the preset dynamic programming language are executed. Thus, according to the device variable definition files, device communication instance definition files and communication protocol packaging and unpacking programs corresponding to each device, the corresponding communication protocol packaging and unpacking interfaces are called, and the communication instances corresponding to each device are started to perform data transmission between the devices. The method adopts an implementation method combining static programming languages and dynamic programming languages, and uses dynamic programming languages (i.e., Lua dynamic languages) to glue together various logic modules such as communication protocols, device variable definitions, and communication transmission methods, and no longer requires static programming languages (i.e., C / C++ static language codes) to define the calling relationships of various logic modules. If the definition of device variables changes, or the address of variables in the communication protocol changes, or the logical relationship of the mapping of variables between devices changes, you only need to change the Lua script of the device variable definition, without recompiling the entire program implemented by C / C++; if you need to expand the communication protocol, you only need to add a new communication protocol packaging and unpacking program, and add the new communication protocol packaging and unpacking program in the Lua script, without recompiling the program implemented by C / C++. This greatly reduces the coupling of various modules of the program, reduces the complexity of hard coding, and then improves the reuse ability of various functional modules of the program, making the communication gateway program more versatile.
[0038] In some implementations of this embodiment, the communication mode of the communication instance corresponding to each device is a thread-to-thread communication mode. Specifically, the communication instance of each device is implemented as a thread in the main program.
[0039] In some implementations of this embodiment, when loading the device variable definition files corresponding to each device, based on the device variable definition files corresponding to each device, a communication data storage space corresponding to each device, a mapping relationship between the device variables and the corresponding communication protocol data frames, and a data conversion relationship between the device variables between multiple devices are established.
[0040] It should be noted that each communication protocol has a unique name in the system and corresponds to the communication protocol through the communication protocol packaging and unpacking program files. This name can be referred to as the communication protocol name. When the main program loads the communication protocol packaging and unpacking program, it is defined by the communication protocol packaging and unpacking program; the variable definition of the device is defined by the device variable definition file. Each device has a unique device variable definition file corresponding to it, and has a unique name corresponding to it. This name can be called the device name. The device name is provided by the device variable definition file. When the main program loads the device variable definition file, the main program obtains it from the device variable definition file.
[0041] In some implementations of this embodiment, the communication instance definition of the device includes a communication protocol name, a device name, and a communication transmission mode of the device.
[0042] 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.
[0043] In some implementations of this embodiment, the communication instance can find the communication protocol packaging 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 necessary information for communicating with the device, and based on this information, the communication instance can realize communication with the device.
[0044] Example 2 Figure 2 is a flowchart of another intelligent gateway communication protocol conversion implementation method provided by an embodiment of the present invention, such as Figure 2 As shown, the present invention provides a method for implementing intelligent gateway communication protocol conversion, taking the communication gateway operating system using the linux 3.10.108 armv5tejl architecture and the lua version being Lua 5.4.6 as an example, the specific process is as follows: Step S1: According to the requirements of the communication protocol, use C / C++ or Lua language to write the communication protocol packaging and unpacking program; Step S2: according to the definition of the device variables, use the Lua language to implement the device variable definition; Step S3: according to the communication transmission mode, communication protocol definition and device variable definition of the device, use Lua language to implement the device communication instance definition; Step S4: The gateway main program starts, loads the required communication packaging and unpacking programs, registers the required communication protocol packaging and unpacking interface with the main program, loads the device variable definition Lua program file implemented by S2, establishes the storage space of the variables of each device, the mapping relationship between the device variables and the communication protocol package, and the conversion relationship between the variables of the devices in the main program, and loads the communication instance definition Lua program file implemented by S3; Step S5: Start each device communication instance and start data transmission operation on the device.
[0045] Please refer to Figure 3 , Figure 3 This is a schematic diagram of a communication protocol packaging and unpacking program implementation provided by an embodiment of the present invention. The communication protocol implemented in this embodiment is implemented in C++, and the name of the communication protocol is: ModbusTCPServer; The packaging function is: int enpack(vector <u8>data, vector <var>vars) { … } The unpacking function is: in depack(vector <u8>data, vector <var>vars) { … } The C++ source code implemented above also needs to be encapsulated into a program that can be loaded in a Lua script according to the rules of writing C / C++ modules in Lua language, loaded into the main program by the require function provided by Lua language, and the communication protocol packaging and unpacking logic process can be called by Lua language.
[0046] Please refer to Figure 4 , Figure 4 This is a schematic diagram of a device variable definition implementation provided by an embodiment of the present invention. The device variable definition consists of a name, a variable, and a variable mapping table. The name implemented in this embodiment is pcs, and the variables are UA, UB, ..., CntrW, ... in sequence.
[0047] In this embodiment, each variable has name, type, address, class, readmode, writemode, and unit members in sequence. name indicates the name of the variable, type indicates the storage type of the variable, class indicates the class definition of the variable in the communication protocol, readmode indicates the read mode of the variable, writemode indicates the write mode of the variable, and uint indicates the unit. Among them, readmode / writemode never means no read / write, 0 means asynchronous read / write, and time (such as 20ms) means read / write interval of 20ms. The variable mapping table consists of an array of inter-device variable mapping entries, and the inter-device variable mapping entries are implemented as follows: Figure 5 As shown, Figure 5 1 is a schematic diagram of implementing inter-device variable mapping provided by an embodiment of the present invention. Inter-device variable mapping consists of from, to and function. From represents the source variable, which represents the variable to be converted; to represents the target variable, which represents the variable to be generated; function represents the generating function; Figure 5 What is implemented is the variable conversion from pcs.UA to ems.UA, which means 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.variable 1" is used to represent variable 1 of device a, and the present invention is not limited to this representation method, as long as the representation method that can represent the subordinate relationship is fine).
[0048] Please refer to Figure 6 , Figure 6 It is a schematic diagram of the implementation of the communication instance definition provided by an embodiment of the present invention. The communication instance definition consists of a communication protocol name, a device name, and a communication mode. Among them, the communication protocol name corresponds to the communication protocol packaging and unpacking program, the device name corresponds to the device variable definition, and the communication mode corresponds to the communication mode table. In this embodiment, the communication mode table consists of dev, para, ..., dev represents the device file of the communication instance to the system, and para represents the communication parameters; Figure 6 Indicates that the communication device is / dev / ttyS0, and the parameters 9600,8,n,1 indicate a baud rate of 9600, 8 data bits without parity, and 1 stop bit. The communication instance records all the information for communicating with the corresponding device. By loading the communication instance into the main program, the corresponding device communication information is imported, and communication with the device can be established later to achieve data transmission.
[0049] Figure 7 FIG. 1 is a flow chart of a communication example execution provided by an embodiment of the present invention. Figure 7 As shown in the figure, two communication example processes are shown: the flowchart on the left is the Master / Client mode, and the flowchart on the right is the Slave / Sever mode. The Master / Client mode means that the communication gateway acts as the master, actively sends data to the device, and then waits for the device to respond; the Slave / Sever mode means that the gateway acts as a slave, waiting to receive the data frame sent by the device, and then processes the data frame and responds.
[0050] It should be noted that in practice there may be more than just these two communication instance modes. Figure 7 Only implementations of two communication examples are shown.
[0051] For the Master / Client communication mode, first, the communication instance thread creates, initializes and opens the communication device S according to the communication mode of this communication instance obtained by the main program; then, according to the device variable definition, find out the variables that currently need to be read from the device, and then create a variable read data frame, which is sent to the device by the device communication interface S, and then wait for the device to reply. After receiving the device reply, unpack the value of the device variable from the device reply data frame and store it in the storage location of the device variable. After reading the variable value, convert the read variable into the variable required by other devices according to the above device variable mapping information, and store it in the variable location of other devices; then, according to the device variable definition, find out the variables that currently need to be written to the device, read the variable value from the storage location of the variable, and then create a variable write data frame, which is sent to the device by the device communication interface S, and then wait for the device to reply.
[0052] For the Slave / Sever communication mode, first, the communication instance thread creates, initializes and opens the communication device S according to the communication mode of this communication instance obtained by the main program; then waits to receive data from S. After receiving data from S, it parses whether it is a variable read or write command; if it is a variable write command, unpack the variable value and write it to the storage location corresponding to the variable. According to the above inter-device variable mapping information, the read variable is converted into the variable required by other devices and stored in the variable location of other devices. Then, a variable write back command data frame is created and sent back to the device through S; if it is a variable read command, unpack the variable to be read, read the variable value from the variable storage location, pack it into a variable read back command frame, and send back to the device through S.
[0053] Figure 8 FIG. 1 is a hardware block diagram of a communication gateway provided by an embodiment of the present invention. Figure 8 As shown, the communication gateway hardware uses the NUC972 core board, 64M RAM, 128M NandFlash, three external RS485 communication interfaces, two CAN communication interfaces and two Ethernet communication interfaces, and adopts 24 DC power supply.
[0054] Through the description of this embodiment, it can be seen that the implementation method of combining static language and dynamic language is adopted, and the communication protocol, device variable definition, communication transmission mode and other logical modules are glued together using Lua language, and there is no need to hard code to define the calling relationship of each logical module. If the device variable definition or the address of the variable in the communication protocol changes, or the logical relationship of the mapping of variables between devices changes, it is only necessary to change the Lua script of the device variable definition without recompiling the entire program implemented by C / C++; if a new communication protocol needs to be expanded, it is only necessary to increase the communication protocol packaging / unpacking program implementation and change the Lua script of the communication instance definition without recompiling the program implemented by C / C++. This greatly reduces the coupling of each module of the program, reduces the complexity of hard coding, improves the reuse ability of functional modules, and makes the communication gateway program more versatile.
[0055] Example 3 Fig. 9 FIG. 1 is a block diagram of a smart gateway communication protocol conversion implementation system provided by an embodiment of the present invention. Fig. 9 As shown, an embodiment of the present invention provides an intelligent gateway communication protocol conversion implementation system, which is deployed in a communication gateway. The system is applied to the communication protocol conversion between devices connected to the communication gateway. The system includes: A request response module, used for, when responding to a communication request between devices, executing the loading of the corresponding packaging and unpacking programs of each communication protocol according to each communication protocol of each device, and executing the registration of the corresponding packaging and unpacking interfaces of each communication protocol; A definition file loading module, used to respectively execute the loading of a device variable definition file corresponding to each device and the loading of a device communication instance definition file corresponding to each device; wherein the device variable definition file and the device communication instance definition file are both defined by a preset dynamic programming language; The communication instance startup module is used to call the corresponding communication protocol packaging and unpacking interface based on the device variable definition file, device communication instance definition file and communication protocol packaging and unpacking program corresponding to each device, and execute the communication instance corresponding to each device to perform data transmission between the devices.
[0056] Specifically, when responding to communication requests between devices, the system executes the loading of the corresponding communication protocol packaging and unpacking programs according to the communication protocols of each device, and executes the registration of the corresponding communication protocol packaging and unpacking interfaces. The system executes the loading of the device variable definition files corresponding to each device defined by the preset dynamic programming language and the loading of the device communication instance definition files corresponding to each device defined by the preset dynamic programming language. Thus, according to the device variable definition files, device communication instance definition files and communication protocol packaging and unpacking programs corresponding to each device, the corresponding communication protocol packaging and unpacking interfaces are called, and the communication instances corresponding to each device are started to perform data transmission between the devices. The system adopts an implementation method combining static programming languages and dynamic programming languages, and uses dynamic programming languages (i.e., Lua dynamic languages) to glue together various logic modules such as communication protocols, device variable definitions, and communication transmission methods, and no longer requires static programming languages (i.e., C / C++ static language codes) to define the calling relationships of various logic modules. If the definition of device variables changes, or the address of variables in the communication protocol changes, or the logical relationship of the mapping of variables between devices changes, you only need to change the Lua script of the device variable definition, without recompiling the entire program implemented by C / C++; if you need to expand the communication protocol, you only need to add a new communication protocol packaging and unpacking program, and add the new communication protocol packaging and unpacking program in the Lua script, without recompiling the program implemented by C / C++. This greatly reduces the coupling of various modules of the program, reduces the complexity of hard coding, and then improves the reuse ability of various functional modules of the program, making the communication gateway program more versatile.
[0057] Example 4 The embodiment of the present invention further provides a machine-readable storage medium, on which instructions are stored. When the instructions are executed by the processor 100, the processor 100 is configured to execute the above-mentioned intelligent gateway communication protocol conversion implementation method.
[0058] Machine-readable storage media include permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules 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 technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0059] An embodiment of the present invention further 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, the above-mentioned intelligent gateway communication protocol conversion implementation method is implemented.
[0060] like Fig.10 FIG. 1 is a schematic diagram of an electronic device provided by an embodiment of the present invention. Fig.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, the steps in the above method embodiment are implemented. Alternatively, when the processor 100 executes the computer program 102, the functions of each module / unit in the above device embodiment are implemented.
[0061] Exemplarily, the computer program 102 may be divided into one or more modules / units, one or more modules / units are stored in the memory 101, and are executed by the processor 100 to complete the present invention. One or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 102 in the electronic device 10. For example, the computer program 102 may be divided into a request response module, a definition file loading module, and a communication instance startup module.
[0062] The electronic device 10 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The electronic device 10 may include, but is not limited to, a processor 100 and a memory 101. Those skilled in the art will appreciate that Fig.10 It is only an example of the electronic device 10 and does not constitute a limitation of the electronic device 10. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.
[0063] The processor 100 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0064] The memory 101 may be an internal storage unit of the electronic device 10, such as a hard disk or memory of the electronic device 10. The memory 101 may also be an external storage device of the electronic device 10, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (FlashCard), etc. equipped on the electronic device 10. Further, the memory 101 may also include both an internal storage unit of the electronic device 10 and an external storage device. The memory 101 is used to store computer programs and other programs and data required by the electronic device 10. The memory 101 may also be used to temporarily store data that has been output or is to be output.
[0065] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by 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 embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0066] It should be understood by those skilled in the art that the embodiments of the present application may be provided as methods, systems, or computer program 102 products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may 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 codes.
[0067] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program 102 products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by the computer program 102 instructions. These computer program 102 instructions can be provided to a processor 100 of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor 100 of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0068] These computer program 102 instructions may also be stored in a computer readable memory 101 that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory 101 produce an article of manufacture including an instruction device that implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0069] These computer program 102 instructions may also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0070] It should also be noted that the term "includes", "comprising" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the existence of other identical elements in the process, method, commodity or device including the element.
[0071] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.< / var> < / var>
Claims
1. A method for implementing intelligent gateway communication protocol conversion, characterized in that: The method is performed by a communication gateway and is applied to the communication protocol conversion between devices connected to the communication gateway. The method comprises: When responding to a communication request between devices, according to each communication protocol of each device, the corresponding communication protocol packaging and unpacking program is loaded, and the corresponding communication protocol packaging and unpacking interface is registered; Respectively executing the loading of the device variable definition file corresponding to each device and the loading of the device communication instance definition file corresponding to each device; wherein the device variable definition file and the device communication instance definition file are both defined by a preset dynamic programming language; Based on the device variable definition file, device communication instance definition file and communication protocol packing and unpacking program corresponding to each device, the corresponding communication protocol packing and unpacking interface is called, and the communication instance corresponding to each device is executed to perform data transmission between the devices.
2. The method for implementing intelligent gateway communication protocol conversion according to claim 1, characterized in that: The definition rules of the device variable definition file include: According to the transmission data of the device variables, the mapping relationship between the device variables and the communication protocol data frame, and the data conversion relationship between the device variables between multiple devices, the device variables are defined using a preset dynamic programming language to obtain the corresponding device variable definition file.
3. The method for implementing intelligent gateway communication protocol conversion according to claim 1, characterized in that: The definition rules of the device communication instance definition file include: According to the transmission data of the device's variables, the mapping relationship between the device's variables and the communication protocol data frame, and the device's communication transmission mode, a device communication instance is defined using a preset dynamic programming language to obtain a corresponding device communication instance definition file.
4. The method for implementing intelligent gateway communication protocol conversion according to claim 1, characterized in that: The design rules of the communication protocol packaging and unpacking program include: According to the data frame format requirements of the communication protocol, a communication protocol packing and unpacking program is written 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; The logic process of the packaging 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 logic 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.
5. The method for implementing intelligent gateway communication protocol conversion according to claim 4, characterized in that: The preset static programming language includes C language or C++ language, and the preset dynamic programming language includes Lua language; Use the preset static programming language to write the communication protocol packaging and unpacking program, including: Use C language or C++ language to program the logical process of the packing program and the logical process of the unpacking program to obtain the communication protocol packing and unpacking program; After the communication protocol packaging and unpacking program is compiled into a dynamic library form by the compiler, it is saved in the corresponding device file system directory; Use the preset dynamic programming language to write the communication protocol packaging and unpacking program, including: Use Lua language to obtain Lua script files containing the logical process of the packaging program and the logical process of the unpacking program; The communication protocol packaging and unpacking program obtained from the lua script file is saved in the corresponding device file system directory.
6. The method for implementing intelligent gateway communication protocol conversion according to claim 1, characterized in that: The communication mode of the communication instance corresponding to each device is the mode of inter-thread communication.
7. The method for implementing intelligent gateway communication protocol conversion according to claim 1, characterized in that: When loading the device variable definition files corresponding to each device, based on the device variable definition files corresponding to each device, 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 between multiple devices are established.
8. An intelligent gateway communication protocol conversion implementation system, characterized in that: Deployed on a communication gateway, the system is applied to the communication protocol conversion between devices connected to the communication gateway, and the system includes: A request response module, used for, when responding to a communication request between devices, executing the loading of the corresponding packaging and unpacking programs of each communication protocol according to each communication protocol of each device, and executing the registration of the corresponding packaging and unpacking interfaces of each communication protocol; A definition file loading module, used to respectively execute the loading of a device variable definition file corresponding to each device and the loading of a device communication instance definition file corresponding to each device; wherein the device variable definition file and the device communication instance definition file are both defined by a preset dynamic programming language; The communication instance startup module is used to call the corresponding communication protocol packaging and unpacking interface based on the device variable definition file, device communication instance definition file and communication protocol packaging and unpacking program corresponding to each device, and execute the communication instance corresponding to each device to perform data transmission between the devices.
9. A machine-readable storage medium having instructions stored thereon, characterized in that: When the instruction is executed by a processor, the processor is configured to execute the intelligent gateway communication protocol conversion implementation method as described in any one of claims 1 to 7.
10. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the intelligent gateway communication protocol conversion implementation method described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Multi-protocol conversion access system and method
CN113938529A
Communication protocol coding method and system
CN116016691A
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
Cited By
Flight simulator dynamic coding and decoding system and method based on rule decoupling
CN120416299A