LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling Labview with C#: error code -2147352571

Hi,    

 

  I need to call LabVIEW and pass parameters to LabVIEW from C# so that I can use labview as a sort of "driver" to control my signal generator from C#.

 

I found this tutorial for controlling LabVIEW from C#: http://zone.ni.com/devzone/cda/epd/p/id/3838

 

It contains a C# project that calls a vi which acts as a calculator, parsing a string and computing an answer.

 

 

     I am trying to use this file as a base to work from by changing a few lines to make C# code that calls a different vi (the one that controlls my signal generator).

 

I have attached both the Signal_Generator_Controller_For_Sentry_Testing.vi and the CallLV project that I modified and the origional from NI.

 

I get this error when I click "Run vi" from the C# gui:   Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

If I click "view detail" from the "COMException was unhandled", I find that the error code is -2147352571. The error occurs at this line in the C# code:

 

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

 

   

     Here are the experiments I performed (that didn't solve the problem):

 

Since the demo vi that NI made is contained in a llb file, I built a project that contained this vi, added an llb file to the project, and put Signal_Generator_Controller_For_Sentry_Testing.vi in the llb file.

 

My vi is all inputs (the only output is the signal generator, which is not on the front pannel, obviously). I have tried changing the connector pane so that one of the connectors was an output.

 

I have tried googling the error messages: there isn't anything specific enough to this problem (C# communicating with labview), the error message occurs in situations in multiple programming languages.

 

I have tried passing the parameters "by val" rather than "by ref", but a different error occurs.

 

     Here is what I am able to deduce/ what I have noticed:

 

The vi that NI created to demo communicating with C# "seems to be unable to leave run mode". When you call Labview from C#, the front pannel comes up and you cannot select the "stop button": it is grey. The Pause button doesn't stop exectution either. This makes me think that the vi was compiled in a different manner. I am more inclined to believe that teh vi is formated incorrectly rather than the C# code working improperly.

 

The types of the two parameters, param1 and param2, going into the call statement  are "string" and "object" respectively. This is the same as with the NI code, which works fine. It is not an error with an incorrectly sized array parameter; that gives a different error message and I have fixed that problem. So, even though the error message says "type mismatch, I don't think that the input parameters to the Call function are incorrect.

 

   To Reproduce this error:

 

I have Microsoft Visual C# Express 2008 Edition

I am using Labview version 8.6

In my version of the C# code, in this line: string vipath = @"C:\Program Files\National Instruments\LabVIEW 8.6\builds\Sentry_Test\Sentry.llb\Signal_Generator_Controller_For_Sentry_Testing.vi";

 

You will have to change the directory to wherever you store the vi.

 

You will need the "Labview" Library so that the C# line "using Labview" will work. I think it is downloaded by default either by labview or visual studio.

 

In the C# file that NI created, you must add a fourth parameter '3' in  the line vi= lv.GetVIReference(vipath,"",true) as the last parameter. You get a compiler error otherwise. That was a mistake NI made.

 

Thank you for the help.

 

--Zach

0 Kudos
Message 1 of 3
(5,959 Views)

Zach,

 

Unfortunately, I do have more of a knowledge of how to control objects using ActiveX in LabVIEW and not the other way around.  What ActiveX properties and methods are you using in your code and what are the input parameters that you are trying to pass?  You mentioned that you only have two input parameters, but the VI you posted has 3 inputs.  My guess would be that if you are indeed seeing a type mismatch, it is trying to pass an data type LabVIEW does not know what to do with.  This has been seen when trying to pass strings as Task data types (like the VISA Session).  

ColeR
Field Engineer
0 Kudos
Message 2 of 3
(5,917 Views)

I figured it out and fixed it:

 

One of the VI inputs was a VISA I/O type. I had to type cast it from string to the correct type in order to get the parameters to pass correctly.

 

Also, in my C# program, I had the frequency and amplitude being passed in as string types. 

 

Those three errors were causing the type mismatch.

 

Yes, there are 3 inputs in the vi.

 

Thank you for your help.

 

--Zach

0 Kudos
Message 3 of 3
(5,907 Views)