Replacing actxcontrol with actxserver
Show older comments
Hi, I have a MATLAB script that communicates with multiple motor controllers. I used to use actxcontrol for this on R2022a, but due to this command no longer being supported by MATLAB as of R2025a, I am trying to switch over to using actxserver. The problem is that I get the error message 'Error: Catastrophic failure' whenever I try to send commands.
This is an example of the code using actxcontrol
ma = actxcontrol('MGMOTOR.MGMotorCtrl.1');
ma.StartCtrl;
where I get the warning
'Warning: ACTXCONTROL will be removed in a future release. For more information see UI Alternatives for MATLAB Apps on mathworks.com. '
This is an example of the code using actxserver
mb = actxserver('MGMOTOR.MGMotorCtrl.1');
mb.StartCtrl;
where I get the error
'Error using COM.MGMOTOR_MGMotorCtrl_1/StartCtrl
Error: Catastrophic failure'
I know actxserver isn't a 1 to 1 replacement for actxcontrol so I wanted to check if I'm missing a step in setting up the variable mb in order to be able to send commands.
Thank you very much!
1 Comment
Walter Roberson
about 2 hours ago
Google AI says,
MGMOTOR.MGMotorCtrl.1 cannot be controlled directly using actxserver in MATLAB. Attempting to instantiate it via MATLAB's actxserver function and calling StartCtrl triggers a Catastrophic failure (E_UNEXPECTED) because it is an ActiveX GUI control (.ocx) rather than a headless COM Automation server. [1, 2]
Why actxserver Fails
- UI Container Requirement. Thorlabs APT ActiveX controls (MGMOTOR.MGMotorCtrl.1) require a graphical window container (such as a MATLAB figure window) to initialize their internal message loop and UI threads before hardware commands can execute. [1, 2]
- Removal of actxcontrol. Because actxcontrol has been deprecated and removed in newer MATLAB releases (R2025a+), legacy scripts relying on APT ActiveX controls cannot simply swap actxcontrol for actxserver. [1]
Recommended Migration Paths
To control Thorlabs motion hardware in modern MATLAB versions without ActiveX errors, transition to one of Thorlabs' supported .NET or C APIs:
- Thorlabs Kinesis .NET API (Standard Replacement)
- Mechanism. Load the Kinesis .NET assemblies directly into MATLAB using NET.addAssembly instead of COM/ActiveX.
- Advantage. Runs completely headless (no figure window required), supports 64-bit MATLAB natively, and works across all modern MATLAB releases.
- Resources. Official MATLAB examples and class wrappers are available in the Thorlabs Motion Control Examples repository on GitHub (Thorlabs/Motion_Control_Examples) and the MATLAB Central File Exchange. [1, 2, 3]
- Thorlabs XA Software Platform (Long-Term Support)
- Mechanism. Thorlabs' newer cross-platform motion control suite (XA), which replaces Kinesis and legacy APT.
- Advantage. Provides thread-safe, language-agnostic C/C++ and .NET APIs (usable via MATLAB's loadlibrary or NET.addAssembly) with long-term support. [1, 2]
- Legacy Workaround (Older MATLAB Versions Only)
- If you are running a MATLAB version where actxcontrol still exists (R2024b or earlier), you must host the control inside an invisible or visible figure container: [1, 2]
f = figure('Visible', 'off');
h = actxcontrol('MGMOTOR.MGMotorCtrl.1', [0 0 300 200], f);
h.StartCtrl;
set(h, 'HWSerialNum', 12345678); % Replace with device serial number
h.Identify;
Answers (0)
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!