Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions C#/XA/KST201/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
57 changes: 57 additions & 0 deletions C#/XA/KST201/KST201.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{604C5D86-9F3D-4585-8C8E-F4579CB3AAA4}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>KST201</RootNamespace>
<AssemblyName>KST201</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="tlmc_xa_dotnet, Version=1.1.3.24917, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files\Thorlabs XA\SDK\.NET Framework (C#)\Libraries\x64\tlmc_xa_dotnet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
129 changes: 129 additions & 0 deletions C#/XA/KST201/Program.cs
Original file line number Diff line number Diff line change
@@ -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<DeviceInfo> 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() ?? "<null device>");
}
}
}
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();

}
}
}
}
33 changes: 33 additions & 0 deletions C#/XA/KST201/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
10 changes: 10 additions & 0 deletions C#/XA/KST201/obj/Debug/KST201.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -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
Empty file.
6 changes: 6 additions & 0 deletions C#/XA/KST201/obj/Debug/KST201.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>