Additional Information
The example is not available in legacy versions of DIAdem. If you have an old DIAdem version and the example cannot be found, you will need to perform the steps below to implement communication between DIAdem and MATLAB:
Note: This method is
not recommended. It is documented for compatibility with old projects, but the shipping example approach should be used for newer projects.
Note: This method works only with 32-bit versions of DIAdem.
- Download the attached ScriptLibrary.OCX into the DIAdem installation directory and register it through regsrv32, either by pressing <Windows+r> or Start >> Run to bring up the run menu.
- At the Run prompt type, input the text below, correcting the filepath with your DIAdem version to register the ScriptLibrary.OCX on your computer. This will register the ScriptLibrary.OCX on your computer.
- For Windows 2000 & NT
c:\winnt\system32\regsvr32 "C:\Program Files\National Instruments\<your DIAdem version>\ScriptLibrary.ocx" - For Windows XP
c:\Windows\system32\regsvr32 "C:\Program Files\National Instruments\<your DIAdem version>\ScriptLibrary.ocx" - For Windows 7 and Windows 10
regsvr32 "C:\Program Files\National Instruments\<your DIAdem version>\ScriptLibrary.ocx"
- Copy the attached file, FFTTest1.M into the current directory folder as specified in the MATLAB software.
- To determine the current directory folder, start the MATLAB software, and from the File menu select, Set Path.
- Finally, detach and run the script MatLabTest1.VBS from within DIAdem.
- The script does the following
- Generates data in DIAdem.
- DIAdem transfers the data to the MATLAB® software.
- DIAdem invokes the MATLAB script server to run a script (FFTTest1.M) that performs an FFT on the data transferred from DIAdem.
- The MATLAB software then returns the results to DIAdem.
- DIAdem then pauses for 5 seconds showing the results returned from the MATLAB software.
- Then DIAdem calculates an FFT and displays both the MATLAB software results and DIAdem FFT results in VIEW.
DIAdem is calling the MATLAB software through it’s ActiveX interface, the
ScriptLibrary.ocx is managing data type conversions between the MATLAB software and DIAdem’s VBScript engine as well as the object instantiation.
The attached example
MatLabTest1.VBS contains all the code that opens a connection between the MATLAB environment and DIAdem, allowing for transfer of data and running of MATLAB scripts.
The following lines from the VBS script referred to in the previous paragraph create the interface:
Dim oMatLabM 'Create MatLAB Object variable
Set oMatLabM = CreateObject("DIAdem.ScriptLibrary.MATLAB")
The object variable “
oMatLabM” now can be used in the DIAdem script to access the complete ActiveX interface of the MATLAB environment.
To push a DIAdem data channel to the MATLAB software use the following syntax:
Call oMATLAB.PutChannel("Sine_Wave")
Where “
Sine_Wave” is an existing channel in DIAdem data.
To pull an array back from the MATLAB software into the DIAdem data area, use the following syntax:
Call oMATLAB.GetChannel("FFTRes")
Where “
FFTRes” is an array created in the MATLAB environment
To run a MATLAB script, use the following syntax:
Call oMATLAB.Execute("FFTTest1")
Note: The first time you run the script, it may be necessary to have the MATLAB software open. If you get an error message, "
Can not create Object, Out of Memory", just start the MATLAB software and run the script again. You should only have to do this the first time.
Note: This tool is
unsupported.
MATLAB is a registered trademark of The MathWorks, Inc. Other product and company names listed are trademarks and trade names of their respective companies.