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

Passing variable from event handler

Asked by Filip Dvoracek on 17 May 2013

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

Filip

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

0 Comments

Filip Dvoracek

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.

0 Comments

Filip Dvoracek

Contact us