A typical technology for implementing inter-component communication in configuration software
2026-04-06 07:37:14··#1
1. Introduction Configuration software, as a user-customizable software platform tool, has been widely used in various industries and fields. It has matured alongside the development of DCS and computer control technology, with componentization and distributed architecture becoming its fundamental characteristics. Excellent configuration software typically designs its main components—real-time database, HMI, I/O server, and data server—as independently running components. These components can run simultaneously on a single computer or distributed across different computers, communicating with each other via networks. This architecture allows users to flexibly configure their systems and rationally allocate the computational load across servers. However, componentization also brings complexity to software design. In particular, achieving efficient, real-time, and reliable communication between components becomes a critical issue. 2. Inter-Component Communication Technology Inter-component communication can be achieved in two ways: local and remote. In the design, the local method can be considered as the basis for the remote method. In other words, achieving local communication also achieves remote communication. This is because data exchanged between components can be transmitted to the destination machine remotely, and then communicated with the remote component locally. Below, we will discuss how to implement local and remote communication between components. 3 Local Communication When implementing local communication between components, the essential problem to be solved at the underlying level is inter-process communication. Inter-process communication is a technology closely related to the OS. The method introduced in this article is based on Microsoft's Windows operating system. Various versions of the Windows operating system provide rich inter-process communication methods. From pipes, mail slots, and DDE technology provided in early versions, to the later-released COM technology, and the new methods provided in the latest ".NET", etc. The technology introduced in this article belongs to the "traditional" technology. Its foundation is the message passing function of Windows, while also being assisted by memory file mapping and semaphore technology. The author believes that this method has the following advantages: (1) Simple implementation Because the technologies involved are not very complex, it is relatively easy to implement. (2) High real-time performance This method uses the OS's underlying technology, with fewer intermediate links, high running efficiency, and can achieve fast data communication. (3) Good portability Because it uses the OS's underlying technology, this method is less affected by OS version upgrades and is also easy to port to non-Windows operating systems. Some inter-process communication technologies, such as DDE, are no longer supported in the new version of the Windows operating system. Other technologies have also changed significantly in terms of interface form and implementation method due to OS upgrades, affecting applications. (4) Good functional controllability. Controllability here refers to whether developers can effectively control the use of a technology. For example, if a technology is over-encapsulated, although the application is simple, it will be difficult to achieve flexible control. (5) Easy reliability control. This is related to the controllability mentioned above. The lower the operating system technology, the stronger the reliability. The more encapsulated a technology is, the less controllable its reliability becomes. (6) Strong adaptability to system environment. This issue can be illustrated with a simple example: Many users who have used software products developed based on COM/DCOM technology (such as OPC software) have experienced the confusion of having to face the complex configuration of COM/DCOM due to different system environments. Local communication still belongs to the C/S structure in terms of computing mode. The main problem is how to realize fast and concurrent data exchange instances between multiple clients and servers. The following is an explanation with examples. 3.1 Multiple client-server communication example Assume that the client and server are client and server programs using this technology, and they are both independent processes based on windows. Each time data is exchanged, the client sends a request message to the server, and the server sends a response message back to the client after receiving the request message, and so on. Because multiple clients may be exchanging data with the same server at the same time, the above interaction process must be asynchronous to ensure reliability and concurrency. For ease of implementation, a middleware icom dedicated to process communication needs to be abstracted for all clients to call at the same time. (1) Provide three basic interfaces a) open() In this interface, icom implements the following functions: initialize memory-mapped files for data exchange, create semaphore objects for uplink (client to server) and downlink (server to client) event notifications, create semaphore objects to prevent shared conflicts, start the service thread, and at the same time, the client sends a message to the server for authentication and registration. b) close() The client calls this interface when closing the process or disconnecting from the server. This interface icom needs to release the object resources created when the open() method is executed, and at the same time the client sends a message to the server to perform the deregistration operation. c) sendmessage() The client calls this interface when sending a message to the server. (2) Message transmission process When the client calls the icom sendmessage() method to send a message to the server, it needs to use semaphores to control the timing. After the message is sent to the server using the SDK function sendmessagetimeout(), wait for the server's reply through the semaphore. Once the reply signal is received, it is known that the server has put the reply message into the memory-mapped file, and the message can be obtained and passed to the client as a parameter. In order to receive the message sent by the other party, the main window class of the server program needs to add a mapping function for the message "wm_copydata". When the client calls the icom sendmessage() method to send a message to the server, the server will immediately receive the wm_copydata message and obtain the message information through the message parameter. However, after receiving a request message, the server does not immediately process or reply. It first responds to the `wm_copydata` message using the `replymessage()` method to avoid unnecessary waiting by the other process. Then, it places the message in an internal buffer queue and sends a notification message to its main window using `postmessage()`. The request message in the buffer queue is then processed in another message mapping function. This server processing mechanism is crucial for ensuring the interaction process is asynchronous. This asynchronous mechanism is very important because it can reasonably allocate CPU resources and avoid deadlocks when multiple client programs exchange large amounts of data with the server frequently. The server parses the content of the request message, places the reply message in the memory-mapped file allocated in ICOM, and notifies ICOM to receive the reply message via a semaphore. A complete information exchange process is then complete. The message format consists of a header and a data trailer. The header has a fixed structure and includes information such as the message number, data length, and client ID. The data trailer contains any content of variable length. 4. Remote Communication Remote communication is entirely based on local communication. However, two components dedicated to network communication services need to be added: netclient and netserver. netclient and netserver are also two completely independent processes. Taking a TCP/IP network as an example, netclient and netserver are equivalent to a socket client and a socket server, respectively. netclient and netserver do not concern themselves with the content of the transmitted messages; they are only responsible for establishing network connections, transmitting messages, and data caching and recovery in case of network communication failures. Continuing with the example from the previous section, when the client program exchanges data remotely with the server, the client and netclient will run on the same computer, while the server and netserver will run on the same computer. In this case, ICOM will first send the client's request message to netclient via local communication, then netclient will send it to the remote netserver over the network, and finally netserver will transmit it to the server via local communication. The server's reply message is transmitted in the reverse process. In actual product development, netclient and netserver can be designed as network service components with a broader scope. Besides supporting TCP/IP networks, they can also support any communication method such as UDP/IP, serial communication, and GPRS. Regardless of the communication method used, it is completely transparent to both the client and the server, which is precisely the advantage of componentization in product implementation. 5 Conclusion Inter-component communication technology is one of the key technologies for designing configuration software and data communication software. How to ensure reliability, flexibility and wide adaptability while achieving fast, efficient, and multi-user concurrent processing is a question worth considering for designers. The technology introduced in this article has been used in many places in the configuration software products designed by the author, and has been proven to be mature and reliable through more than a thousand application cases. References [1] Ma Guohua. Monitoring configuration software and its application [M]. Beijing: Tsinghua University Press, 2001. [2] Brian Myers, Eric Hamer. Mastering Windows NT Programming, 1994.