LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI GUI in DLL for use from matlab

Hello all,
 
My good intention for this year is to learn how to build a CVI GUI for data acquisition that can - on request - pass on data to matlab.
 
I want to build an acqusition GUI in CVI 8 eg based on one of the DAQmx examples for analog voltage input.
I started to build a GUI in a DLL eg as shown in CVI examples for DLL: guidll and usegui.
Using an mex-dll sample from matlab, I made the DLL in Labwindows and called it from matlab. This seems to work fine.
 
As the matlab-mex uses a single function 'mexFunction'  as interface between matlab and DLL, I will have to call this function with parameters for specific procedures:
- start GUI
- stop GUI and release DLL
- software-trigger acquisition
- transfer data
The actual acquisition configuration can be done easily from a Labwindows GUI.
While I expect to be familiar with most upcoming problems, I need to know how to handle one specific procedure: HOW can I start the 'RunUserInterface'  and return immediately to the calling function ? Because I want to have matlab and the GUI running parallel until I send a call to stop the GUI.
 
Is multi-thread the (only) way to start this ?
Does anybody have a simple example ?
Does anybody have a simple example of matlab combined with DLL -GUI from CVI ?
Does anybody have a different (and already working) procedure to combine a Labwindows/CVI GUI with data transfer to matlab ?
 
Regards, Jos
 
0 Kudos
Message 1 of 8
(4,911 Views)

A Multi-threaded DLL is the best solution for this, yes.

I am not familiar with mathlab, so I have no example for that, but lets say "traditionally" you would do something like this:

mexFunction()

{

LoadPanelEx(...);

RunUserInterface();

........

}

As you said, now mathlab waits for the end of the function, so you would have to quit your User Interface (QuitUserInterface) that mathlab continues working. Do the following instead:

 

mexFunction()

{

LoadPanelEx(...);

CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE,MyFunction,NULL,NULL);

........

}

int CVICALLBACK MyFunction(void *functionData)

{

RunUserInterface()

.......

}

This Version will start a new thread, and returns to mathlab immediately. In the new Thread you can call the RunUserInterface() function, so this thread will run until the UI is closed via QuitUserInterface().

 

Hope this helps!

0 Kudos
Message 2 of 8
(4,885 Views)

Hello ANdre,

 

Thanks !

 However, I got new challenges (read: problems to be solved) and got stuck by my lack of experience. It seemed as if I had to build a kind of DLL data server that exchanges data from/to matlab and from/to the GUI that I wanted to build.

So: I decided to limit myself for the time being to 1) define a NIDAQmx task in Measurement&Automation, and 2) build a DLL with the (single) function mexFunction that loads and executes this task and returns the data as a #channels * #samples back to matlab. So for the time being, I cannot change the task from the matlab script. But after interactive setting/changing the task with MAX, I can retrieve new data repeatedly. Not fancy but easy working!

I still have to do some debugging and verification of input parameter 'TaskName', but the first version works.

 

For other people who try this: I got stuck in the beginning because the NIDAQ had installed a CVI runtime engine version 7.x where I build the DLL with CVI version 8.0. I only copied the DLL to the matlab working directory. Wrong wrong wrong !!! I needed also the newest runtime engine.

 

Thanks, Jos

 

0 Kudos
Message 3 of 8
(4,864 Views)
As a Note: In the CVI development environment, you can build an installer (Menu Build-->Distributions), that automatically would install the DLL and the correct Runtime-Engine. In the Installer Options you can decide if the Runtime should be installed in the application directory or in thw windows/system32 folder.
0 Kudos
Message 4 of 8
(4,850 Views)
Hallo,
I want to call and configure the configuration of fpga and pxi system from  matlab. is it  possible ? if yes  say  me please how?
I work with LabVIEW 8.0 and Matlab 7
 
thanks
befaiz
0 Kudos
Message 5 of 8
(4,648 Views)

Hello Befaiz,

 

My advise is to start in new post in forum for Labview.

As my solution (Measurement & Automation task from matlab without any GUI) worked fined for my requirements (data retrievel after A/D task with multi A/D interface by National Instruments), I have worked not further anymore on this subject.

 

Regards, JGS

 

 

0 Kudos
Message 6 of 8
(4,623 Views)

Hello Jos ,

i want to call my Simulation GUI.VI from Matlab.It is possible?and how?.

Does you have a simple example ?

Thanks

Befaiz

0 Kudos
Message 7 of 8
(4,479 Views)

Hello Befaiz,

If have halted my exercise for an interface towards matlab incl. GUI.

I have limited myself with a matlab so-called mexfunction wich is a DLL with one interface. I use this function to call a task that I have previous defined with Measurement and Automation for an NI multi I/O interface that is supported by NiDAQmx. And I return only a - multiple column - array with results from A/D conversion.

So I have no experience with labview nor with interfacing a GUI towards matlab.

Sorry I cannot help you, Jos

 

 

0 Kudos
Message 8 of 8
(4,466 Views)