The following information is for the EMANT300

Using EMANT300 with Matlab

This application note is written for experienced Matlab users. Our examples were created and tested with Matlab ver 7.2 (R2006a). The code is provided AS-IS and our support engineers are unable to answer any Matlab queries.

When the EMANT300 was developed, the .NET framework was already well established and in ver 2.0. As such our driver was developed as a native .NET assembly or dll Although Matlab has a dll interface it did not provide support for native .NET assemblies or dll.

However Matlab provided COM support. We provided for those with legacy code and wish to take advantage of the EMANT300, a COM wrapper in VB .NET. The source code of the wrapper is also provided. The wrapper source allows legacy users to maintain the wrapper code if necessary and at the same time allow us to focus on providing, maintaining and upgrading robust .NET code.

Note that the simulator does not work with the wrapper.

Please read and complete the EMANT300 installation guide before proceeding with the following.

Before you can use the EMANT300 with Matlab, you must carry out the following steps

  1. Install Microsoft .NET Framework Version 2.0
  2. Install EMANT300COM

Note that you may have already done step 1 and 2. Nonetheless, follow through the steps and if the step has been done, you would be informed by an appropriate dialog box. If so, just exit the corresponding program.

Install Microsoft .NET Framework Version 2.0

EMANT300COM requires .NET Framework v2.0 to work. The Microsoft .NET Framework version 2.0 (x86) redistributable package installs the .NET Framework runtime and associated files required to run applications developed to target the .NET Framework v2.0.

To install the update, browse to the Microsoft folder and run the dotnetfx.exe file and follow the instructions on the screen.

If during the installation, you see the following dialog, the Microsoft .NET Framework version 2.0 has already been installed. Click Cancel to exit.

Install EMANT300COM

Browse to the EMANT300COM folder and run Install.bat. You should see the message Types registered successfully. Press any key to close window and exit program.

Run Matlab

Two example M-files are provided to illustrate how to interface the EMANT300 to Matlab.

Light_Intensity.m

This program measures the Light Intensity using the Light Application Adaptor. Please refer to the Learn DAQ with Visual C# 2005 instruction guide for more information. The appendix of the instruction guide also contains the methods and properties of the EMANT300.

% ------------------------------------------------------ % Simple Analog In and Convert to Light Intensity % This file calls the ReadAnalog method and returns the % analog voltages AIN0 and AINCOM from the EMANT300. % ------------------------------------------------------ clc % Clears the command window hEmant300 = actxserver('EMANT300COM.Wrapper'); hEmant300.Open; hname = hEmant300.HWId; hname % display Hardware Id volt = hEmant300.ReadAnalog('AIN_AIN0','AIN_COM'); lux = volt * 1333; lux % display Lux Value hEmant300.Close;

The first step in accessing EMANT300 from MATLAB is to run the EMANT300COM in an Automation server process using the actxserver function and the EMANT300COM program ID, EMANT300COM.Wrapper.

hEmant300 = actxserver('EMANT300COM.Wrapper');

The COM object that is returned hEMANT300 provides access to a number of interfaces supported by EMANT300.

hEmant300.Open;

Open is a method that instructs the program to connect to the DAQ module that is physically connected to USB port.

volt = hEmant300.ReadAnalog('AIN_AIN0','AIN_COM');

The analog voltage across AIN0 and GND (COM) is read. The 10K resistor reading the Photodiode current is connected to AIN0 and GND (COM).

lux = volt * 1333;

The voltage is converted to Lux and then displayed on the console output. See page 7 of Learn DAQ with Visual C# 2005 instruction guide for theory behind the calculations.

hEmant300.Close;

Finally the DAQ connection is closed. To ensure that your programs end correctly, always call the Close method before you exit your programs.

Waveform.m

The EMANT300 is capable of reading in a 16 bit resolution waveform at up to 2500 samples/sec. You can only read a single input and in burst mode (no continuous acquisition). The following program allows you to measure the output waveform of the PWM signal. Please connect the circuit as shown on the light application adaptor.

  1. Connect Refout to AIN3

  2. Connect PWM to AIN2

% ---------------------------------------------------------------- % Read Waveform - Note that the output is 16 bit % This file calls the ReadAnalogWaveform method and returns the % array analog voltages AIN3 and AIN2 from the EMANT300. % ---------------------------------------------------------------- clc % Clears the command window ScanRate = 2000; % Set scan rate hEmant300 = actxserver('EMANT300COM.Wrapper'); hEmant300.Open; hname = hEmant300.HWId; hname % display Hardware Id err = hEmant300.ConfigAnalog(2.5,'POLARITY_BIPOLAR',ScanRate); wavearray = hEmant300.ReadAnalogWaveform('AIN_AIN3','AIN_AIN2',400); % Add 2.5V offset % See App Note for Analog Input > 2.5V for n=1:400 wavearray(n) = wavearray(n) + 2.5; end plot(wavearray); hEmant300.Close;