diff --git a/C#/XA/KST201/App.config b/C#/XA/KST201/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/C#/XA/KST201/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/C#/XA/KST201/KST201.csproj b/C#/XA/KST201/KST201.csproj new file mode 100644 index 0000000..d2d7d74 --- /dev/null +++ b/C#/XA/KST201/KST201.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {604C5D86-9F3D-4585-8C8E-F4579CB3AAA4} + Exe + KST201 + KST201 + v4.8 + 512 + true + true + + + x64 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + False + ..\..\..\..\..\..\Program Files\Thorlabs XA\SDK\.NET Framework (C#)\Libraries\x64\tlmc_xa_dotnet.dll + + + + + + + + + + + \ No newline at end of file diff --git a/C#/XA/KST201/Program.cs b/C#/XA/KST201/Program.cs new file mode 100644 index 0000000..88ee44c --- /dev/null +++ b/C#/XA/KST201/Program.cs @@ -0,0 +1,129 @@ +// Title: KST201 +// Created Date: 01/29/2025 +// Last Modified Date: 01/29/2025 +// .NET Framework version: 4.8 +// Thorlabs DLL version: 1.5.2.26681 +// Example Description: +// This example demonstrates how to get a list of connected devices, set-up the communication for the Thorlabs +// KST201 controllers, home it, and move it by 1 mm or degrees. + +using System; +using Thorlabs.MotionControl.XA; +using Thorlabs.MotionControl.XA.Products; + +namespace KST201 +{ + class Program + { + private static string _deviceId = "26006127";//Replace with your device serial number + static void Main(string[] args) + { + SystemManager systemManager; + + //Start up XA + try + { + systemManager = SystemManager.Create(); + systemManager.Startup(); + } + catch(Exception ex) + { + Console.WriteLine("Exception: {0}", ex.Message); + return; + } + + //Get the device list + System.Collections.Generic.IList devicelist = systemManager.GetDeviceList(); + + // Print all connected devices + Console.WriteLine("Connected devices: {0}", devicelist?.Count ?? 0); + if (devicelist != null && devicelist.Count > 0) + { + foreach (var d in devicelist) + { + Console.WriteLine("Devices"); + try + { + Console.WriteLine("{0}, Serial Number: {1}\n", + d.PartNumber, + d.Device); + + } + + catch + { + Console.WriteLine(d?.ToString() ?? ""); + } + } + } + else + { + Console.WriteLine("No devices found."); + } + + //Open the KST201 device + Kst201 device; + bool ret = systemManager.TryOpenDevice(_deviceId, "", OperatingModes.Default, out device); + if (ret==false) + { + Console.WriteLine("Failed to open device {0}", _deviceId); + systemManager.Shutdown(); + return; + } + else + { + Console.WriteLine("Device {0} opened successfully", _deviceId); + } + try + { + //Enable the device + device.SetEnableState(EnableState.Enabled,TimeSpan.FromSeconds(1)); + + //Get the hardware info + HardwareInfo hardwareInfo = device.GetHardwareInfo(TimeSpan.FromSeconds(1)); + Console.WriteLine("Device Name:{0}", hardwareInfo.PartNumber); + + //Home the device + Console.WriteLine("Homing..."); + device.Home(TimeSpan.FromSeconds(60)); + Console.WriteLine("Homing completed."); + + //Get the connected product info to determine the unit type + ConnectedProductInfo productInfo =device.GetConnectedProductInfo(); + Unit deviceUnit=productInfo.UnitType; + + //Get the current position + Int32 currentPosInDeviceUnits = device.GetPositionCounter(TimeSpan.FromSeconds(5)); + + //Move the device by 1 mm + double distance = 1.0; // in mm + long valueInDeviceUnits = device.FromPhysicalToDeviceUnit(ScaleType.Distance, deviceUnit, distance); + Console.WriteLine("Moving {0} mm...", distance); + device.Move(MoveMode.RelativeMove,(int)valueInDeviceUnits, TimeSpan.FromSeconds(30)); + Console.WriteLine("Move completed."); + + //Get the current position + currentPosInDeviceUnits = device.GetPositionCounter(TimeSpan.FromSeconds(5)); + + //Convert the device units to physical units + UnitConversionResult currentPos =device.FromDeviceUnitToPhysical(ScaleType.Distance, currentPosInDeviceUnits); + Console.WriteLine("Current Position: {0} {1}", currentPos.Value, deviceUnit.ToString()); + + } + catch (Exception ex) + { + Console.WriteLine("Exception:{0}",ex.Message); + } + finally + { + //Close the device + device.Disconnect(); + device.Close(); + + //Shutdown XA + systemManager.Shutdown(); + + } + } + } +} diff --git a/C#/XA/KST201/Properties/AssemblyInfo.cs b/C#/XA/KST201/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c93da96 --- /dev/null +++ b/C#/XA/KST201/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("KST201")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("DCHSCCM01")] +[assembly: AssemblyProduct("KST201")] +[assembly: AssemblyCopyright("Copyright © DCHSCCM01 2026")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("604c5d86-9f3d-4585-8c8e-f4579cb3aaa4")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/C#/XA/KST201/obj/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs b/C#/XA/KST201/obj/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs new file mode 100644 index 0000000..15efebf --- /dev/null +++ b/C#/XA/KST201/obj/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] diff --git a/C#/XA/KST201/obj/Debug/KST201.csproj.FileListAbsolute.txt b/C#/XA/KST201/obj/Debug/KST201.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..e721936 --- /dev/null +++ b/C#/XA/KST201/obj/Debug/KST201.csproj.FileListAbsolute.txt @@ -0,0 +1,10 @@ +C:\Users\gboedecker\source\repos\KST201\KST201\bin\Debug\KST201.exe.config +C:\Users\gboedecker\source\repos\KST201\KST201\bin\Debug\KST201.exe +C:\Users\gboedecker\source\repos\KST201\KST201\bin\Debug\KST201.pdb +C:\Users\gboedecker\source\repos\KST201\KST201\bin\Debug\tlmc_xa_dotnet.dll +C:\Users\gboedecker\source\repos\KST201\KST201\obj\Debug\KST201.csproj.AssemblyReference.cache +C:\Users\gboedecker\source\repos\KST201\KST201\obj\Debug\KST201.csproj.CoreCompileInputs.cache +C:\Users\gboedecker\source\repos\KST201\KST201\obj\Debug\KST201.csproj.Up2Date +C:\Users\gboedecker\source\repos\KST201\KST201\obj\Debug\KST201.exe +C:\Users\gboedecker\source\repos\KST201\KST201\obj\Debug\KST201.pdb +C:\Users\gboedecker\source\repos\KST201\KST201\obj\Debug\KST201.exe.config diff --git a/C#/XA/KST201/obj/Debug/KST201.csproj.Up2Date b/C#/XA/KST201/obj/Debug/KST201.csproj.Up2Date new file mode 100644 index 0000000..e69de29 diff --git a/C#/XA/KST201/obj/Debug/KST201.exe.config b/C#/XA/KST201/obj/Debug/KST201.exe.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/C#/XA/KST201/obj/Debug/KST201.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file