Application of DDE and COM technology in configura

2022-08-23
  • Detail

Application scheme of DDE and COM technology in configuration software development

with the vigorous development of various embedded systems and fieldbus, configuration software has increasingly become the soul of industrial automation systems. It has unique effects in real-time data storage, retrieval, graphic display and man-machine dialogue. But the script language of configuration software is very simple, and it is relatively weak in data processing, algorithm implementation and so on. This limits the application of configuration software in industrial automation to a certain extent

As an excellent numerical calculation software, matlab provides a toolbox used in signal processing, industrial control, applied mathematics and other fields, but it has very high requirements for the operating environment, and takes up a huge amount of system resources, and its ability to generate a practical human-computer interface is not strong

in order to develop configuration software with friendly man-machine interface, realize various control algorithms and complete real-time digital signal processing, matlab can be used for numerical calculation, and the processed data can be transmitted to the configuration software for man-machine interface development, so as to give full play to their respective advantages. In this way, the data exchange and processing between development software has become the key to the problem

according to the programming interface and data communication protocol provided by MATLAB and the widely used configuration software in touch, this paper proposes a method of using DDE and COM technology to develop configuration software

1. Basic idea and system architecture

dynamic data exchange (DDE) is a communication protocol developed by Microsoft. This protocol allows applications in the windows environment to send/receive data and instructions from each other. It implements the client server relationship between two applications running at the same time. The server application provides data and receives requests from other applications interested in the data. The requesting application is called a client. InTouch can use Microsoft's DDE to communicate with other windows programs, and can also act as a client or server program

matlab provides a variety of mixed programming methods, but most of these methods can not be separated from the running environment of MATLAB, and it is not convenient for other applications to call. In order to get rid of the Matlab running environment, and design the function module based on it, so as to facilitate the call of other applications, MathWorks company recommends using COM builder to develop com in the MATLAB environment. COM is the abbreviation of component object module. It is a general object interface. Any language can call it as long as it conforms to this interface standard

in this way, you can use matlab to develop COM components, develop DDE service program under VC, and make it communicate with InTouch. This DDE service program calls com developed by MATLAB for numerical processing and algorithm implementation. In the development of configuration software for industrial automation, VC can be used to collect data, send commands and control complex processes; Using COM developed under Matlab to complete the complex algorithm implementation and digital signal processing programming; Realize the man-machine dialogue interface under InTouch and receive the user's commands. The specific system architecture is shown in Figure 1

2. Application implementation

the core of windows DDE function application is DDE transaction management library (ddeml), which is responsible for managing DDE sessions and communications between applications under Windows operating system, and also provides users with a series of application program interface API functions

dde realizes the communication between programs through three identification conventions:

application: the names of both parties conducting DDE dialogue

topic: the data field to be discussed

item: the specific data object being discussed

in DDE service program, first use ddeinitialize to initialize, then call ddecreatestringhandle to establish the handle of application name, topic, item and other identification, and then register the name of DDE service program in the operating system through ddenameservice. Based on these handles, the client program can use the DDE services it provides. The program implementation in vc++ is as follows:

include...

DWORD idinstc = 0, IData;//Idate is the data corresponding to the project

hsz hszsvr, hsztopic, hszirem

DdeInitialize(&idInst,(PFNCALLBACK)DdeCallback,CBF_

FAIL_ EXECUTES┃CBF_ SKIP_ Allnotify although the control method is relatively simple 1ions, 0l)

//create a handle for the identification of application name, topic and item

hszsvr = ddecreatestringhandle (idinst, "ddeapp", 0)

hszTopic=DdeCreateStringHandle(idInst,“DDEAppTopic”,0);

hszItem=DdeCreateStringHandle(idInst,“DDEApphem”,0);

//register the DDE service in the operating system

ddenameservice (idinst, hszsvr, 0l, dns_register)

...

the core of DDE service program is a callback function, which processes all DDE messages and corresponding data requests. The code of the DDE service program callback function is as follows:

hddata callback ddecallback (word ustype, word usfmt, hconv hconv, HSZ hsz1, HSZ hsz2, hdde data hdata, DWORD 1datal, DWORD 1data2) {char sz[5]

if (ustype = = xtyp_connect) {//get the connection request return ((hddata) true)

//verify the subject, item handle and data format

if (hszl= = hsztopic & & hsz2 = =hszitem & & usfmt = = cf_text) {

if (ustype = = xtyp_request ‖ ustype===xtyp_advreq) {/get data request

.

_ itoa(iData,sz,10);// Convert the data into text format

r take it out and demould after the foam solidifies for a certain time return ddecreatedatahandle (idinst, (lpbyte) SZ,

strlen (S2) x 1, 0l, hszitem, CP_ TEXT,0);

}

if (ustype = = xtyp_poke) {//get the data sent by the client

ddegetdata (hdata, (lpbyte) SZ, strlen (SZ) plus 1, 0l)

iData=atoi(sz); // Save data

ddepostadvise (idinst, hsztopic, hszitem)

return((HDDEDATA)DDE_ FACK);

return 0;

,

use DDE postadvise to trigger xtyp whenever data needs to be sent to DDE clients_ Advreq, so as to achieve the purpose of sending data to the client program

define I/O type variables in InTouch's tagName dictionary to call the data sent by the DDE service program. When declaring the access name of I/O type, just determine the application name, subject name and item name of DDE service program

the numerical calculation and real-time digital signal processing part of the new material industry sales revenue of the province in 2013 was realized in MATLAB and provided in the form of COM components. The key of this part is the writing of m file under Matlab, the formation of COM components and the call to com in DDE service program

com component is actually a C-class, but interfaces are pure virtual classes, and components are derived from interfaces. Start combuilder through comtool under Matlab, and set the name of the class and some other options according to the prompt. Adding methods to this class is achieved by adding M files to the project. This m file is not a script file but a function file. Adding properties is defined in the m file through global. As for events, you need to use the syntax%event. Examples are as follows:

%mymethod.m file source code%myevent.m file source code

function mymethod function myevent

global mvalue;%# Event

...

adding the above two files to this project adds a method mymethod, attribute mvalue and event myevent. Generate a D11 file through compilation. This DLL is the release form of com

calling this com in VC is the same as calling other com. The difference is that you need to include the files provided by MATLAB in the VC project. The specific operation is to add \ externclude \ and \ externn \ CPP in include files, and \ extern \ Win32 and \ extern \ Win32 \ mi crosoft in library files

combuilder also provides a packaging tool for COM components, which generates a self extracting file and realizes the necessary DLL installation and com registration through it

call COM components in DDE service program for numerical calculation and signal processing, and provide DDE services to InTouch. In InTouch, enrich the man-machine dialogue interface by calling the data sent by DDE, and receive the operator's commands to complete the functions of the system

3. Consideration of details in actual development

com component development under Matlab is a function only available in MATLAB6.5, and this module is not available in early versions. In addition, not all matlab toolkits support com compilation. At this time, you can consider using other functions instead, or you can use DDE to call matlab functions, but this cannot be separated from the running environment of matlsb

using DDE and COM technology in configuration software can give full play to the function of MATLAB in numerical calculation and the unique effect of InTouch in the development of man-machine interface, which is suitable for the design of functional modules and the development of large-scale configuration software. (end)

Copyright © 2011 JIN SHI