Using .dll from Thorlabs to communicate with the motors

125 views (last 30 days)
Hi all,
we are struggling to use .dll files provided by Kinesis software in Thorlabs Inc., to make connection to the motors.
(Originally, our matlab programs were based on actxcontrol functions,
but we're now switching to .Net-based system, as MATLAB is not willing to support the function anymore)
Referring to other codes in online, we executed following codes:
% Load .dll files associated with the Thorlabs motor
asm1 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.DeviceManagerCLI.dll');
asm2 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.GenericMotorCLI.dll');
asm3 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\ThorLabs.MotionControl.KCube.DCServoCLI.dll');
% Generate device list
deviceList = Thorlabs.MotionControl.DeviceManagerCLI.DeviceManagerCLI.GetDeviceList;
% Make a connection to the DC motor of serial number '27500135'
test = Thorlabs.MotionControl.KCube.DCServoCLI.KCubeDCServo.CreateKCubeDCServo('27500135')
Then, at the last line, this code always ends up with a crash, failing to make a handle object for the motor.
Is there anyone who can give us advice for resolving the problem?
If additional information is needed to figure out the issue, please let us know.
FYI, the crash log is :
MATLAB Log File: C:\Users\SSSG\AppData\Local\Temp\matlab_crash_dump.12140-1
Unknown exception 0xe0434352 detected at 2021-04-23 17:40:25 +0900
Crash Decoding : Disabled - No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : windows-1252
Deployed : false
Graphics Driver : Unknown hardware
Graphics card 1 : Microsoft ( 0x0 ) Microsoft Remote Display Adapter Version 10.0.18362.693 (2006-6-21)
Graphics card 2 : Intel Corporation ( 0x8086 ) Intel(R) HD Graphics 630 Version (2016-10-7)
Java Version : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Architecture : win64
MATLAB Entitlement ID : 2262836
MATLAB Root : C:\Program Files\MATLAB\R2021a
MATLAB Version : (R2021a)
OpenGL : hardware
Operating System : Microsoft Windows 10 Education
Process ID : 12140
Processor ID : x86 Family 6 Model 158 Stepping 9, GenuineIntel
Session Key : 4005d758-a860-440a-a913-5a7b1d20e311
Window System : Version 10.0 (Build 18363)
Fault Count: 1
Abnormal termination:
Unknown exception 0xe0434352
Current Thread: 'MCR 0 interpreter thread' id 13100
Register State (from fault):
RAX = 0000004d704f8ef8 RBX = 00000000e0434352
RCX = 0000004d704f8ca0 RDX = 0000004d704f8d08
RSP = 0000004d704f93b0 RBP = 0000004d704f9640
RSI = 0000000000000001 RDI = 0000000000000005
R8 = 0000000000000000 R9 = 0000004d704f8d30
R10 = 000001e38bab2d00 R11 = 0000000000000000
R12 = 0000000000004000 R13 = 00007ffe31461200
R14 = 0000004d704f9548 R15 = 00007ffe7455f808
RIP = 00007ffe83263b19 EFL = 00000202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (from fault):
[ 0] 0x00007ffe83263b19 C:\WINDOWS\System32\KERNELBASE.dll+00277273 RaiseException+00000105
[ 1] 0x00007ffe73eff6b1 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll+01504945 MetaDataGetDispenser+00178033
[ 2] 0x00007ffe73f8a6dd C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll+02074333 StrongNameSignatureVerification+00020941
[ 3] 0x00007ffe73f8a783 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll+02074499 StrongNameSignatureVerification+00021107
[ 4] 0x00007ffe73f8a790 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll+02074512 StrongNameSignatureVerification+00021120
[ 5] 0x00007ffe743d7081 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll+06582401 TranslateSecurityAttributes+01928065
[ 6] 0x00007ffe74127d50 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll+03767632 NGenCreateNGenWorker+00474496
[ 7] 0x00007ffe70b1d90d C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\mscorlib\fa77f3773e7347d73b54c65ccbb4ba62\
[ 8] 0x00007ffe70b351f2 C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\mscorlib\fa77f3773e7347d73b54c65ccbb4ba62\
[ 9] 0x00007ffe70b350d3 C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\mscorlib\fa77f3773e7347d73b54c65ccbb4ba62\
[ 10] 0x00007ffe315111bd <unknown-module>+00000000
[ 11] 0x000001e3985b3c30 <unknown-module>+00000000
[ 12] 0x000001e39877ad90 <unknown-module>+00000000
[ 13] 0x0000004d704f9ec0 <unknown-module>+00000000
[ 14] 0x00007ffe315110db <unknown-module>+00000000
[ 15] 0x000001e3ce270000 <unknown-module>+00000000
[ 16] 0x00007ffe31298690 <unknown-module>+00000000
[ 17] 0x00007ffe311de9a0 <unknown-module>+00000000
[ 18] 0x00007ffe73ef965b C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll+01480283 MetaDataGetDispenser+00153371
[ 19] 0x00007ffe74383fa9 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll+06242217 TranslateSecurityAttributes+01587881
[ 20] 0x90ca81d8e48a06ea <unknown-module>+00000000
[ 21] 0x000001e39883a370 <unknown-module>+00000000
[ 22] 0x00007ffe82e114cb C:\WINDOWS\System32\ucrtbase.dll+00070859 free_base+00000027
[ 23] 0x7374696d694c726f <unknown-module>+00000000

Accepted Answer

Carlo Vinchi
Carlo Vinchi on 4 May 2022
Edited: Carlo Vinchi on 4 May 2022
Hi Hoon,
we just wanted to let you know that we found the problem. Thanks again for your replies!
The problem was that we did not write the semicolon sign ( ";" ) at the end of the problematic line of code (as you did your code, but we didnt realize that this might be the problem) . However, now it works...
In the following you can find the code that works for us. Maybe this is helpful for other people who are facing the same problem.
clear all;
MOTORPATHDEFAULT = 'C:\Program Files\Thorlabs\Kinesis\';
import Thorlabs.MotionControl.DeviceManagerCLI.*
import Thorlabs.MotionControl.GenericMotorCLI.*
import Thorlabs.MotionControl.KCube.StepperMotorCLI.*
import Thorlabs.MotionControl.GenericMotorCLI.KCubeMotor.*
import Thorlabs.MotionControl.GenericMotorCLI.Settings.*
% Initialize Device List
Thorlabs.MotionControl.DeviceManagerCLI.DeviceManagerCLI.BuildDeviceList() % Build device list
serialNumbersNet = Thorlabs.MotionControl.DeviceManagerCLI.DeviceManagerCLI.GetDeviceList() % Get device list
serialNumbers = cell(ToArray(serialNumbersNet)) % Convert serial numbers to cell array
serial_no = serialNumbers{1} % shows correct serial number ('26004231')
deviceNET = KCubeStepper.CreateKCubeStepper(serial_no);
After this you can enable the device by calling deviceNet.EnableDevice().
Best regards,
  1 Comment
Hoon Kim
Hoon Kim on 6 May 2022
Hi Carlo,
thank you for sharing the solution! I'm happy to hear that you also resolved the problem finally.
It must be helpful for other MATLAB users who are looking for an alternative to actxcontrol in communicating with Thorlab devices.
Best regards,

Sign in to comment.

More Answers (1)

Carlo Vinchi
Carlo Vinchi on 2 May 2022
Hi Hoon Kim,
we are struggling with a similar problem.
We are trying to connect another Thorlabs motor (stepper motor ZFS25B).
MATLAB always crashes at the same line as your code does.
test = Thorlabs.MotionControl.KCube.StepperMotorCLI.KCubeStepper.CreateKCubeStepper(serial_no)
Did you find a solution for this problem so far?
Best regards,
Hoon Kim
Hoon Kim on 2 May 2022
Hi Carlo,
it's sorry to hear that the import-commands cannot solve the problem.
please refer to our code below -
asm1 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.DeviceManagerCLI.dll');
asm2 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.GenericMotorCLI.dll');
asm3 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\ThorLabs.MotionControl.KCube.DCServoCLI.dll');
asm4 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\ThorLabs.MotionControl.Tools.Common.dll');
asm5 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\ThorLabs.MotionControl.Tools.Logging.dll');
asm6 = NET.addAssembly('C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.PrivateInternal.dll');
import Thorlabs.MotionControl.DeviceManagerCLI.*
import Thorlabs.MotionControl.GenericMotorCLI.*
import Thorlabs.MotionControl.KCube.DCServoCLI.*
device = Thorlabs.MotionControl.KCube.DCServoCLI.KCubeDCServo.CreateKCubeDCServo(serialNo);
It is more or less similar to your code given above.
Just to make sure, I guess you're already aware of the fact that 'serial_no' should be given as a character array, for example '27502481'.
In our code, we make users typing the serial number of devices, instead of loading it via 'GetDeviceList()' function.
Best regards
Raha on 14 Feb 2023
I am using a BBD 200 series, what s the code to connect using a BBD onstead of KCube:
device = Thorlabs.MotionControl.KCube.DCServoCLI.KCubeDCServo.CreateKCubeDCServo(serialNo);

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!