using LabViewHelper;
|
using NationalInstruments.LabVIEW.Interop;
|
using System;
|
using System.Collections.Generic;
|
|
namespace ViHelper
|
{
|
public class ViVariable
|
{
|
public string Name { get; set; }
|
public Type Type { get; set; }
|
public dynamic Data { get; set; }
|
}
|
|
public class LabViHelper
|
{
|
public static Type ConvertType(type labviewType)
|
{
|
if (labviewType == type.I8 || labviewType == type.I16 || labviewType == type.I32
|
|| labviewType == type.I64 || labviewType == type.U8
|
|| labviewType == type.U16 || labviewType == type.U32
|
|| labviewType == type.U64)
|
{
|
return typeof(int);
|
}
|
if (labviewType == type.Single__32Float || labviewType == type.Double__32Float)
|
{
|
return typeof(double);
|
}
|
if (labviewType == type.Boolean)
|
{
|
return typeof(bool);
|
}
|
|
if (labviewType == type.String)
|
{
|
return typeof(string);
|
}
|
throw new Exception("No supported type");
|
}
|
|
private static void Get(string viPath, out ViVariable[] inVariables, out ViVariable[] outVariables)
|
{
|
try
|
{
|
inVariables = null;
|
outVariables = null;
|
|
var path = new LVPath(viPath);
|
LabViewRunner.GetIO(path, 0, out Cluster[] inputs, out Cluster[] outputs, out type[] iTypes, out type[] oTypes, out var viError);
|
|
|
|
if (inputs == null || outputs == null)
|
{
|
throw new Exception("No Controls");
|
}
|
|
if (inputs.Length != iTypes.Length)
|
{
|
throw new Exception("In param nums Error");
|
}
|
|
if (outputs.Length != oTypes.Length)
|
{
|
throw new Exception("Out param nums Error");
|
}
|
|
inVariables = new ViVariable[inputs.Length];
|
for (int i = 0; i < inputs.Length; i++)
|
{
|
inVariables[i] = new ViVariable
|
{
|
Name = inputs[i].name,
|
Data = inputs[i].variant__32Data.value,
|
Type = ConvertType(iTypes[i])
|
};
|
}
|
|
outVariables = new ViVariable[outputs.Length];
|
for (int i = 0; i < outputs.Length; i++)
|
{
|
outVariables[i] = new ViVariable
|
{
|
Name = outputs[i].name,
|
Data = outputs[i].variant__32Data.value,
|
Type = ConvertType(oTypes[i])
|
};
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
public static void GetIOType(string viPath, out ViVariable[] inVariables, out ViVariable[] outVariables)
|
{
|
try
|
{
|
Get(viPath, out inVariables, out outVariables);
|
}
|
catch
|
{
|
Get(viPath, out inVariables, out outVariables);
|
}
|
}
|
}
|
}
|