Discussion:
Task Handle to and from LabView dll with .NET
(too old to reply)
brantdwight
2008-08-07 00:40:05 UTC
Permalink
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
Sappster
2008-08-07 20:10:09 UTC
Permalink
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?
brantdwight
2008-08-07 22:10:07 UTC
Permalink
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
Sappster
2008-08-08 17:40:08 UTC
Permalink
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?
brantdwight
2008-08-13 20:40:06 UTC
Permalink
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


4461_handle.zip:
http://forums.ni.com/ni/attachments/ni/170/349136/1/4461_handle.zip
Sappster
2008-08-14 20:40:07 UTC
Permalink
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?
brantdwight
2008-08-14 21:10:04 UTC
Permalink
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
Sappster
2008-08-15 13:40:19 UTC
Permalink
Hi Luke,&nbsp;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&nbsp;to your labview dlls. This way you have supported functions for DAQ and many examples. &nbsp;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.&nbsp;<a href="http://digital.ni.com/public.nsf/allkb/F0FD13D2DD0C433986256D9C00468D29?OpenDocument" target="_blank">http://digital.ni.com/public.nsf/allkb/F0FD13D2DD0C433986256D9C00468D29?OpenDocument</a> &nbsp;Let me know if this helps or if that isn't an option.
brantdwight
2008-08-15 14:10:05 UTC
Permalink
Mark,&nbsp;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?&nbsp; How do I do this?&nbsp;Thanks,&nbsp;Luke
Sappster
2008-08-15 14:10:05 UTC
Permalink
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?
brantdwight
2008-08-15 14:10:07 UTC
Permalink
Mark,&nbsp;After looking at it, I'll just need to pass data from DAQmx&nbsp;to scale it to engineering units, apply filtering, and take THD, THD+Noise, and Sinad measurements.&nbsp; Hopefully a similiar approach can be done&nbsp;with&nbsp;RF measurements.&nbsp;Thanks,&nbsp;Luke
Sappster
2008-08-15 14:10:08 UTC
Permalink
Hi Luke,&nbsp;The Rf measurments should be similar. Let me know if theres anything I can help with.&nbsp;Cheers,
Loading...