Data communication between iFix and Matlab based on DDE
2026-04-06 06:39:49··#1
1. Introduction * GE's iFIX industrial configuration software is stable and efficient, and has been widely used in industrial automation for many years. Like other industrial configuration software, as a human-machine interface software, iFIX has unique advantages, but its mathematical and computational functions are somewhat lacking. MATLAB, a mathematical software produced by MathWorks, is an engineering computational language based on C language kernel and matrix operations, possessing powerful numerical computation capabilities and rich control algorithms. This paper uses VC++ to implement bidirectional data communication between iFIX and MATLAB, introducing MATLAB's computational functions and algorithms into iFIX DDE. DDE (Dynamic Data Exchange) is a Windows inter-process communication mechanism based on the Windows message mechanism. Two applications communicate by exchanging messages; these two programs are called the server and client, respectively. The DDE server maintains data that other Windows programs may use, while the DDE client is the program that obtains this data from the server. The same Windows application can be both a client of one program and a server of another. A server can send data to multiple clients, and a client can obtain data from multiple servers; all of this is defined through DDE dialogue. DDE communication requires three parameters: service name, topic name, and item name. The service name is generally the same as the application acting as the server. A service can provide multiple topics, and a topic can provide multiple items. Finally, the item name determines the data to be exchanged. 2. Basic Idea of Implementing iFIX and MATLAB DDE Communication in VC++ iFIX software implements both a DDE server and a DDE client, supporting clipboard data in text format. MATLAB also implements both a DDE server and a DDE client. When acting as a server, it supports three clipboard formats: text, metafilepict, and xltable. When acting as a client, it supports text format. This paper implements a DDE server using a VC++ program, with both iFIX software and MATLAB acting as VC++ clients. The relationship between the three is shown in Figure 1: [align=center] Figure 1 Basic Structure of Bidirectional Data Transfer[/align] 3. Design of DDE Server Program Based on Visual C++ 3.1 Basic Principles The core of the DDE protocol is the DDE message. Programs communicating communicate by exchanging messages. The main task of the DDE server program is to maintain data that may be used by other Windows programs, implement the message loop of the DDE server, and thus handle various requests from DDE clients. 3.2 Program Implementation The program flowchart of the DDE server implemented using Visual C++ is shown in Figure 2. [align=center] Figure 2 DDE Server Program Flowchart[/align] (1) During program initialization, ddeinitialize() is called to initialize the DDE management library, and the callback function ddecallback() is provided as a parameter. When the program receives a pending transaction in the form of a message, it calls the callback function. The callback function is usually written in the form of switch-case. Branches handle different transactions; then ddecreatestringhandle() is called to return the handle of the service name, topic name, and project name. The returned type is hsz. (2) Register the DDE service and call ddenameservice() with the service name handle as a parameter. (3) The prototype of the callback function ddecallback() is: hddedata exchange ddecallback(uint type, uint fmt, hconv hconv, hsz hsz1, hsz hsz2, hddedata hdata, dword dwdata1, dword dwdata2); where type is the transaction type, fmt is the clipboard format of the exchanged data, hconv is the handle of the current dialog, hsz1, hsz2, hdata, dwdata1; the meaning of dwdata2 depends on the different transactions, hsz1 and hsz2 are generally the handles of the topic name and project name, and hdata is generally the handle of the exchanged data. (4) Generating the names of each field means giving the DDE server name, topic name and project name. Server name (servicename): ddetest g_hszappname=ddecreatestringhandle(g_idinst, "ddetest", null); Topic name (topic): test1 g_hsztopicname=ddecreatestringhandle(g_idinst, "test1", null); Item names (items): h1, h2, ut, up, ... g_hszinitem[0]=ddecreatestringhandle(g_idinst, "h1", null); g_hszinitem[1]=ddecreatestringhandle(g_idinst, "h2", null); g_hszoutitem[0]=ddecreatestringhandle(g_idinst, "ut", null); g_hszoutitem[1]=ddecreatestringhandle(g_idinst, "up", null); 4 Test Test Requirements: The system's acquired data and control outputs should be synchronously displayed in iFIX, DDE server, and MATLAB. Test Method: A process flow diagram is drawn using iFIX, displaying process parameters such as temperature, pressure, flow rate, and liquid level in real time. These parameters are transmitted to MATLAB via DDE for corresponding control calculations. The control signals are then transmitted back to iFIX via DDE, enabling control of the main equipment via a lower-level computer. A VC++ program acts as the server, synchronously displaying all data. An m-file is written in MATLAB to display the uploaded data and provide the control voltages up (pump control voltage) and ut (heating voltage). iFIX Configuration: First, iFIX is configured. Then, an ODF file named ceshi.odf is created in the iFIX draw window (see Figure 3). The graphical interface includes seven parameters (temperature, pressure, flow rate, liquid level, etc.) and two control voltages (up and ut), as well as time curves for h2 and up. The display time for these curves is 3 minutes, the maximum value of h2 is 200 mm water column, and the maximum value of up is 24V. The DDE node names (or I/O devices and I/O addresses) corresponding to these nine quantities need to be set. For example, the DDE node name corresponding to h2 is: =ddetest|test1!h2. [align=center] Figure 3: The graphical interface of iFix[/align] 5 Conclusion Furthermore, the MATLAB program can be converted into a VC++ program and compiled together with the DDE server program into an executable file to run in iFix. This can easily implement various algorithms and simulations, and has good engineering application prospects.