Problem with handles in GUI
Show older comments
Hi - I am having a problem with handles in guide. I have created a GUI to run some laboratory experiments and acquire data(maybe I should be using Simulink for this?).
In the gui I have created a timer object to schedule reading of the instruments. I have set up a instrument on opening the gui:
handles.controller1=visa('agilent','GPIB0::3::INSTR');
When the timer is triggered I would like to write a sequence of commands to the instrument through the callback function. Here is where the problem is as the visa object is not transferred through the handles when referenced, e.g.:
fwrite(handles.controller1, '63', 'uint8'); %UNL
On the other hand, if I don't try to write to the controller and just display the handles in the call back function to the command window the object is shown in the handles...??? [Using a script with a series of commands I am able to communicate with the instrument so I am confident that the code works].
Any assistance would be great!
Thanks
Answers (1)
Jan
on 6 Sep 2012
You have to provide the handles variable to the callback of the timer. E.g.:
set(TimerHandle, 'UserData', handles);
And then inside the callback:
function TimerCallback(ObjH, EventData)
handles = get(ObjH, 'UserData');
...
Another idea would to append handles as third input:
set(TimerH, 'TimerFcn', {@TimerCallback, handles});
Then the callback catches this as:
function TimerCallback(ObjH, EventData, handles)
Categories
Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!