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#/XA/UMCx/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>
159 changes: 159 additions & 0 deletions C#/XA/UMCx/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Title: UMCX
// Created Date: 23/06/2026
// Last Modified Date: 23/06/2026
// .NET Framework version: 4.7.2
// Thorlabs DLL version: 1.6.8.27431
// Example Description:
// This example demonstrates how to set-up the communication for the Thorlabs
// UMCX controllers with a brushless stage, home it, and move it by 1 mm or degrees.

using System;
using System.Threading;
using Thorlabs.MotionControl.XA;
using Thorlabs.MotionControl.XA.Products;

namespace UMC.net_testing
{
class Program
{
//Change this line to match the serial number on your device (format: 121XXXXXX)
private static string _deviceId = "121000020";
//Select the channel to control ("1", "2", or "3")
private static string _channelNumber = "1";

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)
{
int index = 1;

foreach (var d in devicelist)
{
Console.Write("Device {0}: ", index);
try
{
Console.WriteLine("{0}, Serial Number: {1}", d.DeviceType, d.Device);

}
catch
{
Console.WriteLine(d?.ToString() ?? "<null device>");
}

index++;
}
}
else
{
Console.WriteLine("No devices found.");
}

//Open the UMCx device
Umcx device;
bool ret = systemManager.TryOpenDevice(_deviceId, "", OperatingModes.Default, out device);
if (ret == false)
{
Console.WriteLine("\nFail to open base unit {0}", _deviceId);
systemManager.Shutdown();
return;
}
else
{
Console.WriteLine("\nBase Unit {0} opened successfully", _deviceId);
}

//Open the channel
UmcxBrushlessLogicalChannel channel; //Make sure to choose the correct stage type for the channel, i.e. UmcxBrushlessLogicalChannel or UmcxStepperLogicalChannel
string _channelId = _deviceId + "-" + _channelNumber;
ret = systemManager.TryOpenDevice(_channelId, "", OperatingModes.Default, out channel);
if (ret == false)
{
Console.WriteLine("Fail to open channel {0}", channel.DeviceId);
systemManager.Shutdown();
return;
}
else
{
Console.WriteLine("Channel {0} opened successfully", channel.DeviceId);
}

try
{
//Enable the device
channel.SetEnableState(EnableState.Enabled, TimeSpan.FromSeconds(1));

//Get the stage information
ConnectedProductInfo connectedProductInfo = channel.GetConnectedProductInfo();
Console.WriteLine("Channel {0} Stage Name:{1}", channel.DeviceId, connectedProductInfo.ProductName);

//Home the device
Console.WriteLine("Homing");
channel.Home(TimeSpan.FromSeconds(60));
Console.WriteLine("Home completed");

//Set the distance. Unit: millimeters or degrees depending on the actuator
double distance = 1;

//Get the unit type of the actuator
Unit deviceUnit = connectedProductInfo.UnitType;

//Convert the distance to device unit
long posInDeviceUnits = channel.FromPhysicalToDeviceUnit(ScaleType.Distance, deviceUnit, distance);
Thread.Sleep(500);

//Move the device
Console.WriteLine("Moving to {0} {1}", distance, deviceUnit.ToString());
channel.Move(MoveMode.Absolute, (int)posInDeviceUnits, TimeSpan.FromSeconds(60));
Console.WriteLine("Move completed");

//Get the current position
int currentPosInDeviceUnits = channel.GetPositionCounter(TimeSpan.FromSeconds(1));

//Convert the device unit to physical unit
UnitConversionResult currentPos = channel.FromDeviceUnitToPhysical(ScaleType.Distance, currentPosInDeviceUnits);
Console.WriteLine("Current Position: {0} {1}", currentPos.Value, currentPos.UnitType);
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}", ex.Message);
}
finally
{
//Close the channel
if (channel != null)
channel.Close();

//Close the device
if (device != null)
{
device.Disconnect();
device.Close();
}

//Shutdown XA
systemManager.Shutdown();

}
}
}
}
36 changes: 36 additions & 0 deletions C#/XA/UMCx/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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("UMC .net testing")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UMC .net testing")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[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("12c10132-4d7d-4940-a749-b41cee252bb6")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
77 changes: 77 additions & 0 deletions C#/XA/UMCx/UMCx.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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>{12C10132-4D7D-4940-A749-B41CEE252BB6}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>UMC.net_testing</RootNamespace>
<AssemblyName>UMC.net_testing</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</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>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</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.6.8.27431, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\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>
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")]
9 changes: 9 additions & 0 deletions C#/XA/UMCx/obj/Debug/UMCx.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
C:\Users\cstroud\source\repos\UMC .net testing\obj\x64\Debug\UMC .net testing.csproj.AssemblyReference.cache
C:\Users\cstroud\source\repos\UMC .net testing\obj\x64\Debug\UMC .net testing.csproj.CoreCompileInputs.cache
C:\Users\cstroud\source\repos\UMC .net testing\bin\x64\Debug\UMC.net_testing.exe.config
C:\Users\cstroud\source\repos\UMC .net testing\bin\x64\Debug\UMC.net_testing.exe
C:\Users\cstroud\source\repos\UMC .net testing\bin\x64\Debug\UMC.net_testing.pdb
C:\Users\cstroud\source\repos\UMC .net testing\bin\x64\Debug\tlmc_xa_dotnet.dll
C:\Users\cstroud\source\repos\UMC .net testing\obj\x64\Debug\UMC .net testing.csproj.CopyComplete
C:\Users\cstroud\source\repos\UMC .net testing\obj\x64\Debug\UMC.net_testing.exe
C:\Users\cstroud\source\repos\UMC .net testing\obj\x64\Debug\UMC.net_testing.pdb
6 changes: 6 additions & 0 deletions C#/XA/UMCx/obj/Debug/UMCx.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>
Loading