Showing results for 
Search instead for 
Did you mean: 

Calling vi from C#


I am trying to run a VI from C# and extract the result of the vi. The results is of type Waveform (DBL). I am able to send the correct input parameter to the vi and run the vi but I am unable to extract the wave form from the vi. How can I extract a Waveform (DBL) from vi? Here is the code I am using :

//Instantiate a reference to LabVIEW
lv = new LabVIEW.ApplicationClass();

//Set the path to the VI
string vipath=@"d:\\";

//Get reference to that VI
vi= lv.GetVIReference(vipath,"",true,5);

// Input and output string name of the vi I am calling
string[] str1 = new String[4];
str1[3]="signal out";

//The wrapper function expects to be passed a object type by reference.
//We pass the string array to the object type here
object param1 = (object)str1;

//Define the variable that will pass the expression to be evaluated to
//LabVIEW and typecast it to type object

object[] str2 = new object[4];
object param2= (object)str2;

//Check if front panel of VI should be displayed

//Call the VI
vi.Call(ref param1,ref param2);

//Extract the answer and Display the result

0 Kudos
Message 1 of 3
What error are you getting when you try to retrieve your waveform data?...which is an array of dbl right?

0 Kudos
Message 2 of 3
I'm not sure what problem you are having, but the interop code that you are using doesn't look right. I am not sure about the output type (DBL waveform) since you are casting it as an array. However, here is an example I wrote and tested that calls a VI with 4 string inputs and one DBL array output. If you are using a LV Waveform type, then realize that the output isn't a simple array but a complex type. In fact, the type of the output element is System.__ComObject.

If the vi is indeed outputing a waveform then consider using the "Get Waveform Components" to break it into simplier data types (t0, delta, array) which are automatically marshaled for you (as in the example below). If you can't change the VI or create a wrapper VI that does the breakout for you, let me know and we can talk about access the waveform object in C#.


LabVIEW.Application lv = new LabVIEW.ApplicationClass();
LabVIEW.VirtualInstrument vi = lv.GetVIReference("c:\\temp\\", "", true, 5);
vi.ShowFPOnCall = true;

String[] paramNamesArray = new String[5];
paramNamesArray[0] = "InputOne";
paramNamesArray[1] = "InputTwo";
paramNamesArray[2] = "InputThree";
paramNamesArray[3] = "InputFour";
paramNamesArray[4] = "Array";
Object paramNames = paramNamesArray;

Object[] paramValsArray = new Object[5];
paramValsArray[0] = "Here is one";
paramValsArray[1] = "Here is two";
paramValsArray[2] = "Here is three";
paramValsArray[3] = "Here is four";
paramValsArray[4] = new Double[0];
Object paramVals = paramValsArray;

vi.Call(ref paramNames, ref paramVals);

// Convert the object reference back to the array - remember it was
// an ref parameter so on the return paramValsArray and paramVals point
// to different objects
paramValsArray = (Object[])paramVals;
Double[] results = (Double[])paramValsArray[4];
for(Int32 i=0; i{
Console.WriteLine("{0} = {1}", i, results[i]);
0 Kudos
Message 3 of 3