LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get vi error out information using C#

Hi,I am working on concept-- running labVIEW test cases (.vi files) using C# code.

I am able to run any of the .vi file using my C# code. presently .vi file rans in backgroud (actually it is needed).

But i need to capture run time messages/warnings/error while running any of the labVIEW code. but i am not getting any solution how to do it.

 

Bellow is code snipet which will run laVIEW code.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Include LabVIEW namespace from the COM Interface
using LabVIEW;

namespace WindowsFormsApplication3
{
    class Labviewlaunch
    {
        public void labviewlaunchfun(string userSelectedFilePath)
        {
           
        _Application labVIEWApp = new Application();
            if (labVIEWApp == null)
            {
                Console.WriteLine("RunLabVIEWVI : An error occurred getting labVIEWApp.");
                return;
            }
            //Paths to VIs, must use absolute path
            //Enter the absolute path to your VI here
            string viadd_path = userSelectedFilePath;
            //Create VI object
            VirtualInstrument viadd = labVIEWApp.GetVIReference(viadd_path, "", false, 0);
           
            if (labVIEWApp == null)
            {
                Console.WriteLine("RunLabVIEWVI : An error occurred getting the VI reference.  Make sure the VI path you entered is correct.");
                return;
            }
            //Run the VI with default input values, you will see the values on the front panel update if it is open
            viadd.Run();
        }
    }
}

 

with this code .vi file will run in background. but we will not have any information about vi ran without any error or warning.

which function or API will give information of labview run time engine during running any of the labVIEW code.

 

please help me in this.

0 Kudos
Message 1 of 5
(2,468 Views)

my main intention is to get "error out" output information using C# code.

suggest me the C# code how to get VI "error out" output information in C#

 

0 Kudos
Message 2 of 5
(2,440 Views)

Well you are using the ActiveX server interface which is pretty old and only exports a LabVIEW VI server interface as it was available around LabVIEW 5 or so.

 

Basically you want to Call the VI synchronously rather than Run it asynchonously. 

 

The VirtualInstrument class does have a Call() method but its parameters are somewhat involved. 

Basically the first parameter is an array of strings that defines the names of the input and output parameters you want to reference, and the second parameter is an array of variants that has the same order as the names. In here you pass in values for any input parameter (front panel control) you specified in the name list and get a variant for any output parameter (front panel indicator) that was listed in the name list. (You might have to provide on the input side a dummy variant for the output parameters you want to retrieve!)

 

Your error cluster will be an extra challenge to parse as it will be a variant of (most likely an array with three variant elements that define the boolean status, integer code, and error message string element).

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 5
(2,424 Views)

Thanks for your solution.

 

instead of using  viadd.call() function, we can use viadd.GetControlValue("error out") method. where "error out" is the name of the error out indicator in vi what i loaded. with this function we can get information of vi status( run successfully or thrown an error)

 

but if i load other vi which will not have error out indicator !!  my C# code throws error.

 

Need to find out the way how we can monitor status of run time engine, when viadd.Run method is called. 

please suggest me, way to capture the message/warning/error information of labview run time engine when viadd.Run method is called.

 

is there a way to capture these information using C#?

 

I forget to tell my requirement. My main requirement is write a C# code which will pop-up message to load .vi file or .vi files in the folder. After loading, it just run the .vi file and update execution information(error/warning/successful pass info)  on to C# WPF textbox.

 

please help me in this.

Thank you

 

0 Kudos
Message 4 of 5
(2,409 Views)

Your terminology is pretty off here. You can not catch errors from the runtime engine itself. You can of course catch errors from your VI you run and you define yourself what errors the VI can generate if any, but if you use VI.Run() you do not know when your VI is finished (it could take several seconds to execute) and the output terminals of a VI are generally only guaranteed to be valid after the VI has finished execution. You could of course use VI.Run() and then poll VI.ExecState continously until it doesn't tell you to be in Running mode anymore but that is pretty involved and prone to race conditions, so using VI.Call() instead is still preferable. Call will block until the VI is finished executing.

If the VI you call has or has not the "error out" terminal is up to you. You define this interface and if you want to read the result of the VI you have to provide some means for the caller (even if it is external to LabVIEW as what you want) to retrieve that result. How you do that is your business.

You could for instance create involved code that would use VI.Call() to start the VI with whatever input parameters you may have and then after VI.Call() returns use VI.GetCtrlVal() to retrieve any possible output terminal and handle the error where the VI.GetCtrlVal() indicates that the terminal is not valid, but that has a possible race condition between the return of VI.Call() until you can execute VI.GetCtrlVal() if someone else in your code decides to call this same VI again in the meantime. Unlikely? Yes. Impossible? Absolutely NOT!!! And the almost impossible things are the ones that will bite your a$$ after you deploy your software to the final test system.

 

So you probably want to standardize the VI interface you want to be able to call from your external application in order to make it easier on the .Net side of things to call your functions!

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 5
(2,402 Views)