A method for data exchange and synchronization between programs
By using memory-mapped files and mutex locks in an open automatic test system, data exchange and synchronization between programs are realized, and the problems of low efficiency, large resource utilization, poor security and insufficient reliability in the existing technology are solved. Simplifies the data exchange process and improves data security.
Patent Information
- Application Number
- CN202111629145.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2041-12-28
AI Technical Summary
In an open automatic testing system, data exchange and synchronization between programs have problems such as low efficiency, large resource utilization, poor security and insufficient reliability, and the prior art cannot solve these problems at the same time.
Through the data display program, copy the configuration information file of the data acquisition program to the location of the data acquisition program, call the ShowDataToSG() or ShowDataToVW() function, create a memory map file and use a mutex to achieve data exchange and synchronization, and use custom messages and memory Map file transfer data.
It realizes simplification and synchronization of data exchange between programs, reduces workload, improves data security, and ensures the efficiency and reliability of data transmission.
Smart Images

Figure CN114327922B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of automatic test and measurement, and in particular relates to a method for data exchange and synchronization between programs. Background Art
[0002] In the field of automatic test and measurement, it is often necessary to collect and display the measurement results in instruments. In an open automatic test system, the data acquisition program is an independently executable program, and the data display platform is an independent program. Therefore, the data exchange and synchronization between the two becomes the key and difficulty of the design of an open automatic test system. In this article, the open automatic test system is mainly used for the research and development, debugging and generation of electronic products such as electronic components, RF components, and microwave components to ensure that qualified objects under test can be put into use. An open automatic test system is generally composed of automatic test equipment, a general test platform, an extensible test program set, and a test environment.
[0003] Automatic test equipment includes: test and measurement instruments (such as signal generators, vector signal sources, spectrum analyzers, vector network analyzers, oscilloscopes, noise analyzers, impedance analyzers, etc.), computers, and switch matrices.
[0004] The general testing platform includes: data display program, database, data report, etc.
[0005] The extensible set of test programs includes: Data acquisition programs.
[0006] The open automatic testing system has the advantages of flexibly calling third-party components to reduce the workload of test case development; realizing the standardization of test cases, reducing the dependence of test cases on individuals; providing test case reuse, test cases and scripts can be reused to protect the assets of testers; providing a scalable test execution framework and automatic testing support; providing one-click test execution to reduce the professional requirements of testers; providing a flexible production and manufacturing framework that can quickly switch production lines and enhance the adaptability of production lines; providing scalable test data management to help users uniformly manage test data and reduce the coupling between test data and test scripts.
[0007] Data exchange (communication) between applications has always been a problem that has troubled many programmers. Although various solutions have emerged, no solution is perfect so far. The main problems we face in data exchange communication are:
[0008] (1) Data exchange and communication issues: Data exchange should be as simple and convenient as possible, and the existing program code structure should not be modified or only a minimal amount of code should be written during communication;
[0009] (2) Data exchange efficiency: less time consumption and less resource occupation;
[0010] (3) Data synchronization problem: can control the rhythm of the data sender.
[0011] (4) Data security issues: Try to transmit data in memory or encrypted form to prevent illegal operations such as theft and decryption.
[0012] (5) Data reliability issue: Before sending data, the data sender must confirm whether the data receiver is ready to receive the data. Only after the data receiver is ready can the data be sent.
[0013] Currently, there are mainly the following methods for exchanging data between applications:
[0014] (1) Sharing: Create a file on the hard disk, one application writes data to the file (the file does not need to be closed, but the buffer must be refreshed), and another application opens the file in a shared manner and reads the contents. This is the simplest way to exchange data. For network users, as long as both terminals are installed with Win311For Workgroup or Windows 95 (or NT), data exchange can also be easily achieved by setting up directory sharing and mapping it to a network drive. The main disadvantages of this sharing method are: only polling can be used to obtain the latest data (low efficiency), and the network mapped drive cannot be changed or cancelled (poor reliability), so this is a "low-level" communication method.
[0015] (2) DDE: Every Windows programmer is familiar with DDE (Dynamic Data Exchange). It is the earliest data exchange method based on Windows. There are three modes to choose from: cold connection, warm connection and hot connection. Generally, the client sends a connection request to the server, and the name and title of the server must be specified. After the connection is established, data can flow in both directions. A typical example is the screenshot software SnagIt, which provides a DDE interface that allows other applications to control it. DDE is fully backward compatible. From a 16-bit platform to a 32-bit platform, the source code hardly needs to be modified.
[0016] DDE also has network functions. Those who have used Win311 For Workgroup probably still remember that it comes with a very attractive small program "Chat", which allows two computers to talk in real time over the network, which was almost a pioneering work at the time. However, few people know that "Chat" uses a special DDE, namely NetDDE. Its basic working principle is still DDE, but it enables one computer to send messages to another terminal in the same network, unlike ordinary DDE which is limited to the same machine. Compared with other data exchange methods, DDE is not advanced enough, and Microsoft no longer actively supports DDE, so its prospects are not optimistic.
[0017] The main disadvantage of the DDE method is that the name and title of the server must be specified before a connection can be established, and the name and title of the server cannot be modified dynamically.
[0018] (3) WM_COPYDATA: The Windows message WM_COPYDATA is powerful, but few people know about it. Its exact definition is: a message sent when one application passes data to another application. As we all know, Windows relies heavily on the message mechanism, so that data can be sent together in a message. We only need to call SendMessage(), with the handle of the other party's window as the first parameter and the address of the pointer structure containing the actual data as the second parameter, and we can send the entire data block as a message to another application. The core of WM_COPYDATA's work is to first create a file mapping object, copy the sender's original data to the mapped file, and then open a "view" of this mapped file on the receiving side.
[0019] The disadvantages of the WM_COPYDATA method are that there must be a form to receive messages and data (lack of flexibility), and the data must be copied to a mapping file before use (waste of resources).
[0020] (4) NetBIOS: Since the 1980s, NetBIOS has been the standard interface for developing client / server programs. At that time, other solutions were almost all developed from UNIX systems. Of course, for today's users, NetBIOS is no longer the only choice. They can choose the best from a variety of solutions. On Windows 95 and NT platforms, NetBIOS functions can be called through the API function Netbios().
[0021] NetBIOS is compatible with the following low-level protocols: NetBEUI protocol (NBF), NWLink NetBIOS (NWNBlink), NetBIOS over TCP / IP (NetBT). The advantage of NetBIOS is its high speed, but its disadvantage is its poor reliability.
[0022] (5) Standard Sockets and WinSock: Sockets were first proposed on the UNIX system. They were initially used for local communication, but were soon applied to the Client / Server system. Its core is very simple: you can regard a Socket as a bidirectional node, through which an application can first establish a connection with another program (established on a mutually recognized end to distinguish between several communication threads running simultaneously), and then they can exchange data with each other.
[0023] Microsoft created WinSock based on it, which is specially used for Windows interface and is fully compatible with Socket. In recent years, networks based on TCP / IP protocol have become popular, and Socket has also been more widely used.
[0024] Today, Sockets has been widely used on the Internet, mainly because of its good portability: Socket applications can communicate with each other on any platform (whether it is a PC or Macintosh, Windows platform or UNIX platform). The latest WinSock2.0 is not only based on TCP / IP protocol, but also on several other transmission protocols (such as IPX).
[0025] The disadvantage of Socket is that it works at the low level of communication, which is more complicated to implement and difficult to achieve synchronous control. In addition, like DDE, the name and title of the server must be specified before the connection can be established, and the name and title of the server cannot be modified dynamically.
[0026] (6) Mailslot and Pipe: Mailslot and Pipe have many similarities, namely, they are both high-level, memory-based communication systems. Mailslot is created by the server. Then, the client can open the Mailslot like opening a file, and then use the API function WriteFile() to write data to the message queue.
[0027] Similarly, Pipe is also created by the Server, and then the Client can read and write data through the general file API. There are two types of Pipe, namely named Pipe and anonymous Pipe. Anonymous Pipe is identified by handle rather than name, which limits it to communication on the same machine and cannot be used on the network. Named Pipe provides identification by name, so it can be opened anywhere else on the network. It should be noted that named Pipe can only be created on WinNT instead of Win95 (that is, the Server), while the Client can be any platform.
[0028] Pipe can communicate in one direction or two directions, while Mailslot can only communicate in one direction. The client can send messages to the mailslot, but cannot receive messages; if you want to receive messages, you can only create a new mailslot. But mailslot has a great advantage: it supports data broadcasting. In other words, if the client sends a message, all objects with the same name in the entire network can receive it. This is because the scope of the mailslot name is only on this machine, so mailslots with the same name can be created on different machines. When the client sends a message, the mailslot on each machine gets a copy of the message and responds accordingly on the local machine. The biggest flaw of Mailslot is that it is unreliable, because its data is transmitted in datagram format, and network errors or excessive loads will cause data loss. It cannot even solve the problem of data synchronization.
[0029] The above methods are the main technologies currently used for data exchange and communication between programs. Each technology has its own advantages and disadvantages, but no one method can solve the data exchange problem and perfectly solve the problem of data synchronization and reliability between programs. Summary of the invention
[0030] The purpose of the present invention is to overcome the deficiencies of the prior art and provide a method for data exchange and synchronization between programs that can realize data interaction with only a simple function, solve the problem of data synchronization between programs, and realize the effect of synchronous display of interfaces between programs.
[0031] The object of the present invention is achieved through the following technical solution: a method for data exchange and synchronization between programs, comprising the following steps:
[0032] S1. The data display program copies the fixed configuration information file of the data acquisition program to the location where the data acquisition program is located, and starts the data acquisition program;
[0033] S2, the data acquisition program reads the measurement data from the instrument and encodes the collected measurement data;
[0034] S3, calling the data exchange function: ShowDataToSG() or ShowDataToVW(), the data exchange function ShowDataToSG() or ShowDataToVW() reads the title of the data display program from the configuration information file of the data display program and searches for the window handle of the data display program;
[0035] S4. Create or open a memory-mapped file and name the memory-mapped file, and create or open a write operation mutex and a read operation mutex of the memory-mapped file;
[0036] S5. Check whether the memory-mapped file can perform data writing operation through the write operation mutex lock. If there is no data writing operation permission, the data acquisition program will wait for the data display program to release the write operation mutex lock signal. If the data display program still does not receive the write operation mutex lock signal released by the data display program within the preset time, the data acquisition program will be forced to enter the write data operation.
[0037] S6. After entering the data write operation, first lock the write operation mutex to protect the memory of the memory-mapped file unit, and write the collected data to the memory-mapped file through the data exchange function ShowDataToSG() or ShowDataToVW(), and store the measured data in the memory-mapped file;
[0038] S7, the data acquisition program uses the data exchange function ShowDataToSG() or ShowDataToVW() to send a custom message to the data display program, release the read-read operation mutex signal, and notify the data display program to read the data from the memory mapping file; after receiving the custom message, the data display program takes out the collected measurement data from the memory mapping file;
[0039] S8. The data display program releases the write operation mutex lock, cancels the blocking of the data acquisition program, and allows the data acquisition program to continue executing. The data acquisition program locks the read operation mutex lock and performs the interaction of the next data.
[0040] Furthermore, the data encoding in step S2 includes the following formats:
[0041] The first encoding format: header + data name + "$" + data value;
[0042] The second encoding format: header + data name + "$" + data value + "$" + data display color;
[0043] The third encoding format: header + data name + "$" + data value + "$" + data upper limit + "$" + data lower limit + "$" + display color;
[0044] The fourth encoding format: header + image name + "$" + panel name + "$" + curve name + "$" + curve type + "$" + X-axis data + "$" + Y-axis data + "$" + display color.
[0045] The beneficial effects of the present invention are as follows: the method of the present invention first simplifies the workload of data exchange, and only a simple function is needed to realize data interaction; secondly, the problem of data synchronization between programs is solved, and the effect of synchronous display of interfaces between programs is realized; and data is transmitted by custom messages and memory mapping files, so that data security is greatly protected. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 The figure is a flow chart of the method for data exchange and synchronization between programs of the present invention. DETAILED DESCRIPTION
[0047] The inter-program data exchange and synchronization method of the present invention first copies the program configuration file to the path where the data acquisition program (SPx) is located -> the data display program (CPx) starts the data acquisition program (SPx) -> calls the data exchange function in the data acquisition program (SPx) -> the data acquisition program (SPx) executes the data exchange function -> the data acquisition program (SPx) searches for the window handle of the data display program (CPx) through the configuration file -> obtains the write operation permission and writes the data -> the data acquisition program (SPx) sends a custom message to notify the data receiving program (CPx) to read the data -> the data display program (CPx) receives the custom message and reads the data -> notifies that the read operation is completed and releases the write operation permission. The specific flow chart is as follows Figure 1 As shown, the technical solution of the present invention is further described below in conjunction with the accompanying drawings.
[0048] like Figure 1 As shown, the inter-program data exchange and synchronization method of the present invention comprises the following steps:
[0049] S1. The data display program (CPx) copies the fixed configuration information file of the data acquisition program (SPx) to the location where the data acquisition program is located, and starts the data acquisition program;
[0050] S2. The data acquisition program reads the measurement data from the instrument and encodes the collected measurement data; the data encoding includes the following formats:
[0051] The first encoding format: header (ShowDataToVW:) + data name + "$" + data value;
[0052] The second encoding format: header (ShowDataToVW:) + data name + "$" + data value + "$" + data display color;
[0053] The third encoding format: header (ShowDataToVW:) + data name + "$" + data value + "$" + data upper limit + "$" + data lower limit + "$" + display color;
[0054] The fourth encoding format: header (ShowDataToVW:) + image name + "$" + panel name + "$" + curve name + "$" + curve type + "$" + X-axis data + "$" + Y-axis data + "$" + display color.
[0055] S3. Calling the data exchange function: ShowDataToSG() or ShowDataToVW(), the data exchange function ShowDataToSG() or ShowDataToVW() reads the title of the data display program from the configuration information file of the data display program and searches for the window handle of the data display program, so as to facilitate the quick finding of the data display program when sending a message to the data display program;
[0056] S4. Create or open a memory-mapped file and name the memory-mapped file, and create or open a write operation mutex and a read operation mutex of the memory-mapped file;
[0057] S5. Check whether the memory-mapped file can perform data writing operation through the write operation mutex lock. If there is no data writing operation permission, the data acquisition program will wait for the data display program to release the write operation mutex lock signal. If the data display program still does not receive the write operation mutex lock signal released by the data display program within the preset time, the data acquisition program will be forced to enter the write data operation.
[0058] S6. After entering the data write operation, first lock the write operation mutex to protect the memory of the memory-mapped file unit, and write the collected data to the memory-mapped file through the data exchange function ShowDataToSG() or ShowDataToVW(), and store the measured data in the memory-mapped file;
[0059] S7, the data acquisition program uses the data exchange function ShowDataToSG() or ShowDataToVW() to send a custom message to the data display program, release the read-read operation mutex signal, and notify the data display program to read the data from the memory mapping file; after receiving the custom message, the data display program takes out the collected measurement data from the memory mapping file;
[0060] S8. The data display program releases the write operation mutex lock, cancels the blocking of the data acquisition program, and allows the data acquisition program to continue executing. The data acquisition program locks the read operation mutex lock and performs the interaction of the next data.
[0061] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the protection scope of the present invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific variations and combinations that do not deviate from the essence of the present invention based on the technical revelations disclosed by the present invention, and these variations and combinations are still within the protection scope of the present invention.
Claims
1. A method for data exchange and synchronization between programs, characterized in that: The steps include: S1. The data display program copies the fixed configuration information file of the data acquisition program to the location where the data acquisition program is located, and starts the data acquisition program; S2, the data acquisition program reads the measurement data from the instrument and encodes the collected measurement data; S3, calling the data exchange function: ShowDataToSG() or ShowDataToVW(), the data exchange function ShowDataToSG() or ShowDataToVW() reads the title of the data display program from the configuration information file of the data display program and searches for the window handle of the data display program; S4. Create or open a memory-mapped file and name the memory-mapped file, and create or open a write operation mutex and a read operation mutex of the memory-mapped file; S5. Check whether the memory-mapped file can perform data writing operation through the write operation mutex lock. If there is no data writing operation permission, the data acquisition program will wait for the data display program to release the write operation mutex lock signal. If the write operation mutex lock signal released by the data display program is not received within the preset time, the data acquisition program is forced to enter the data write operation; S6. After entering the data write operation, first lock the write operation mutex to protect the memory of the memory-mapped file unit, and write the collected data to the memory-mapped file through the data exchange function ShowDataToSG() or ShowDataToVW(), and store the measured data in the memory-mapped file; S7, the data acquisition program uses the data exchange function ShowDataToSG() or ShowDataToVW() to send a custom message to the data display program, release the read operation mutex signal, and notify the data display program to read the data from the memory mapping file; after receiving the custom message, the data display program takes out the collected measurement data from the memory mapping file; S8. The data display program releases the write operation mutex lock, cancels the blocking of the data acquisition program, and allows the data acquisition program to continue executing. The data acquisition program locks the read operation mutex lock and performs the interaction of the next data.
2. A method for data exchange and synchronization between programs according to claim 1, characterized in that: The data encoding in step S2 includes the following formats: The first encoding format: header + data name + "$" + data value; The second encoding format: header + data name + "$" + data value + "$" + data display color; The third encoding format: header + data name + "$" + data value + "$" + data upper limit + "$" + data lower limit + "$" + display color; The fourth encoding format: header + image name + "$" + panel name + "$" + curve name + "$" + curve type + "$" + X-axis data + "$" + Y-axis data + "$" + display color.
Citation Information
Patent Citations
Multi-process interaction method and system
CN103970593A
Multi-instruction response type task collaborative management method oriented to universal service robot
CN113268352A
Method for accurately controlling external program
CN1516010A
