CN109951465B - Data communication method based on factory method mode and dynamic loading module - Google Patents

Data communication method based on factory method mode and dynamic loading module Download PDF

Info

Publication number
CN109951465B
CN109951465B CN201910173596.8A CN201910173596A CN109951465B CN 109951465 B CN109951465 B CN 109951465B CN 201910173596 A CN201910173596 A CN 201910173596A CN 109951465 B CN109951465 B CN 109951465B
Authority
CN
China
Prior art keywords
communication
communication protocol
data
module
protocol information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910173596.8A
Other languages
Chinese (zh)
Other versions
CN109951465A (en
Inventor
刘兴革
佘秋野
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Li Xing Kai Beijing Energy System Technology Co ltd
Original Assignee
Li Xing Kai Beijing Energy System Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Li Xing Kai Beijing Energy System Technology Co ltd filed Critical Li Xing Kai Beijing Energy System Technology Co ltd
Priority to CN201910173596.8A priority Critical patent/CN109951465B/en
Publication of CN109951465A publication Critical patent/CN109951465A/en
Application granted granted Critical
Publication of CN109951465B publication Critical patent/CN109951465B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention discloses a data communication method based on a factory method mode and a dynamic loading module, which comprises the following steps: acquiring first communication protocol information of a data input end and second communication protocol information of a data output end; the factory selects and loads a dynamic link library of a corresponding communication function module according to the first communication protocol information and the second communication protocol information; the dynamic link library respectively constructs an input end communication module and an output end communication module corresponding to the first communication protocol and the second communication protocol according to the read parameter point configuration file information, the first communication protocol information and the second communication protocol information; and activating a background thread for processing data to package the real-time data acquired by the input end communication module from the data input end, and sending the packaged data to a destination address through the data output end by the data output end communication module.

Description

Data communication method based on factory method mode and dynamic loading module
Technical Field
The invention relates to a data communication method, in particular to a data communication method based on a factory method mode and a dynamic loading module.
Background
Factory method modes, also known as factory modes, polymorphic factory modes and virtual builder modes, define a factory parent class that is responsible for defining the common interface for creating objects, and subclasses that are responsible for generating specific objects.
The factory method model defers the creation of a particular product to a subclass of factory classes (a particular factory) where the factory classes are no longer responsible for the creation of all products, but rather only present the interfaces that the particular factory must implement. When a new product is added, the logic of the plant class is not required to be modified, and a new plant subclass is expanded. Thus, the advantages of the package object creating process are maintained, and meanwhile, the open and closed principle is still met.
For a long time, the demand for data communication functions has been the key and pain point of the industries such as electric power and energy. In the current industry, a mature and stable solution is provided for various international/domestic standard communication protocols. However, the following two major disadvantages remain:
1. only one or a few communication protocols can be adapted, and the expansion is not possible. Once a new communication protocol appears, only the software product can be reconstructed and even re-developed.
2. A simple factory model is used to match different communication protocols. The number of communication protocols that this kind of product can adapt to is not very small, but the defect of the simple factory model itself (not conforming to the open closure principle) that when a new communication protocol appears, the factory class logic needs to be modified, and the product code needs to be changed and recompiled. Therefore, the original performance and stability of the product cannot be ensured.
Disclosure of Invention
Aiming at the defects of the prior art, the invention provides a data communication method based on a factory method mode and a dynamic loading module.
The invention discloses a data communication method based on a factory method mode and a dynamic loading module, which executes a first communication protocol at a data input end and a second communication protocol at a data output end, and comprises the following steps:
acquiring first communication protocol information of a data input end and second communication protocol information of a data output end;
step two, the factory selects and loads a dynamic link library of a corresponding communication function module according to the first communication protocol information and the second communication protocol information;
thirdly, the dynamic link library respectively constructs an input end communication module and an output end communication module corresponding to the first communication protocol and the second communication protocol according to the read parameter point configuration file information, the first communication protocol information and the second communication protocol information;
and activating a background thread for processing data to encapsulate the real-time data acquired by the input end communication module from the data input end, and transmitting the encapsulated data to a destination address through the data output end by the data output end communication module.
In the first step of the data communication method based on the factory method mode and the dynamic loading module, the first communication protocol information and the second communication protocol information are obtained by reading the main configuration file.
In the second step of the data communication method based on the factory method mode and the dynamic loading module, the factory searches the existing dynamic link library of the corresponding communication function module according to the first communication protocol information and the second communication protocol information and the pre-specified path.
In the second step of the data communication method based on the factory method mode and the dynamic loading module according to the present invention, if there is no existing dynamic link library of the corresponding communication function module in the pre-designated path, a new dynamic link library is compiled according to the predetermined specification in the factory, the first communication protocol information and the second communication protocol information, and the new dynamic link library is stored according to the pre-designated path.
In the fourth step of the data communication method based on the factory method mode and the dynamic loading module, the background thread acquires real-time data from the input end communication module in an active request or subscription mode.
In the fourth step of the data communication method based on the factory method mode and the dynamic loading module, whether the real-time data is secondarily processed or not is determined according to the parameter information of the main configuration file.
In the fourth step of the data communication method based on the factory method mode and the dynamic loading module, real-time data are packaged according to the requirement of the data output end communication module on the data format.
The data communication method based on the factory method mode and the dynamic loading module can adapt to various communication protocols and carry out data interaction, and can overcome the defect that the expansibility of modifying and recompiling codes is poor in order to adapt to a new communication protocol in the prior art.
Drawings
FIG. 1 is a flow diagram of a data communication method based on a factory method model and a dynamic load module according to the present invention;
FIG. 2 is a schematic flow chart of writing data read by a Modbus protocol into a MySQL database by applying the data communication method based on the factory method mode and the dynamic loading module according to the invention;
fig. 3 is a schematic flow chart of the data communication method based on the factory method mode and the dynamic loading module according to the present invention, which is used for realizing that a dynamic link library of an Oracle functional module is newly added and writing data read by a 104 protocol into an Oracle database.
Detailed Description
The present invention is further described in detail below with reference to the attached drawings so that those skilled in the art can implement the invention by referring to the description text.
As shown in fig. 1, the data communication method based on the factory method mode and the dynamic loading module according to the present invention is to cope with the situation that the communication protocol of the data input terminal is different from the communication protocol of the data output terminal, that is, the first communication protocol is executed at the data input terminal and the second communication protocol is executed at the data output terminal.
Thus, in order to adapt to multiple types of communication protocols and perform data interaction, as shown in fig. 1, the present invention includes the following steps:
step 101, acquiring first communication protocol information of a data input end and second communication protocol information of a data output end.
In this step 101, the first communication protocol information and the second communication protocol information may be acquired by reading the master profile.
Table 1 below shows a main configuration file information structure, and as can be seen from the table, the first communication protocol information and the second communication protocol information can be obtained by reading the main configuration file through the meaning information corresponding to the specific field name.
Table 1:
name of field Means of
INPUT/BasePath Subfolders of first communication protocol(s) configuration file
IO/Output Filename of second communication protocol type configuration file
And 102, selecting and loading a dynamic link library of a corresponding communication function module by the factory according to the first communication protocol information and the second communication protocol information.
In this step, the factory searches the existing dynamic link library of the corresponding communication function module according to the first communication protocol information and the second communication protocol information and according to a pre-specified path. And if the existing dynamic link library of the corresponding communication function module is found, loading the dynamic link library for subsequent steps. If no dynamic link library exists, a corresponding prompt can be given. However, in order to implement data interaction between different communication protocols, the present invention may rebuild a corresponding new dynamic link library, that is, if there is no existing dynamic link library of a corresponding communication function module in a pre-specified path, a new dynamic link library is compiled according to a predetermined specification in a factory, and first and second communication protocol information, and the new dynamic link library is stored according to the pre-specified path.
That is, if an undeveloped communication protocol occurs, development and testing are performed on the protocol only according to the specifications agreed in the factory, the protocol is compiled into a dynamic link library to be loaded and called after the development and testing are completed, and then normal data interaction and processing flows are performed. All the operation steps do not relate to the modification and compilation of the existing product codes, and do not influence the original various characteristics of the products.
And 103, respectively constructing an input end communication module and an output end communication module corresponding to the first communication protocol and the second communication protocol by the dynamic link library according to the read parameter point configuration file information, the first communication protocol information and the second communication protocol information.
As shown in table 2 below, in the parameter point profile structure, different columns correspond to different information,
table 2:
column A Parameter point indexing
Column B Address of parameter point in first communication protocol
Column C Address of parameter point in second communication protocol
Column D Description of parameter points
Column E Multiplying power of parameter point
Column F Offset of parameter point
Column G onwards Additional information, parsed by a specific communication protocol
In this step, the parameter point configuration file information is read to obtain an information list of the parameter points, so that the parameter points can be used when an input end communication module and an output end communication module are constructed.
The loaded dynamic link library initializes and constructs the communication module corresponding to each other by reading the information in the communication protocol sub-configuration file (the file path is read from the table 1) and combining the read parameter point information.
And 104, activating a background thread for processing data to package the real-time data acquired by the input end communication module from the data input end, and sending the packaged data to a destination address through the data output end by the data output end communication module.
In this step, the background thread acquires real-time data from the input end communication module in an active request or subscription manner.
In this step, whether to perform secondary processing on the real-time data, for example, whether to perform magnification processing or offset processing, needs to be determined according to parameter information of a specific communication protocol sub-configuration file.
In this step, the real-time data is encapsulated according to the requirement of the data output end communication module on the data format.
When the data communication method based on the factory method mode and the dynamic loading module is adopted, the communication protocol adapted in specific operation is not written in codes but is determined by a main configuration file. If an undeveloped communication protocol appears, development and test are carried out on the protocol only according to the convention specification in a factory, and then the protocol is compiled into a dynamic link library for loading and calling of a software platform, and then normal data interaction and processing flow are carried out. All the operation steps do not relate to the modification and the compilation of the existing product codes, and do not influence the original various characteristics of the products. In addition, the configuration files of the whole software platform are realized in a distributed mode, the main configuration, the parameter point configuration and the communication protocol configuration are stored independently and are responsible for the functions of each user, and the user can modify, maintain, backup and restore the configuration files conveniently.
Fig. 2 is a schematic flow chart illustrating a process of writing data read by a Modbus protocol into a MySQL database by applying the data communication method based on the factory method mode and the dynamic load module according to the present invention.
Specifically, an input protocol Modbus and an output protocol MySQL are obtained by reading information in a master configuration file;
the communication protocol information at the two ends is transmitted to a factory, and the factory searches a dynamic link library (i.e. a plug-in) of Modbus and MySQL communication function modules in a specified path according to the protocol information and loads the dynamic link library to a software platform (at this moment, the existence of the dynamic link library is assumed);
acquiring an information list of the parameter points by reading information in the parameter point configuration file for the communication protocol function modules at the two ends to use;
the Modbus and MySQL dynamic link libraries are used for initializing and constructing respective corresponding communication modules by reading information in respective communication protocol sub-configuration files and combining read parameter point information;
and activating a background thread, periodically executing the Modbus module to read data, performing secondary processing and packaging by the platform, transmitting the data to the MySQL module, and writing the data to a destination address by the MySQL module.
Fig. 3 is a schematic flow chart of a process of implementing a new addition of an Oracle functional module dynamic link library and writing data read by a 104 protocol into an Oracle database by applying the data communication method based on the factory method mode and the dynamic loading module according to the present invention.
The method comprises the following specific steps:
acquiring an input protocol 104 and an output protocol Oracle by reading information in the main configuration file;
the communication protocol information of the two ends is transmitted to a factory, and the factory finds that the dynamic link library does not exist when looking up the Oracle functional module according to the protocol information;
therefore, according to the appointed standard of the read data interface, writing codes aiming at the property of Oracle to realize the corresponding function;
compiling into a dynamic link library after the development and the test are finished, and placing the dynamic link library to a path appointed by a software platform;
after the software platform is started, a specified path is searched, and the existence of a dynamic link library of the Oracle functional module is found;
then loading a dynamic link library (plug-in) of the 104 and Oracle communication functional module to a software platform;
the information list of the parameter points is obtained by reading the information in the parameter point configuration file and is used by the communication protocol function modules at the two ends;
104, an Oracle dynamic link library, which is used for initializing and constructing respective corresponding communication modules by reading information in respective communication protocol sub-configuration files and combining the read parameter point information;
and finally, activating a background thread, periodically executing 104 module read data, performing secondary processing and packaging by the platform, transmitting to the Oracle module, and writing data to the destination address by the Oracle module.
While embodiments of the invention have been described above, it is not limited to the applications set forth in the description and the embodiments, which are fully applicable in various fields of endeavor to which the invention pertains, and further modifications may readily be made by those skilled in the art, it being understood that the invention is not limited to the details shown and described herein without departing from the general concept defined by the appended claims and their equivalents.

Claims (5)

1. A data communication method based on a factory method mode and a dynamic loading module, wherein a first communication protocol is executed at a data input end, and a second communication protocol is executed at a data output end, the method comprising the steps of:
acquiring first communication protocol information of a data input end and second communication protocol information of a data output end;
step two, selecting and loading a dynamic link library of a corresponding communication function module by a factory according to the first communication protocol information and the second communication protocol information;
the factory searches an existing dynamic link library of the corresponding communication function module according to the first communication protocol information and the second communication protocol information and a pre-specified path;
if the pre-designated path does not have the existing dynamic link library of the corresponding communication function module, compiling a new dynamic link library according to the preset specification in the factory, the first communication protocol information and the second communication protocol information, and storing the new dynamic link library according to the pre-designated path;
thirdly, constructing an input end communication module and an output end communication module corresponding to the first communication protocol and the second communication protocol respectively according to the read parameter point configuration file information, the first communication protocol information and the second communication protocol information by the dynamic link library;
and step four, activating a background thread for processing data to package the real-time data acquired by the input end communication module from the data input end, and sending the packaged data to a destination address through the data output end by the data output end communication module.
2. The factory method mode and dynamically loaded module based data communication method of claim 1, wherein in step one, the first communication protocol information and the second communication protocol information are obtained by reading a master configuration file.
3. The factory method model and dynamic loading module-based data communication method of claim 1, wherein in step four, the background thread obtains real-time data from the input-side communication module in an active request or subscription manner.
4. The factory method mode and dynamically loaded module based data communication method according to claim 2, wherein in said fourth step, it is determined whether to perform the secondary processing on the real-time data according to the parameter information of the master profile.
5. The factory method mode and dynamic load module-based data communication method of claim 2, wherein in step four, real-time data is encapsulated according to the data format requirements of the data output side communication module.
CN201910173596.8A 2019-03-08 2019-03-08 Data communication method based on factory method mode and dynamic loading module Active CN109951465B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910173596.8A CN109951465B (en) 2019-03-08 2019-03-08 Data communication method based on factory method mode and dynamic loading module

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910173596.8A CN109951465B (en) 2019-03-08 2019-03-08 Data communication method based on factory method mode and dynamic loading module

Publications (2)

Publication Number Publication Date
CN109951465A CN109951465A (en) 2019-06-28
CN109951465B true CN109951465B (en) 2022-11-08

Family

ID=67009326

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910173596.8A Active CN109951465B (en) 2019-03-08 2019-03-08 Data communication method based on factory method mode and dynamic loading module

Country Status (1)

Country Link
CN (1) CN109951465B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6601192B1 (en) * 1999-08-31 2003-07-29 Accenture Llp Assertion component in environment services patterns
CN103607702A (en) * 2013-11-15 2014-02-26 上海大汉三通通信股份有限公司 A method and system for carrying out communication among different platforms in short message service
CN107911642A (en) * 2017-11-24 2018-04-13 沈阳理工大学 A kind of cable television network management system
CN107980124A (en) * 2017-08-31 2018-05-01 深圳市元征科技股份有限公司 A kind of collecting method and server

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8490074B2 (en) * 2007-11-27 2013-07-16 The Boeing Company Aircraft software part library

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6601192B1 (en) * 1999-08-31 2003-07-29 Accenture Llp Assertion component in environment services patterns
CN103607702A (en) * 2013-11-15 2014-02-26 上海大汉三通通信股份有限公司 A method and system for carrying out communication among different platforms in short message service
CN107980124A (en) * 2017-08-31 2018-05-01 深圳市元征科技股份有限公司 A kind of collecting method and server
CN107911642A (en) * 2017-11-24 2018-04-13 沈阳理工大学 A kind of cable television network management system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
车载设备嵌入式监控组态软件的研究与应用;金敏等;《电子测量与仪器学报》;20121115(第11期);全文 *

Also Published As

Publication number Publication date
CN109951465A (en) 2019-06-28

Similar Documents

Publication Publication Date Title
CN107273286B (en) Scene automatic test platform and method for task application
US8214803B2 (en) Program testing method and testing device
CN102841841B (en) A kind of test asserts processing method and system
CN106293664A (en) Code generating method and device
CN111752571A (en) Program upgrading method, device, equipment and storage medium
CN112306861A (en) Unittest and Jenkins tool-based interface automatic testing system and method
CN111399828A (en) Model-driven logic device modeling method and terminal
CN111966760A (en) Hive data warehouse-based test data generation method and device
CN110109658B (en) ROS code generator based on formalized model and code generation method
CN109951465B (en) Data communication method based on factory method mode and dynamic loading module
Kulkarni et al. Abstraction of UML class diagram from the input java program
CN113590491A (en) Test platform and product test method
CN116302054A (en) Development method and device of software project, storage medium and electronic equipment
CN114489675A (en) Processing method and device of automatic driving system and electronic equipment
CN103220186A (en) Communication equipment testing method and system
CN114416305A (en) Robot engine implementation method and system and electronic equipment
CN111930387A (en) Integration method and device of integration package, electronic equipment and storage medium
CN105204383A (en) Generation method and device for application servo system
CN107229564B (en) Pressure simulation method and device
CN116501744B (en) Automatic form building and warehousing method and device for simulation data and computer equipment
CN116451795B (en) Quantum circuit diagram processing method and device, electronic equipment and storage medium
CN116976443B (en) Performance index debugging method, terminal equipment and computer storage medium
Rhizadi et al. Database generator to support product derivation in SPL
CN116204429B (en) Code organization and debugging method, system and storage medium thereof
CN115495442B (en) Database operation file generation method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant