Skip to content

Commit 59b7df1

Browse files
committed
Restructured project. Added tests.
- Added support for wrapping LabView objects (treated like instruments) - Added support for out types.
1 parent 7ae1d6a commit 59b7df1

18 files changed

+372
-231
lines changed

Directory.Build.props

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
4+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
5+
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
6+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
7+
<TargetFramework>netstandard2.0</TargetFramework>
8+
<OpenTapVersion>9.23.2</OpenTapVersion>
9+
</PropertyGroup>
10+
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
11+
<IsDebug>true</IsDebug>
12+
</PropertyGroup>
13+
14+
<PropertyGroup Condition=" '$(Configuration)' == 'Release'">
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition="'$(IsDebug)'=='true'">
18+
<OutputPath>$(MSBuildThisFileDirectory)bin\Debug\</OutputPath>
19+
<Optimize>false</Optimize>
20+
<DebugType>full</DebugType>
21+
<DebugSymbols>true</DebugSymbols>
22+
</PropertyGroup>
23+
24+
<PropertyGroup Condition="'$(IsDebug)'!='true'">
25+
<OutputPath>$(MSBuildThisFileDirectory)bin\Release\</OutputPath>
26+
<DefineConstants>TRACE</DefineConstants>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
</PropertyGroup>
30+
</Project>

LabViewTestStep.cs

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="OpenTAP" Version="$(OpenTapVersion)" />
8+
<OpenTapPackageReference Include="Unit Test" Version="0.1.0-beta.44+ade62d1d" />
9+
</ItemGroup>
10+
<ItemGroup>
11+
<ProjectReference Include="..\OpenTap.LabView\OpenTap.LabView.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Linq;
2+
using OpenTap.LabView.Types;
3+
using OpenTap.UnitTest;
4+
5+
namespace OpenTap.LabView.UnitTests
6+
{
7+
public class TypeDataTests : ITestFixture
8+
{
9+
static TraceSource log = Log.CreateSource("test");
10+
11+
[Test]
12+
public void DetectPlugins()
13+
{
14+
// TODO: Add actual tests.
15+
var labViewResourceTypes = TypeData.GetDerivedTypes<Instrument>().ToArray();
16+
//var ins = labViewResourceTypes[1].CreateInstance();
17+
}
18+
19+
[Test]
20+
public void AnnotateResource()
21+
{
22+
// TODO: Add actual tests.
23+
var stepTypes =TypeData.GetDerivedTypes<LabViewTestStep>().ToArray();
24+
var connectType = stepTypes.FirstOrDefault(x => x.Name.Contains("Connect"));
25+
var instance = connectType.CreateInstance();
26+
var a = AnnotationCollection.Annotate(instance);
27+
var member= a.Get<IMembersAnnotation>().Members.FirstOrDefault(x => x.Get<IMemberAnnotation>()?.Member.Name.Contains("ServiceFoo") ?? false);
28+
29+
30+
}
31+
32+
33+
34+
}
35+
}

OpenTap.LabView.sln

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33712.159
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTap.LabView", "OpenTap.LabView\OpenTap.LabView.csproj", "{C1760C0B-F69D-416F-807B-F37797C6377E}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTap.LabView.UnitTests", "OpenTap.LabView.UnitTests\OpenTap.LabView.UnitTests.csproj", "{5053CA6C-FA23-439E-BE1E-B864164DD4B7}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{C1760C0B-F69D-416F-807B-F37797C6377E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{C1760C0B-F69D-416F-807B-F37797C6377E}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{C1760C0B-F69D-416F-807B-F37797C6377E}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{C1760C0B-F69D-416F-807B-F37797C6377E}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{5053CA6C-FA23-439E-BE1E-B864164DD4B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{5053CA6C-FA23-439E-BE1E-B864164DD4B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{5053CA6C-FA23-439E-BE1E-B864164DD4B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{5053CA6C-FA23-439E-BE1E-B864164DD4B7}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {41C2F350-C704-40B4-826D-C1F97D2673BB}
30+
EndGlobalSection
31+
EndGlobal
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Library</OutputType>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<OpenTapPackageDefinitionPath>package.xml</OpenTapPackageDefinitionPath>
6+
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<AdditionalOpenTapPackage Include="TUI" Version="1" />
11+
<AdditionalOpenTapPackage Include="Editor"/>
12+
<InternalsVisibleTo Include="OpenTap.LabView.UnitTests"/>
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="OpenTAP" Version="$(OpenTapVersion)" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<Reference Include="InteropAssembly">
21+
<HintPath>Dependency\InteropAssembly.dll</HintPath>
22+
</Reference>
23+
<Reference Include="NationalInstruments.LabVIEW.Interop">
24+
<HintPath>../Dependency/NationalInstruments.LabVIEW.Interop.dll</HintPath>
25+
</Reference>
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<Content Include="..\Dependency\InteropAssembly.dll">
30+
<Link>InteropAssembly.dll</Link>
31+
</Content>
32+
</ItemGroup>
33+
34+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"profiles": {
3+
"Editor": {
4+
"commandName": "Executable",
5+
"executablePath": "./editor.exe"
6+
},
7+
"Unit Test": {
8+
"commandName": "Executable",
9+
"executablePath": "./tap.exe",
10+
"commandLineArgs": "unit-test run --verbose"
11+
}
12+
}
13+
}

TestSteps/AssemblyLoader.cs renamed to OpenTap.LabView/TestSteps/AssemblyLoader.cs

+6-13
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
using System.ComponentModel;
55
using System.Linq;
66
using System.Reflection;
7-
using System.Windows.Forms;
8-
using static InteropAssembly.Demant__46ServiceFoo;
97

10-
11-
namespace OpenTap.Plugins.LabviewInterop
8+
namespace OpenTap.LabView
129
{
13-
[Display("Load Assembly", Group: "OpenTap.Plugins.LabviewInterop", Description: "Load Assembly from Labview VI Interop")]
14-
public class AssemblyLoaderStep : TestStep
10+
[Display("Load Assembly", Group: "LabVIEW", Description: "Load Assembly from Labview VI Interop")]
11+
class AssemblyLoaderStep : TestStep
1512
{
1613
#region Settings
1714
// ToDo: Add property here for each parameter the end user should be able to change.
@@ -27,17 +24,13 @@ public class ListItem
2724
[Browsable(true)]
2825
public void Button_Clicked()
2926
{
30-
OpenFileDialog openFileDialog1 = new OpenFileDialog();
31-
openFileDialog1.Filter = "Assembly Files (*.dll, *.exe)|*.dll;*.exe|All files (*.*)|*.*";
32-
openFileDialog1.FilterIndex = 1;
33-
openFileDialog1.RestoreDirectory = true;
27+
3428

35-
if (openFileDialog1.ShowDialog() == DialogResult.OK)
3629
{
3730
_listOfAvailableText.Clear();
3831
_listOfAvailableValues.Clear();
3932

40-
assemblyPath = openFileDialog1.FileName;
33+
assemblyPath = "test.dll";
4134

4235
// Load the assembly
4336
_assembly = Assembly.LoadFrom(assemblyPath);
@@ -148,7 +141,7 @@ public override void Run()
148141

149142
if (selectedMethod.GetParameters().Count(x => x.ParameterType.Name == "Qry") != 0)
150143
{
151-
objList.Add(new Qry());
144+
//objList.Add(new Qry());
152145
}
153146

154147
object[] parameters2 = getParameters(selectedMethod, objList.ToArray());

LabViewMemberData.cs renamed to OpenTap.LabView/Types/LabViewMemberData.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4-
namespace OpenTap.Plugins.LabView
4+
using NationalInstruments.LabVIEW.Interop;
5+
namespace OpenTap.LabView.Types
56
{
67
public class LabViewMemberData : IMemberData
78
{
@@ -19,6 +20,17 @@ public LabViewMemberData(LabViewTypeData labViewTypeData, ParameterInfo paramete
1920
Name = parameterInfo.Name;
2021
DeclaringType = labViewTypeData;
2122
TypeDescriptor = TypeData.FromType(parameterInfo.ParameterType);
23+
24+
// Generally Out parameters are marked ith a &. These we can just handle
25+
// by their underlying type. we know that they are references in the call.
26+
if (parameterInfo.IsOut && parameterInfo.ParameterType.Name == "String&")
27+
TypeDescriptor = TypeData.FromType(typeof(string));
28+
if (parameterInfo.IsOut && parameterInfo.ParameterType.Name == "Int32&")
29+
TypeDescriptor = TypeData.FromType(typeof(int));
30+
31+
// if its a resource class we need to use the wrapper class.
32+
if (TypeDescriptor.DescendsTo(typeof(LVClassRoot)))
33+
TypeDescriptor = new LabViewTypeData(((TypeData)TypeDescriptor).Type);
2234
Writable = true;
2335
Readable = true;
2436
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Reflection;
3+
using NationalInstruments.LabVIEW.Interop;
4+
namespace OpenTap.LabView.Types
5+
{
6+
class LabViewResource : Instrument
7+
{
8+
public readonly LabViewTypeData PluginType;
9+
LVClassRoot labViewObject;
10+
internal object LabViewObject;
11+
public LabViewResource()
12+
{
13+
14+
}
15+
16+
public LabViewResource(LabViewTypeData labViewPluginTypeData)
17+
{
18+
this.PluginType = labViewPluginTypeData;
19+
var tp = this.PluginType.Type;
20+
var ctor = tp.GetMethod(tp.Name, BindingFlags.Static | BindingFlags.Public);
21+
if (ctor != null)
22+
{
23+
var parameters = new object[1];
24+
ctor.Invoke(null, parameters);
25+
26+
this.LabViewObject = parameters[0];
27+
}
28+
else
29+
{
30+
var innerObject = Activator.CreateInstance(this.PluginType.Type);
31+
LabViewObject = innerObject;
32+
}
33+
34+
35+
}
36+
37+
}
38+
}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Collections.Generic;
2+
using System.ComponentModel;
3+
using System.Linq;
4+
using NationalInstruments.LabVIEW.Interop;
5+
namespace OpenTap.LabView.Types
6+
{
7+
public class LabViewTestStep : TestStep
8+
{
9+
public LabViewTypeData PluginType;
10+
public LabViewTestStep(LabViewTypeData type)
11+
{
12+
this.PluginType = type;
13+
Values = new Dictionary<string, object>();
14+
}
15+
[Browsable(false)]
16+
public Dictionary<string,object> Values
17+
{
18+
get;
19+
set;
20+
}
21+
public override void Run()
22+
{
23+
var p = PluginType.Method.GetParameters();
24+
// get the parameters for the methods. These should correspond 1:1 with the values.
25+
var parameters = p.Select(x =>
26+
{
27+
Values.TryGetValue(x.Name, out var value);
28+
if (value is LabViewResource lvr)
29+
{
30+
return lvr.LabViewObject;
31+
}
32+
return value;
33+
}).ToArray();
34+
35+
PluginType.Method.Invoke(null, parameters);
36+
for (int i = 0; i < p.Length; i++)
37+
{
38+
39+
if (p[i].Name.Contains("__32out"))
40+
{
41+
if (parameters[i] is LVClassRoot cls)
42+
{
43+
if (Values[p[i].Name.Replace("__32out", "__32in")] is LabViewResource res)
44+
{
45+
res.LabViewObject = cls;
46+
}
47+
}
48+
}else if (p[i].IsOut)
49+
{
50+
Values[p[i].Name] = parameters[i];
51+
}
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)