Software Requirements: USBXpress
This article will describe the steps to call a DLL, created in LabVIEW, from a C++
application. The c++ application will call a function exported from this dll.
This function will display a dialog created in LabVIEW that will mimic the dialog created in
C++. This will demonstrate how to transfer that data retrieved from the F320 using
USBXpress to LabVIEW.
Test Panel Dialog Modifications:Open the TestPanel application found in the USBXpress examples directory:
In real time, the dialog will update based on what actions are done to the board. A
modification will need to be made to this application to call the dll created in LabVIEW.
Also, a button will be added to the dialog that will link to a handler function to open the
dialog created in LabVIEW. The updated dialog will look as follows:
LabVIEW Implementation Steps:We want to recreate this dialog in LabVIEW 7.1 to look like the following:
The controls on the front panel are updated by globals. These globals are defined on
another Virtual Instrument (VI) seen in the following illustration:
Each global corresponds to one of the controls on the MainTestPanel.vi. The block
diagram of the MainTestPanel.vi is connected as follows:
The final VI that needs to be created is the one that will be called from the C++
application to update the globals with data from the F320 board. The front panel of the
UpdateFrontPanel.vi is shown below. This VI also needs the controls linked to the
connector diagram. This is done by right clicking on the icon and selecting “Show Connector”.
There will be a connector box for each control on the front panel and the connection is made
by selecting a box and then clicking on a control. This is a necessary step that will allow
arguments to be added to the exported function declaration for this VI.
The block diagram will update the global variables:
Once the VI’s are created, the DLL can now be built. Select Tools>>Build Application
or Shared Library (DLL). The Target settings are shown below:
Under the Source Files tab, exported VI’s will need to be added. The two for this DLL
are MainTestPanel.vi and UpdateFrontPanelData.vi.
The UpdateFrontPanelData.vi will have parameters added to its function prototype.
Select the Define VI Prototype button. The following dialog will pop up and parameters
can be added to the function prototype.
Once everything has been defined, the Build button can be pressed and will generate aheader file, library file, and a DLL in the specified location. These files will be incorporated
Final Test Panel Application Code Updates:In the TestPanel C++ application, the project settings need to be modified to link into the
In the project view, add LVTestPanel.h to the project Header Files folder. This header
file will need to be included to the TestPanelDlg.cpp file under the other includes at the
top of the file.
Two code modifications will need to be made. The first will be in the OnButton handler
for the Open LV Test Panel button. In that function add a call to LVTestPanel. This is
one of the two exported functions generated from the LabVIEW Test Panel application.
The second modification is in the OnTimer function. The line before the call to
CDialog:nTimer(nIDEvent), add the following line of code:
UpdateFrontPanelData(cLed1, cLed2, m_IObuffer.analog1, m_IObuffer.analog2, (P0 &
0x01), (P0 & 0x02) >> 1, (P0 & 0x04) >> 2, (P0 & 0x08) >> 3);
This will update the global variables in the LabVIEW Test Panel application.
Finally, build and run the application with a F320 board running the TestPanel firmware
found in the following directory: