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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using AddInPlugin.Util;
using LabViewHelper;
using NationalInstruments.LabVIEW.Interop;
using OpenTap;
using OpenTap.Addin.Annotation;
using System;
using System.Linq;
using ViHelper;
 
namespace AddInPlugin
{
    [Prototype]
    [Display("ViStep", Description: "ÔËÐÐVI")]
 
    public class ViStep : VariableTestStep
    {
        #region Settings
        private string viPath;
 
        [Display("·¾¶", Order: 0.0, Description: "Dll¾ø¶Ô·¾¶.")]
        [FilePath(FilePathAttribute.BehaviorChoice.Open)]
        public string ViPath
        {
            get => viPath;
            set
            {
                if (viPath != value)
                {
                    viPath = value;
                    OnPropertyChanged(nameof(viPath));
                    LoadVi();
                }
            }
        }
 
        #endregion
 
        static ViStep()
        {
            try
            {
                LabViewRunner.GetIO(new LVPath(), 0, out Cluster[] inputs, out Cluster[] outputs, out type[] iTypes, out type[] oTypes, out var viError);
            }
            catch (Exception ex)
            {
 
            }
        }
 
        public ViStep()
        {
            // ToDo: Set default values for properties / settings.
            Rules.Add(() => !string.IsNullOrWhiteSpace(ViPath), "·¾¶²»ÄÜΪ¿Õ", ViPath);
        }
 
        private void LoadVi()
        {
            try
            {
                if (string.IsNullOrEmpty(ViPath))
                {
                    return;
                }
                //LabViewRunner.GetIO(new LVPath(ViPath), 0, out Cluster[] inputs, out Cluster[] outputs, out type[] iTypes, out type[] oTypes, out var viError);
 
                LabViHelper.GetIOType(ViPath, out var inVariables, out var outVariables);
 
                MethodVariables.Clear();
                foreach (var inv in inVariables)
                {
                    MethodVariables.Add(new MethodVariable
                    {
                        Name = inv.Name,
                        Type = inv.Type,
                        TypeName = inv.Type.ToString(),
                        Direction = VariableDirection.In,
                        ValueStr = inv.Data.ToString()
                    });
                }
 
                foreach (var onv in outVariables)
                {
                    MethodVariables.Add(new MethodVariable
                    {
                        Name = onv.Name,
                        Type = onv.Type,
                        TypeName = onv.Type.ToString(),
                        Direction = VariableDirection.Out
                    });
                }
            }
            catch (Exception ex)
            {
                Log.Error("ViStep load vi error. {0}", ex);
            }
        }
 
        public override void PrePlanRun()
        {
            // ToDo: Optionally add any setup code this step needs to run before the testplan starts
            base.PrePlanRun();
        }
 
        /// <summary>
        /// ×ª»»²ÎÊý
        /// </summary>
        private void ResolveVariables()
        {
            foreach (var m in MethodVariables)
            {
                m.Value = PlanRun.Resolve(this, m.ValueStr);
            }
        }
 
        /// <summary>
        /// ÔËÐк¯Êý
        /// </summary>
        private void RunMethod()
        {
            ResolveVariables();
 
            var ins = MethodVariables.Where(m => m.Direction == VariableDirection.In)
                    .Select(m => new Cluster { name = m.Name, variant__32Data = new LVVariant(m.Value) }).ToArray();
 
 
            LabViewRunner.ViRunner(new LVPath(this.ViPath), 0, ins, out var outs);
            foreach (var ov in outs)
            {
                foreach (var m in MethodVariables)
                {
                    if (ov.name == m.Name)
                    {
                        m.Value = ov.variant__32Data.value;
                        break;
                    }
                }
            }
        }
 
        public override void Run()
        {
            try
            {
                // ToDo: Add test case code here
                //RunChildSteps(); //If step has child steps.
                RunMethod();
 
                UpdateVariableToRuntime();
                this.Verdict = Verdict.Pass;
            }
            catch (Exception ex)
            {
                Log.Error("ViStep Run error. {0}", ex);
                this.Verdict = Verdict.Error;
            }
        }
 
        private void UpdateVariableToRuntime()
        {
            //if (IsConstructorMethod)
            //{
            //    var methodVariable = MethodVariables[0];
            //    PlanRun.UpdateRuntimeVariable(methodVariable.ValueStr, instance);
            //}
            foreach (var mv in MethodVariables)
            {
                if (mv.Direction == VariableDirection.Out)
                {
                    PlanRun.Update(this, mv.ValueStr, mv.Value);
                }
            }
        }
 
        public override void PostPlanRun()
        {
            // ToDo: Optionally add any cleanup code this step needs to run after the entire testplan has finished
            base.PostPlanRun();
        }
    }
}