chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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);
            }
        }
    }
}