Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Jul 1, 2008


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

How to connect IDL to DIAdem

0 ratings | 0.00 out of 5
Print

Overview

DIAdem offers a wide variety of ways to easily analyze and present large data sets; however there are several reasons why you may want to use Research Systems Inc.TM IDL software to perform analysis on DIAdem data. One reason is to take advantage of the powerful IDL analysis and image processing functions. Another reason is to reuse legacy of algorithms developed in IDL in DIAdem.

Connecting IDL to DIAdem

This document describes two ways to connect IDL to DIAdem. There is a DIAdem component that can be registered and extends the DIAdem scripting capabilities to communicate to IDL, or directly via OLE communication using the IDLDrawWidget ActiveX Control. The OLE interface basically exposes IDL’s ActiveX functions and allows the user to perform a wide range of IDL operations on the DIAdem environment.

DIAdem OLE component interface to IDL


This approach is recommended to users who want to directly exchange data between IDL and DIAdem and optionally execute command line instructions in applications that do not require the IDL visual interface.

The IDL Connectivity interface is a free addition to DIAdem which enables users to use DIAdem’s scripting interface and pass data between DIAdem and IDL as well as execute command line instructions.
The IDL DIAdem Connectivity interface in DIAdem makes it easy to quickly interface with IDL scripts which have its inputs and outputs exposed through variables. The advantage to using this method of interfacing with IDL is that no additional IDL programming is needed if the variables that you are interested in accessing are supported by the interface. The limitation resides on the data types that aren’t supported by the interface. The rest of this application note will focus on how to use the IDL interface in DIAdem.

Interface installation and registration
The IDL interface is an OCX control. To be able to use this functionality you must first register the component called ScriptLibrary.ocx. Please follow the subsequent instructions:
1. Detach ScriptLibrary.OCX in to the DIAdem directory and register it through regsrv32, either by pressing “Windows R” or “Start\Run” to bring up the run menu.
2. At the Run prompt type:
For Windows 2000 & NT
c:\winnt\system32\regsvr32 "c:\program files\National Instruments\diadem 9.1\ScriptLibrary.ocx"
For Windows Xp
c:\Windows\system32\regsvr32 "c:\program files\National Instruments\diadem 9.1\ScriptLibrary.ocx"

This will register the ScriptLibrary.ocx on your computer
Congratulations, you registered your IDL interface successfully!

Example code
The attached example “IDLTest1.VBS” contains all the code that opens a connection between IDL and DIAdem, allowing for transfer of data and running of IDLscripts

To create an instance of IDL in DIAdem, use the following syntax.

Dim oIDLM 'Create IDL Object variable
Set oIDLM = CreateObject("DIAdem.ScriptLibrary.IDL")

The object variable “oIDLM” now can be used in the DIAdem script to access the complete ActiveX interface of IDL.

To push a DIAdem data channel to IDL use the following syntax:
Call oIDL.PutChannel("Sine_Wave")
Where “Sine_Wave” is an existing channel in DIAdem’s “Data portal”.

To pull a IDL array back into the DIAdem data area, use the following syntax:
Call oIDL.GetChannel("FFTRes")
Where “FFTRes” is an array created in IDL

To Run an IDL script, use the following syntax
Call oIDL.Execute("FFTTest1")

See Also:
Incomplete document created on 4/18/2005 5:09:28 PM

Using the IDLDrawWidget ActiveX Control


This approach is recommended to users willing to directly visualize IDL graphs in the DIAdem environment; more specifically within DIAdem's custom dialog boxes.

IDL for Windows distributions include an ActiveX control that makes IDL functionality available to other applications. Including the IDLDrawWidget control in your Windows application allow you to create user interfaces using the programming language like VBS within DIAdem, while using IDL’s data analysis and display functionality.
Note:
The IDLDrawWidget ActiveX control provides a COM interface to IDL, but requires an IDL installation to function. This means that in order for an application to use the IDLDrawWidget control, a licensed copy of IDL must be installed on the same computer.

Creating an Interface and Handling Events
The goal of this first example is very simple: to create a user interface in a SUD dialog and have IDL respond to events and display an image. The following figure shows what the finished project looks like when it runs. The SUD source code used to create the example is shown in the following figure:


Figure 1: A simple example showing the IDLDrawWidget


As the figure shows, our first example program consists of two buttons (“Plot Data” and “Exit”), a graphics area, and a text box. All of these elements reside on top of what is called a SUD dialog. Clicking the “Plot Data” button causes IDL to produce the surface plot shown. Clicking “Exit” causes IDL and the SUD dialog to close.

Drawing the interface
Begin building the first example by starting the DIAdem dialog editor and creating a new SUD dialog.
1. Add the IDL ActiveX component to the project. The SUD editor displays a list of all available components when you select the Components from the controls menu.

Figure 2 : Components from the controls menu

2. Select the “IDLDrawX3 ActiveX Control module” check box and close the Components window.

Figure 3: IDLDrawWidget Control

3. Select the “IDLDrawX3 ActiveX Control module” check box and close the Components window.
4. Begin drawing the interface. (make sure the name of the new object is the default IDLDRAWX31)
5. Create a new button and call “Plot Data”
6. Specify the IDL Path and Graphics Level. Having added IDLDrawWidget to the dialog, we now have access to IDLDrawWidget’s properties and methods. Select the ActiveX control tab at the properties field for IdlPath. Specify the directory path of the IDL ActiveX control (the default installation path is c:\ RSI\IDL61\bin\bin.x86).
7. Click at any empty field of your dialog to select the dialog object and select the EventInitialize event.
8. Paste the following code in your EventInitialize subroutine:
'Initialize an IDL process and check for a valid IDL license :
Result = IDLDraw31.X.InitIDL (0)
If Result < 1 Then
MsgBox "InitIDL failed."
Exit Sub
End If

'Create the draw widget graphics window for ActiveX Control:
Result = IDLDraw31.X.CreateDrawWidget
If Result < 0 Then
MsgBox "CreateDrawWidget failed."
Exit Sub
End If
9. Return to the dialog view
10. Double-click the Plot Data button (this should bring you to the EventClick subroutine)
11. Paste the following code in your EventClick subroutine:
Call IDLDraw31.X.ExecuteStr ("Z = SHIFT(DIST(40), 20, 20)")
Call IDLDraw31.X.ExecuteStr ("Z = EXP(-(Z/10)^2)")
Call IDLDraw31.X.ExecuteStr ("SURFACE, Z")
Call IDLDraw31.X.ExecuteStr ("PRINT, SIZE(Z)")
12. Click at any empty field of your dialog to select the dialog object and select the EventTerminate event.
'Shut down the IDL process and free any resources that were being used
IDLDraw31.X.DoExit
13. Save your work and select the button “Test in DIAdem”

Another example
As a downloadable file here is another example that demonstrate the usage of this interface

[+] Enlarge Image
Figure 6-1: Another example showing the IDLDrawWidget and images returned by IDL

See Also:
Using the IDLDrawWidget ActiveX Control


0 ratings | 0.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).