MATLAB Answers


Passing variable from event handler

Hi all,

I would be very grateful for help, advice or suggestion. I have an application to control geodetic instrument using synchoronous interface. However some commands are asynchronous by its nature, e.g. GetReflectors. After this command is triggered I receive as many server answers as is the number of available reflectors. So I have registered an COM event and associate handler function. So far so good. I can display the data coming but I do not know how to pass some variable to the main function. I tried to save variable as .mat file or in .txt file and read it. Actually it works in Matlab but it do not works in compiled .exe aplication (Error firing event). Even "disp" command do not work in compiled aplication (display nothing). So the main question is: how to pass variables from handler to main function. Is there a way?

Thank you very much


function pushbutton_GetReflectors_Callback(hObject, eventdata, handles) 
ltsync = actxserver ('LTControl.LTCommandSync2'); %Act as server: LTConnect2                          %List of all COM events
ltsync.registerevent({'ReflectorsData' 'ReflectorsHandler'}) %Register event
ltsync.GetReflectors()  %Ask instrument for reflectors
pause(3)                                                   %Time to receive answers
function ReflectorsHandler(varargin)    %Handler of the event ReflectorsData
disp('Reflector Data:');
disp(varargin{3})        %Reflector ID
disp(varargin{4})        %Reflector name 


2 Answers

Answer by Filip Dvoracek on 27 May 2013
 Accepted answer

OK, I will answer my question myself, hope this could help others. The problem was mainly in that there was not compiled file including event hadler in exe application. The file has to be named in the main script like %#function function_name to be properly included in compilation.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!