MATLAB: Launching, requesting data, and closing WinWedge from Matlab

WinWedge DDE Server Settings

Remember to set WinWedge up in DDE Server Mode! Click here.

DDE Application Name: MATLAB
DDE Topic: Engine

Example #1: Launching WinWedge from MATLAB

Create or edit a .m file and enter the following code in the file:

cd ('c:\Program Files\WinWedge');
dos ('winwedge.exe myconfig.SW3 &');
cd ('d:\matlabbin');

This code launches the wedge with the specified config file and then returns to the original working directory in MATLAB. Save this .m file as invoke.m and launch from the MATLAB >> prompt.

Example #2: Requesting data from WinWedge

Create or edit a .m file and enter the following code in the file:

while chan == 0
 chan = ddeinit('winwedge', 'com1');
end

mydata = ddereq(chan, 'field(1)');
rc = ddeterm (chan);
disp(mydata);

This function establishes a DDE channel between the Wedge and MATLAB. Then it retrieves the content of field(1) in the wedge and perform the disp(mydata) operation that displays the data that was retrieved from the wedge in MATLAB’s command window. The disp(mydata) is just a small example of what can be done with the data once it is brought into the MATLAB. The disp(mydata) could also be swapped for a call to another .m file to run even more MATLAB code.

Example #3 Closing the WinWedge

Create a .m file called dismiss.m with the following code:

chan = ddeinit('winwedge', 'com1');
ddeexec(chan, '[APPEXIT]');

These two lines initiate a link with the wedge and then close the WinWedge application. This code assumes the WinWedge is already activated in the background.

Contact Us