diff --git a/C#/KCube/KPC101/App.config b/C#/KCube/KPC101/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/C#/KCube/KPC101/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/C#/KCube/KPC101/KPC101_Example.csproj b/C#/KCube/KPC101/KPC101_Example.csproj new file mode 100644 index 0000000..c5d6b9d --- /dev/null +++ b/C#/KCube/KPC101/KPC101_Example.csproj @@ -0,0 +1,85 @@ + + + + + Debug + AnyCPU + {D5ED37A5-9897-42C6-8878-DFB422D01E86} + Exe + KPC101_Example + KPC101_Example + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + true + + + + + + + + + + + + False + bin\x64\Debug\Thorlabs.MotionControl.DeviceManagerCLI.dll + + + False + bin\x64\Debug\Thorlabs.MotionControl.GenericPiezoCLI.dll + + + False + bin\x64\Debug\Thorlabs.MotionControl.KCube.PiezoStrainGaugeCLI.dll + + + + + + + + + + + \ No newline at end of file diff --git a/C#/KCube/KPC101/Program.cs b/C#/KCube/KPC101/Program.cs new file mode 100644 index 0000000..c3e1e8b --- /dev/null +++ b/C#/KCube/KPC101/Program.cs @@ -0,0 +1,156 @@ +// Title: KDC101_Example +// Created Date: 03/05/2026 +// Last Modified Date: 03/05/2023 +// .NET Framework version: 4.8 +// Thorlabs DLL version: 1.14.59 +// Example Description: +// This example demonstrates how to set-up the communication for the Thorlabs +// KPC101 controllers. +using System; +using System.Collections.Generic; +using System.Threading; +using Thorlabs.MotionControl.DeviceManagerCLI; +using Thorlabs.MotionControl.GenericPiezoCLI.Piezo; +using Thorlabs.MotionControl.KCube.PiezoStrainGaugeCLI; + + + +namespace KCP_CStest +{ + internal class Program + { + + static void Main() + { + //SimulationManager.Instance.InitializeSimulations(); Uncomment for simulated device. + + // Get the test KPC101 serial number (e.g. 113000123) + string serialNo = "113000001"; + + 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 KCube Piezo Strain Gauge Motors and check our serial number is correct - by using the device prefix + // (i.e. for serial number 113000123, the device prefix is 113) + List serialNumbers = DeviceManagerCLI.GetDeviceList(KCubePiezoStrainGauge.DevicePrefix); + if (!serialNumbers.Contains(serialNo)) + { + // The requested serial number is not a KPC101 or is not connected + Console.WriteLine("{0} is not a valid serial number", serialNo); + Console.ReadKey(); + return; + } + + // Create the KCZ device + KCubePiezoStrainGauge device = KCubePiezoStrainGauge.CreateKCubePiezoStrainGauge(serialNo); + if (device == null) + { + // An error occured + Console.WriteLine("{0} is not a KCubePiezoStrainGauge", 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"); + } + } + + // 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(250); + // Needs a delay so that the current enabled state can be obtained + Thread.Sleep(500); + // Enable the channel otherwise any move is ignored + device.EnableDevice(); + // Needs a delay to give time for the device to be enabled + Thread.Sleep(500); + + // Get Piezo configuration + PiezoConfiguration piezoConfiguration = device.GetPiezoConfiguration(serialNo); + // Not used directly in example but illustrates how to obtain device settings + PiezoDeviceSettings currentDeviceSettings = device.PiezoDeviceSettings as PiezoDeviceSettings; + + // Display info about device + DeviceInfo deviceInfo = device.GetDeviceInfo(); + Console.WriteLine("Device {0} = {1}", deviceInfo.SerialNumber, deviceInfo.Name); + + device.SetPositionControlMode(PiezoControlModeTypes.OpenLoop); + + // Max voltage - 75 + Decimal maxVolts = device.GetMaxOutputVoltage(); + + Decimal voltage = 1; + // If a voltage is requested + if ((voltage != 0) && (voltage <= maxVolts)) + { + // Update voltage if required using real world methods + device.SetOutputVoltage(voltage); + + Thread.Sleep(1000); + + Decimal newVolts = device.GetOutputVoltage(); + Console.WriteLine("Voltage set to {0}", newVolts); + } + + Console.WriteLine("Setting Zero"); + device.SetZero(); + Thread.Sleep(1000); + Console.WriteLine("Voltage:{0}", device.GetOutputVoltage()); + Console.WriteLine("Position:{0}", device.GetPosition()); + + device.SetPositionControlMode(PiezoControlModeTypes.CloseLoop); + + + //Set position + Decimal setposition = 1.5m; + device.SetPosition(setposition); + + Thread.Sleep(1000); + + Decimal position = device.GetPosition(); + Console.WriteLine("New Position {0}", position); + + + device.StopPolling(); + + device.Disconnect(true); + Console.WriteLine("Device disconnected"); + //SimulationManager.Instance.UninitializeSimulations(); uncomment for simulated device. + + Console.ReadKey(); + } + } +} diff --git a/C#/KCube/KPC101/Properties/AssemblyInfo.cs b/C#/KCube/KPC101/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d1eff41 --- /dev/null +++ b/C#/KCube/KPC101/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("KPC101_Example")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("DCHSCCM01")] +[assembly: AssemblyProduct("KPC101_Example")] +[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("d5ed37a5-9897-42c6-8878-dfb422d01e86")] + +// 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#/KCube/KPC101/bin/x64/Debug/KPC101_Example.exe.config b/C#/KCube/KPC101/bin/x64/Debug/KPC101_Example.exe.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/C#/KCube/KPC101/bin/x64/Debug/KPC101_Example.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/C#/KCube/KPC101/obj/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs b/C#/KCube/KPC101/obj/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs new file mode 100644 index 0000000..15efebf --- /dev/null +++ b/C#/KCube/KPC101/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#/KCube/KPC101/obj/x64/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs b/C#/KCube/KPC101/obj/x64/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs new file mode 100644 index 0000000..15efebf --- /dev/null +++ b/C#/KCube/KPC101/obj/x64/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#/KCube/KPC101/obj/x64/Debug/KPC101_Example.csproj.FileListAbsolute.txt b/C#/KCube/KPC101/obj/x64/Debug/KPC101_Example.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..f594ac2 --- /dev/null +++ b/C#/KCube/KPC101/obj/x64/Debug/KPC101_Example.csproj.FileListAbsolute.txt @@ -0,0 +1,13 @@ +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\obj\x64\Debug\KPC101_Example.csproj.AssemblyReference.cache +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\obj\x64\Debug\KPC101_Example.csproj.CoreCompileInputs.cache +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\bin\x64\Debug\KPC101_Example.exe.config +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\bin\x64\Debug\KPC101_Example.exe +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\bin\x64\Debug\KPC101_Example.pdb +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\bin\x64\Debug\Thorlabs.MotionControl.PrivateInternal.dll +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\bin\x64\Debug\Thorlabs.MotionControl.Tools.Common.dll +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\bin\x64\Debug\Thorlabs.MotionControl.Tools.Logging.dll +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\bin\x64\Debug\Thorlabs.MotionControl.Tools.WPF.dll +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\obj\x64\Debug\KPC101_E.4EEB1B3A.Up2Date +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\obj\x64\Debug\KPC101_Example.exe +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\obj\x64\Debug\KPC101_Example.pdb +C:\Users\gboedecker\source\repos\KPC101\KPC101_Example\KPC101_Example\obj\x64\Debug\KPC101_Example.exe.config diff --git a/C#/KCube/KPC101/obj/x64/Debug/KPC101_Example.exe.config b/C#/KCube/KPC101/obj/x64/Debug/KPC101_Example.exe.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/C#/KCube/KPC101/obj/x64/Debug/KPC101_Example.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/C#/XA/BBD30X/App.config b/C#/XA/BBD30X/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/C#/XA/BBD30X/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/C#/XA/BBD30X/BBD30X.csproj b/C#/XA/BBD30X/BBD30X.csproj new file mode 100644 index 0000000..20fbafa --- /dev/null +++ b/C#/XA/BBD30X/BBD30X.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {6F6540DC-4ED9-4D48-BE55-32A5AB2A7A1F} + Exe + BBD303 + BBD303 + v4.8 + 512 + true + true + + + x64 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + ..\..\..\..\..\..\..\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/BBD30X/Program.cs b/C#/XA/BBD30X/Program.cs new file mode 100644 index 0000000..c811852 --- /dev/null +++ b/C#/XA/BBD30X/Program.cs @@ -0,0 +1,181 @@ +// Title: BBD30X +// Created Date: 03/09/2026 +// Last Modified Date: 03/09/2026 +// .NET FrameworF version: 4.8 +// Thorlabs DLL version: 1.5.0.26490 +// Example Description: +// This example demonstrates how to set-up the communication for the Thorlabs +// BBD30X controllers, home it, and move it by 1 mm or degrees. + +using System; +using Thorlabs.MotionControl.XA; +using Thorlabs.MotionControl.XA.Products; + +namespace BBD30X +{ + class Program + { + //Change this line to match the serial number on your device (format: 103XXXXXX) + private static string _deviceId = "103000001"; + //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; + } + + //Uncomment this part(and systemManager.RemoveSimulation(bbd303Simulation) at the end on Main) + //If you are using a simulated device + /* + string bbd303Simulation = @"{ + ""PartNumber"": ""BBD303"", + ""SerialNumber"": ""103000001"", + ""Channels"": + [{ ""BayNumber"": ""1"", + ""SerialNumber"": ""104000002"", + ""ActuatorType"": ""DDS220""}, + { + ""BayNumber"": ""2"", + ""SerialNumber"": ""104000003"", + ""ActuatorType"": ""DDS300""}, + { + ""BayNumber"": ""3"", + ""SerialNumber"": ""104000004"", + ""ActuatorType"": ""DDS600""}]}"; + + systemManager.CreateSimulation(bbd303Simulation); + */ + + //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) + { + 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() ?? ""); + } + + index++; + } + } + else + { + Console.WriteLine("No devices found."); + } + + //Open the BBD30X device + Bbd30x 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 + Bbd30xLogicalChannel channel; + 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); + + //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(); + } + + //Uncomment this line if you are using Simulations + //systemManager.RemoveSimulation(bbd303Simulation); + + //Shutdown XA + systemManager.Shutdown(); + + } + } + } +} \ No newline at end of file diff --git a/C#/XA/BBD30X/Properties/AssemblyInfo.cs b/C#/XA/BBD30X/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..13774a1 --- /dev/null +++ b/C#/XA/BBD30X/Properties/AssemblyInfo.cs @@ -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("BBD303")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BBD303")] +[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("6f6540dc-4ed9-4d48-be55-32a5ab2a7a1f")] + +// 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")] diff --git a/C#/XA/BBD30X/obj/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs b/C#/XA/BBD30X/obj/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs new file mode 100644 index 0000000..15efebf --- /dev/null +++ b/C#/XA/BBD30X/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/BBD30X/obj/Debug/BBD303.exe.config b/C#/XA/BBD30X/obj/Debug/BBD303.exe.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/C#/XA/BBD30X/obj/Debug/BBD303.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/C#/XA/BBD30X/obj/Debug/BBD30X.csproj.FileListAbsolute.txt b/C#/XA/BBD30X/obj/Debug/BBD30X.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..385be33 --- /dev/null +++ b/C#/XA/BBD30X/obj/Debug/BBD30X.csproj.FileListAbsolute.txt @@ -0,0 +1,10 @@ +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\bin\Debug\BBD303.exe.config +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\bin\Debug\BBD303.exe +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\bin\Debug\BBD303.pdb +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\bin\Debug\tlmc_xa_dotnet.dll +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\obj\Debug\BBD30X.csproj.AssemblyReference.cache +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\obj\Debug\BBD30X.csproj.CoreCompileInputs.cache +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\obj\Debug\BBD30X.csproj.Up2Date +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\obj\Debug\BBD303.exe +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\obj\Debug\BBD303.pdb +C:\Users\zizhang\OneDrive - THORLABS Inc\Documents\4. SW Project\BBD303 Csharp XA\BBD303\obj\Debug\BBD303.exe.config diff --git a/C#/XA/BBD30X/obj/Debug/BBD30X.csproj.Up2Date b/C#/XA/BBD30X/obj/Debug/BBD30X.csproj.Up2Date new file mode 100644 index 0000000..e69de29