Why can I not access some COM objects in Matlab that are available from a VB script?

조회 수: 2 (최근 30일)
I have a VB script which sucessfully accesses objects and methods in Vector CANalyzer - the gist of the code is:
Set App = CreateObject("CANalyzer.Application")
App.Open (PathConfig & "Easy.cfg")
Set Logging = App.Configuration.OnlineSetup.LoggingCollection(1)
Set Exporter = Logging.Exporter
With Exporter.Sources
.Clear
.Add (src_file)
End With
Exporter.Load
Exporter.Save True
But when I try the same operation in Matlab, I don't seem to be able to access the 'Exporter' object - I can only get as far as the
'LoggingCollection' object, which I can call methods from.
app = actxserver('CANalyzer.Application');
logging = app.Application.Configuration.OnlineSetup.LoggingCollection;
invoke(logging)
test = Add(logging);
Quit(app);
delete(app);
I've tried following the advice on this thread, trying to access objects and methods even though they're not visible, but this doesn't work either. i.e.
testValue = get(app.Application.Configuration.OnlineSetup.LoggingCollection.Logging, 'FullName');
Returns error: 'No appropriate method, property or field Logging for class Interface.413... etc...
Am I setting up the COM server incorrectly, or is this a peculiarity of the program I'm accessing? Is there any way to solve this problem?
Many thanks,
Tom

채택된 답변

Tom Hillman
Tom Hillman 2015년 3월 27일
I've managed to sort this out - the problem was that the LoggingCollection object technically was a group of objects, even though there was only one of them. Using an invoke command to return the handle of item 1 in this group seems to work.
The code below uses Canalyzer to convert .asc files to .mat files...
% This script allows matlab to control the conversion of Canalyzer .asc files to matlab .mat files
%Opens COM server - best to already have Canalyzer running with the correct configuration open
app = actxserver('CANalyzer.Application');
Get handle of logging collection object
logging = app.Application.Configuration.OnlineSetup.LoggingCollection;
% Select first logging block
export1 = invoke(logging, 'Item', 1);
% clear sources and write new source
invoke(export1.exporter.sources, 'Clear');
invoke(export1.exporter.sources, 'Add', 'C:\test.ASC');
% clear destinations and write new destination
invoke(export1.exporter.destinations, 'Clear');
invoke(export1.exporter.destinations, 'Add', 'C:\test.mat');
invoke(export1.exporter,'Load')
invoke(export1.exporter,'Save','True')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by