📄 stagegui.m
字号:
function varargout = StageGUI(varargin)
% STAGEGUI M-file for StageGUI.fig
% Opens a window to control the posistion of the stage, and disable the
% joystick.
% STAGEGUI, by itself, creates a new STAGEGUI or raises the existing
% singleton*.
%
% H = STAGEGUI returns the handle to a new STAGEGUI or the handle to
% the existing singleton*.
%
% STAGEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in STAGEGUI.M with the given input arguments.
%
% STAGEGUI('Property','Value',...) creates a new STAGEGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before StageGUI_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to StageGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help StageGUI
% Last Modified by GUIDE v2.5 18-May-2004 11:54:59
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @StageGUI_OpeningFcn, ...
'gui_OutputFcn', @StageGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes just before StageGUI is made visible.
function StageGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to StageGUI (see VARARGIN)
% Choose default command line output for StageGUI
handles.output = hObject;
% Read intput variable:
% Handle of the Main window
handles.Main=varargin{1};
% Load parameters from the Main window
Main_handles=guidata(handles.Main);
% Port COM
handles.PCOM=Main_handles.SStage;
% Step
handles.ValStep=Main_handles.Step;
set(handles.Step,'String',sprintf('%.1f',Main_handles.Step))
% Unable joystick
fprintf(handles.PCOM,'2ex;1mo');
% Locate the window
set(hObject,'Position',[Main_handles.LocStaGUI, 250, 170]);
% Update handles structure
guidata(hObject, handles);
% Update position
Position_Update(handles);
% UIWAIT makes StageGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Outputs from this function are returned to the command line.
function varargout = StageGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes when user attempts to close StageCTL.
function StageCTL_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to StageCTL (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Enable the joystick
fprintf(handles.PCOM,'1ex');
% Hint: delete(hObject) closes the figure
delete(hObject);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes during object creation, after setting all properties.
function Position_CreateFcn(hObject, eventdata, handles)
% hObject handle to Position (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Position_Update(handles)
% handles structure with handles and user data (see GUIDATA)
% Update position
fprintf(handles.PCOM,'1tp');
pause(0.2);
PosC=char(fread(handles.PCOM,handles.PCOM.BytesAvailable,'uint8')');
% Notice the negative sign, because the motor is upside-down
PosN=-round(str2num(PosC)*10000)/10;
set(handles.Position,'String',sprintf('%.1f',PosN));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over Position.
function Position_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to Position (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Update position
Position_Update(handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in RST.
function RST_Callback(hObject, eventdata, handles)
% hObject handle to RST (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Define the zero point in the scale as the current position
fprintf(handles.PCOM,'1dh');
pause(0.2);
% Update position
Position_Update(handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in UP.
function UP_Callback(hObject, eventdata, handles)
% hObject handle to UP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Enable Buttons
set(handles.UP,'Enable','off')
set(handles.DW,'Enable','off')
% Move the stage
fprintf(handles.PCOM,['1pr' num2str(-abs(handles.ValStep)/1000)]);
Status=0;
while Status~=1
fprintf(handles.PCOM,'1md?');
pause(0.2);
Status=str2num(char(fread(handles.PCOM,handles.PCOM.BytesAvailable,'uint8')));
end
% Update position
Position_Update(handles);
% Enable Buttons
set(handles.UP,'Enable','on')
set(handles.DW,'Enable','on')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in DW.
function DW_Callback(hObject, eventdata, handles)
% hObject handle to DW (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Enable Buttons
set(handles.UP,'Enable','off')
set(handles.DW,'Enable','off')
% Move the stage
fprintf(handles.PCOM,['1pr' num2str(abs(handles.ValStep)/1000)]);
Status=0;
while Status~=1
fprintf(handles.PCOM,'1md?');
pause(0.2);
Status=str2num(char(fread(handles.PCOM,handles.PCOM.BytesAvailable,'uint8')));
end
% Update position
Position_Update(handles);
% Enable Buttons
set(handles.UP,'Enable','on')
set(handles.DW,'Enable','on')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes during object creation, after setting all properties.
function Step_CreateFcn(hObject, eventdata, handles)
% hObject handle to Step (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Step_Callback(hObject, eventdata, handles)
% hObject handle to Step (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Step as text
% str2double(get(hObject,'String')) returns contents of Step as a double
Step = str2double(get(hObject,'String'));
if isnan(Step)
Step=1;
end
handles.ValStep=round(Step*10)/10;
set(hObject,'String',sprintf('%.1f',handles.ValStep))
% Update handles structure
guidata(hObject, handles);
% Load parameters from the Main window
Main_handles=guidata(handles.Main);
% Update parameters
Main_handles.Step=handles.ValStep;
% Update Configuration GUI
try
Config_handles=guidata(Main_handles.HConfig);
set(Config_handles.Step,'String',sprintf('%.1f',handles.ValStep));
Config_handles.ValStep=handles.ValStep;
guidata(Main_handles.HConfig,Config_handles);
end
% Save parameters to the Main window
guidata(handles.Main,Main_handles);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -