LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Task Handle to and from LabView dll with .NET

Hello,

I've been using Microsoft Visual C#.NET and Microsoft Visual Basic.NET as a test executive. I'd like to make use of LabView toolkits to control PXI modules like the NI PXI-4461 by creating LabView dlls to access via .NET. I've successfully passed data to/from my LabView dlls with .NET, but I haven't been able to pass the instrument task handles. Are there any conversions that need to happen on the task handles as they are input and output to/from LabView? How should the .NET code be written for this? Are there any examples available for this?

Thanks,

Luke

0 Kudos
Message 1 of 12
(4,234 Views)
Hi Luke,
 
Have you tried passing the handles as strings?
 
What tasks are you performing in the .NET side of the code? Could you set all the handles in the labview dll to be represented by an enum or similar data type? Or is there a reason you want the handles in the .NET side?
Sappster
0 Kudos
Message 2 of 12
(4,212 Views)

Mark,

Thanks for the reply.

I have tried passing the handles as strings and other data types, but I haven't had any luck.

On the .NET side, I'm not modifying the tasks, but only passing them for later use. For example, I will want to output a signal, then take some measurements, and once the measurements are complete, stop the waveform output.

Attached is a quick and dirty LabView project that includes VI's to output signal, measure signal, and stop the card. The "PXI_AudioAnalyzer.vi" is a pseudo example that ties these VI's together.

Thanks,

Luke

0 Kudos
Message 3 of 12
(4,204 Views)
Hi Luke,
 
You didn't attach the files you mentioned.
 
You should be able to manipulate the strings and use them for your code. The task inputs can be replaced with strings, so as long as you format them correctly you should be able to use them. What problems are you running into with passing strings? Any error codes?
Sappster
0 Kudos
Message 4 of 12
(4,183 Views)

Mark,

 

Sorry, I had some issues attaching my files.  In the attache zip, there is a LabView project with 4461_waveform_out_noLoop.vi and 4461_Stop.vi that I used to create the 4461_Stop.dll.  I have also included a directory with my .NET code (4461_Labview_Stop).  In this example, I'm just trying to output a waveform with the 4461 via .NET through a call to the 4461_waveform_out_noLoop.vi (this step works) and then stop it witha call to the 4461_Stop.vi (this part doesn't work).

I've tried doing this by converting the LabView task handle to a string and have had the same results as the provided example.  I haven't had any error code, but the instrument doesn't respond to the .NET calls when handles are passed in to LabView.

 

Do you have any recommendations?

 

Thanks,

 

Luke

0 Kudos
Message 5 of 12
(4,147 Views)

Hi Luke,

 

Have you considered just accessing the DAQmx Dlls instead? That may be easier than writing your own. You can find the reference help for those under start » programs » National Instruments » NI-DAQ.

 

As far as your code goes, you are passing the tasks as numeric integers. Does that work for the waveform output call? Also, I didn't find the stop function in your dlls, did you include it in the compiled dll?

Sappster
0 Kudos
Message 6 of 12
(4,127 Views)

Mark,

 

I'm trying to get the handle passes to work with my simple 4461 output example first because I'd like to use Labview's Sound and Vibration toolkit. From what I know, the Sound and Vibration Toolkit is only available in LabView.  Likewise, I'd like to use some LabView code for my RF PXI instruments too.  Ultimately, I'd like to use .NET for as much as I can, but only use LabView created dlls for features that aren't available in .NET. To do this, I need to be able to pass handles in and out of LabView and I've started simple with the 4461 output example where I have one VI initialize the instrument and generate the signal and have another VI stop the instrument.  Do you know if it's possible to get toolkits that are only available in LabView for .NET? I can't find any examples that do this. Do you have any examples available that pass instrument handles into and out of .NET, preferrably in C#?

 

For my provided code, the tasks are numeric integers. I've tried many different data types for the tasks (including strings), and NOTHING has worked.  The waveform output calls outputs a signal because at that point I'm only passing my amplitude and frequency information into the LabView dll but if I pass the task handle as a string, I get garbage in .NET. For every method that I've tried, once I get the handle into .NET, when I call the stop VI, the instrument doesn't stop outputting signal. 

 

In the dll, the stop function is called _4461_Stop, so yes, it's in my compiled dll.

 

Thanks,

 

Luke

0 Kudos
Message 7 of 12
(4,123 Views)

Hi Luke,

 

Here are some references about programming in c# .NET. I recommend seperating your program and doing the DAQ tasks using the DAQ API and passing the data you want to run in the sound and vibration toolkit to your labview dlls. This way you have supported functions for DAQ and many examples.

 

You are corrct about the sound and vibration toolkit, it is not intended to be used in anything other than LabVIEW, so you will have to create wrapper dlls to access the functionality that you want.

 

http://digital.ni.com/public.nsf/allkb/F0FD13D2DD0C433986256D9C00468D29?OpenDocument

 

Let me know if this helps or if that isn't an option.

Sappster
0 Kudos
Message 8 of 12
(4,107 Views)

Mark,

 

Thanks for the info. I've used the NI provided DAQmx examples successfully, but wouldn't I still need to pass the handle to the LabView dll to take measurements using the Sound and Vibration toolkit?  How do I do this?

 

Thanks,

 

Luke

0 Kudos
Message 9 of 12
(4,103 Views)
The acquisition is done using the DAQ drivers and the sound and vibration toolkit just analyzes the data. What Measurment are you talking about specifically? The inputs for that function should just be data. Does it recquire a task input?
Sappster
0 Kudos
Message 10 of 12
(4,101 Views)