how to keep SCPI instrument open from GUI?

1 view (last 30 days)
Christoph
Christoph on 26 Jan 2016
Answered: Walter Roberson on 26 Jan 2016
Dear all!
I am using the "Test & Measurement Tool" App to send and receive SCPI commands in combination with a temperature controller (Oxford Instruments Mercury iTC). Works like a charm (since I am mostly just setting/reading temperature), but I want to build a small GUI so that later I can program conveniently some temperature protocols and plot them etc.
unfortunately I am totally not familiar with GUIs even though I have worked with Matlab for over 5 years now. (shame on me).
So I am looking at the Session log and trying to figure out how to work but the problem is that the system keeps closing the connection every time after I am pushing the main (connect) button. So I cannot execute any other command. Further the handles object which contains the connection to COM7 seems to not be shared with other functions in the same gui.
from the session log I found the connection is established as follows:
% Find a serial port object.
obj1 = instrfind('Type', 'serial', 'Port', 'COM7', 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial('COM7');
else
fclose(obj1);
obj1 = obj1(1)
end
% Disconnect from instrument object, obj1.
fclose(obj1);
% Connect to instrument object, obj1.
fopen(obj1);
And I put this in the pushbutton,
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Find a serial port object.
handles.obj1 = instrfind('Type', 'serial', 'Port', 'COM7', 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(handles.obj1)
handles.obj1 = serial('COM7');
else
fclose(handles.obj1);
handles.obj1 = handles.obj1(1)
end
% Connect to instrument object, obj1.
fopen(handles.obj1);
status1 = query(handles.obj1, 'READ:SYS:CAT?');
set(handles.text2, 'String', status1)
ReadTemp = query(handles.obj1, 'READ:DEV:MB1.T1:TEMP:SIG:TEMP?');
set(handles.text5, 'String', ReadTemp(31:end))
then the field I am writing to is updated (correctly), but the connection seems to close because when I am trying to update using another pushbutton the object is gone. It might live in a different workspace but I think the handles are shared in all (?).
can someone help me to establish a persistent connection and how to read the temperature value let's say every 1 min?
Any help is greatly appreciated!
Yours, Chris

Answers (1)

Walter Roberson
Walter Roberson on 26 Jan 2016
After you assign to handles use
guidata(hObject, handles)

Community Treasure Hunt

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

Start Hunting!