Hook MATLAB event listeners to TestLab events through Microsoft Automation (COM)

11 views (last 30 days)
Hey all,
I understand that this may be a bit specialised towards TestLab inner workings, but I believe it is worth asking.
I’ve been trying to implement some kind of acquisition with TestLab controlled through MATLAB. I would like to automate the whole process (MATLAB will handle the automated movement of some system components), and I decided to go with Microsoft’s Automation framework.
I’m still at the first steps of the process development, and I’ve been experimenting with some very simple examples. I’ve been trying to hook a MATLAB function to some TestLab DataWatches. Specifically, I’ve tried the “ValueChanged” event of the “Active Section” and "Active Sheet” watches, but apparently, I am doing something wrong and the events are not triggered in MATLAB.
Below is a very simple code snippet I’ve been using.
tl = actxserver("LMSTestLabAutomation.Application"); % Get a TestLab application object
asw = tl.ActiveBook.ActiveSectionWatch; % Get the active section watch -- NOT SURE THIS IS CORRECT, I MAY HAVE TO USE THE FindDataWatch OF THE ActiveBook
asw.registerevent({"ValueChanged", @letmeknow}); % Hook the event handler to call letmeknow(varargin) defined in a different .m file -- as "instructed" by MATLAB's documentation --- This works with Excel!
Unfortunately, the function letmeknow() is never called when I change the active section (I have created some and change through them). To check whether MATLAB “knows about” the changes, I have used
inspect(asw);
which opens a GUI with the properties of the ActiveSectionWatch, and the Data and AsyncData are updated correctly (at the specified update interval - given at the “UpdateFrequency” property value). That means that MATLAB can get notified of the changes happening in TestLab, but obviously, I am doing something wrong.
I assume that I do not register the events correctly in MATLAB. I am somewhat sceptical as to whether I should use the ActiveSectionWatch object or I should acquire a Watch object through the FindDataWatch function of (in this example) ActiveBook. I haven’t tested that because I haven’t managed to open the .tlb file of the documentation to look for the appropriate Port names to pass to the FindDataWatch, due to restrictions in the available software running on the computer with TestLab and the move of data (the .tlb file that is) out of the computer.
I would appreciate your help or any ideas I could test.
Best to all.

Accepted Answer

Satyam
Satyam on 18 Nov 2025
MATLAB does not support asynchronous COM events and does not support interface events from a Custom server. Many Simcenter Testlab “DataWatch” notifications (e.g., ValueChanged) are exposed through custom/event interfaces that MATLAB’s COM client cannot sink, hence the callback never runs even though you can see the watch values change via inspect. https://www.mathworks.com/help/matlab/matlab_external/com-events.html
You can try polling the DataWatch using a MATLAB timer or create a lightweight .NET component that would subscribe to Testlab events (which .NET supports) and then forward those notifications to MATLAB.
I hope it helps.
  1 Comment
Achilles
Achilles on 20 Nov 2025 at 8:01
Hello @Satyam,
Thanks a bunch for the response. This does indeed help and I have verified it with the Siemens people. It is quite unfortunate that this is the case, but I guess it is what it is.
We'll look for alternatives for our application then. Your clarification is highly appreciated.
Kind regards,
Achilles.

Sign in to comment.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!