Accessing an actxserver COM object with a GUI

조회 수: 9 (최근 30일)
Dmitry
Dmitry 2015년 1월 8일
댓글: Geoff Hayes 2018년 2월 6일
Hello,
I am trying to create a GUI that controls a third party program, which controls a camera.
I create the COM object as an activeX server as follows:
cameraHandle = actxserver('maxim.ccdcamera');
Now this object is in the workspace and I can interact with this object and make it do whatever I wish, no problem.
For example, the command for the camera to take a picture is:
invoke(cameraHandle,'Expose',exposureTime);
Now I would like to make one of the buttons in my GUI, do the same thing.
The code for the button is:
function buttonExpose_Callback(hObject, eventdata, handles)
% hObject handle to buttonExpose
% handles structure with handles and user data
% some commands here
How can I make this function act on the object cameraHandle?
Thanks!

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 1월 9일
Dmitry - if you wish to use the same code in your GUI, then instantiate the cameraHandle in the _OpeningFcn of the GUI, save it to the handles structure, and then reference it in your pushbutton code. Try the following
function myGui_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for untitled3
handles.output = hObject;
% create the COM object
handles.cameraHandle = actxserver('maxim.ccdcamera');
% Update handles structure
guidata(hObject, handles);
And then in your push button callback, just do
function buttonExpose_Callback(hObject, eventdata, handles)
exposureTime = 42;
invoke(handles.cameraHandle,'Expose',exposureTime);
Note that any callback that receives the handles structure as an input parameter, can reference the cameraHandles via
handles.cameraHandle
  댓글 수: 1
Dmitry
Dmitry 2015년 1월 9일
Geoff,
You're absolutely right. I was trying to figure out how to add the camera handle to the handles structure of the gui. This is the way to do that.
It works fine now. Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Abdur Rosyid
Abdur Rosyid 2018년 2월 3일
This is interesting. I also need to do the same task, but in AppDesigner. Furthermore, I need to call the object in different callbacks. How can I do this in AppDesigner? Thank you.
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2018년 2월 6일
Abdur - this is not an answer to the question so please delete and post as a comment or create a new question. Please provide sufficient details.

댓글을 달려면 로그인하십시오.

카테고리

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