Skip to content
Open
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#/Benchtop/UDXC/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.7.2" />
</startup>
</configuration>
176 changes: 176 additions & 0 deletions C#/Benchtop/UDXC/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// Title: UDXC
// Created Date: 10/27/2025
// Last Modified Date: 10/27/2025
// .NET Framework version: 4.8.2
// Thorlabs DLL version: Kinesis 1.14.56
// Example Description:
// This example demonstrates how to set-up the communication for the Thorlabs UDXC Benchtop controllers.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Timers;
using Thorlabs.MotionControl.Benchtop.PiezoCLI.UDXC;
using Thorlabs.MotionControl.DeviceManagerCLI;

namespace UDXC_CSharp
{
internal class Program
{
static void Main(string[] args)
{
// Uncomment this line (and SimulationManager.Instance.UninitializeSimulations() at the end on Main)
// If you are using a simulated device
// SimulationManager.Instance.InitializeSimulations();

// Enter the serial number for your device
string serialNo = "122000001";

try
{
// Tell the device manager to get the list of all devices connected to the computer
DeviceManagerCLI.BuildDeviceList();
}
catch (Exception ex)
{
// An error occurred - see ex for details
Console.WriteLine("Exception raised by BuildDeviceList {0}", ex);
Console.ReadKey();
return;
}

// Get available UDXC and check out serial number is correct - by using the device prefix
// (i.e. for serial number 122000123, the device prefix is 122)
List<string> serialNumbers = DeviceManagerCLI.GetDeviceList(InertialStageController.DevicePrefix_UDXC);
if (!serialNumbers.Contains(serialNo))
{
// The requested serial number is not a UDXC or is not connected
Console.WriteLine("{0} is not a valid serial number", serialNo);
Console.ReadKey();
return;
}

// Create the device
InertialStageController device = InertialStageController.CreateInertialStageController(serialNo);
if (device == null)
{
// An error occured
Console.WriteLine("{0} is not a UDXC Controller", serialNo);
Console.ReadKey();
return;
}

// Open a connection to the device.
try
{
Console.WriteLine("Opening device {0}", serialNo);
device.Connect(serialNo);
}
catch (Exception)
{
// Connection failed
Console.WriteLine("Failed to open device {0}", serialNo);
Console.ReadKey();
return;
}

// Wait for the device settings to initialize - timeout 5000ms
if (!device.IsSettingsInitialized())
{
try
{
device.WaitForSettingsInitialized(5000);
}
catch (Exception)
{
Console.WriteLine("Settings failed to initialize");
}
}

// Display info about device
DeviceInfo deviceInfo = device.GetDeviceInfo();
Console.WriteLine("Device {0} = {1}", deviceInfo.SerialNumber, deviceInfo.Name);

// Start the device polling
// The polling loop requests regular status requests to the motor to ensure the program keeps track of the device.
device.StartPolling(200);
// Needs a delay so that the current enabled state can be obtained
Thread.Sleep(500);
// Enable the device otherwise any move is ignored
device.EnableDevice();
// Needs a delay to give time for the device to be enabled
Thread.Sleep(500);

// Call GetUDXCConfiguration on the device to initialize the settings
UDXCConfiguration udxcConfiguration = device.GetUDXCConfiguration(serialNo, DeviceConfiguration.DeviceSettingsUseOptionType.UseDeviceSettings);
UDXCSettings currentDeviceSettings = UDXCSettings.GetSettings(udxcConfiguration);
device.SetSettings(currentDeviceSettings, true, true);

// Performance Optimize
device.PulseParamsAcquireStart();
Thread.Sleep(500);
Console.WriteLine("Optimizing performance, please wait...");
// When IsPulseParamsAcquired is true, it indicates the optimization has finished
while (device.Status.IsPulseParamsAcquired == false)
Thread.Sleep(500);

//Home the stage - timeout 60000ms
Console.WriteLine("Home the device");
device.Home(60000);

//Optionally move the stage to target position (position is set in "nm")
int closeLoopPosition = 0;
if (closeLoopPosition != 0)
{
// Set the target position
device.SetClosedLoopTarget(closeLoopPosition);

// Get and Set the velocity and acceleration
UDXCClosedLoopParams closedLoopParams = device.GetClosedLoopParameters();
closedLoopParams.RefSpeed = 10000000; // velocity is set in nm/s
closedLoopParams.Acceleration = 10000000; // acceleration is set in nm/s^2
device.SetClosedLoopParameters(closedLoopParams);

try
{
// Move the stage
device.MoveStart();
Console.WriteLine("Moving the device to {0} nm", closeLoopPosition);

// Monitor the position
int posCheckCnt = 0, newPos = 0;
for(int i = 0; i < 100; i++)
{
newPos = device.GetCurrentPosition();
if (Math.Abs(closeLoopPosition - newPos) < 6000)
if (posCheckCnt > 3)
break;
else
{
Thread.Sleep(200);
posCheckCnt++;
}
else
Thread.Sleep(200);
}

// Print the current position
Console.WriteLine("Device moved to {0} nm", newPos);
}
catch (Exception)
{
Console.WriteLine("Fail to move to the position");
}
}

// Tidy up and exit
device.StopPolling();
device.Disconnect(true);
Console.WriteLine("Program finished");

// Uncomment this line if you are using Simulations
// SimulationManager.Instance.UninitializeSimulations();
Console.ReadKey();
}
}
}
33 changes: 33 additions & 0 deletions C#/Benchtop/UDXC/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;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UDXC CSharp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UDXC CSharp")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8a27c61f-7728-462f-9607-2628bdaaa99e")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
66 changes: 66 additions & 0 deletions C#/Benchtop/UDXC/UDXC CSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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>{8A27C61F-7728-462F-9607-2628BDAAA99E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>UDXC_CSharp</RootNamespace>
<AssemblyName>UDXC CSharp</AssemblyName>
<TargetFrameworkVersion>v4.7.2</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>
<Prefer32Bit>false</Prefer32Bit>
</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="Thorlabs.MotionControl.Benchtop.PiezoCLI, Version=1.14.56.25920, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\Thorlabs.MotionControl.Benchtop.PiezoCLI.dll</HintPath>
</Reference>
<Reference Include="Thorlabs.MotionControl.DeviceManagerCLI, Version=1.14.56.25920, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\Thorlabs.MotionControl.DeviceManagerCLI.dll</HintPath>
</Reference>
<Reference Include="Thorlabs.MotionControl.GenericPiezoCLI, Version=1.14.56.25920, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\Thorlabs.MotionControl.GenericPiezoCLI.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>
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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
13 changes: 13 additions & 0 deletions C#/Benchtop/UDXC/obj/Debug/UDXC CSharp.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\bin\Debug\UDXC CSharp.exe.config
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\bin\Debug\UDXC CSharp.exe
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\bin\Debug\UDXC CSharp.pdb
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\obj\Debug\UDXC CSharp.csproj.AssemblyReference.cache
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\obj\Debug\UDXC CSharp.csproj.CoreCompileInputs.cache
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\obj\Debug\UDXC CSharp.exe
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\obj\Debug\UDXC CSharp.pdb
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\bin\Debug\Thorlabs.MotionControl.PrivateInternal.dll
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\bin\Debug\Thorlabs.MotionControl.Tools.Common.dll
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\bin\Debug\Thorlabs.MotionControl.Tools.Logging.dll
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\bin\Debug\Thorlabs.MotionControl.Tools.WPF.dll
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\obj\Debug\UDXC CSharp.exe.config
C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\UDXC\UDXC CSharp\obj\Debug\UDXC CSh.3079E5E8.Up2Date
6 changes: 6 additions & 0 deletions C#/Benchtop/UDXC/obj/Debug/UDXC CSharp.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.7.2" />
</startup>
</configuration>
4 changes: 4 additions & 0 deletions C++/Benchtop/UDXC/Required DLLs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Thorlabs.MotionControl.DeviceManager.dll
Thorlabs.MotionControl.Benchtop.Piezo.dll
Thorlabs.MotionControl.Benchtop.Piezo.UDXC.h
Thorlabs.MotionControl.Benchtop.Piezo.lib
Loading