any one help me how to explain this code

function varargout = gui(varargin)
% GUI MATLAB code for gui.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_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 gui
% Last Modified by GUIDE v2.5 15-Apr-2015 02:44:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(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 gui is made visible.
function gui_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 gui (see VARARGIN)
% Choose default command line output for gui
handles.output = hObject;
ports = getAvailableComPort();
handles.s=serial(ports(1),'BaudRate',9600);
handles.s.RequestToSend = 'off';
handles.s.DataTerminalReady = 'off';
handles.s.BytesAvailableFcn = {@mycallback,hObject};
% Initialize slider and its readout text field
buffSize = 60;
circBuff = nan(1,buffSize);
x = 1:60; % Make up some data and plot
% Create a surface plot of peaks data. Store handle to it.
handles.plot1 = plot(handles.axes1,x,circBuff);
handles.plot2 = plot(handles.axes2,x,circBuff);
handles.plot3 = plot(handles.axes3,x,circBuff);
set(handles.com,'String',[' ';getAvailableComPort()])
set(handles.warning, 'String','Normal','BackgroundColor','Green')
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_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 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)
if strcmp(get(handles.s, 'Status'), 'closed')
disp "opened"
fopen(handles.s);
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if strcmp(get(handles.s, 'Status'), 'open')
disp "closed"
fclose(handles.s);
end
% --- Executes on selection change in com.
function com_Callback(hObject, eventdata, handles)
% hObject handle to com (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns com contents as cell array
% contents{get(hObject,'Value')} returns selected item from com
str = (get(hObject,'String'));
val = get(hObject,'Value');
temp = char(str(val));
set(handles.s,'Port',temp);
% --- Executes during object creation, after setting all properties.
function com_CreateFcn(hObject, eventdata, empty)
% hObject handle to com (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function warning_Callback(hObject, eventdata, empty)
% hObject handle to warning (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 warning as text
% str2double(get(hObject,'String')) returns contents of warning as a double
% --- Executes during object creation, after setting all properties.
function warning_CreateFcn(hObject, eventdata, empty)
% hObject handle to warning (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function mycallback(obj,eventdata,hfigure)
%BytesAvailable = obj.BytesAvailable;
data = fread(obj, obj.BytesAvailable);
if data(1,1)==112 && data(end,1)==10
temp1 = find(data==112);
temp2 = find(data==116);
temp3 = find(data==102);
temp4 = find(data==13);
pressure = (data(temp1+1,1)-48)*10^(temp2-temp1-2)+(data(temp1+2,1)-48)*10^(temp2-temp1-3)+((data(temp1+3,1)-48)*10^(temp2-temp1-4))*(temp2-temp1-3)
temperature = (data(temp2+1,1)-48)*10^(temp3-temp2-2)+((data(temp2+2,1)-48)*10^(temp3-temp2-3))*(temp3-temp2-2)+((data(temp2+3,1)-48)*10^(temp3-temp2-4))*(temp3-temp2-3)
fluidrate = (data(temp3+1,1)-48)*10^(temp4-temp3-2)+(data(temp3+2,1)-48)*10^(temp4-temp3-3)+((data(temp3+3,1)-48)*10^(temp4-temp3-4))*(temp4-temp3-3)
end
handles = guidata(hfigure);
circBuff = get(handles.plot1,'YData');
circBuff = [circBuff(2:end) pressure];
set(handles.plot1,'YData',circBuff);
circBuff = get(handles.plot2,'YData');
circBuff = [circBuff(2:end) temperature];
set(handles.plot2,'YData',circBuff);
circBuff = get(handles.plot3,'YData');
circBuff = [circBuff(2:end) fluidrate];
set(handles.plot3,'YData',circBuff);
newdata = [pressure, temperature, fluidrate];
stats = get(handles.tab, 'Data');
stats = [newdata; stats(1:end-1,:)];
set(handles.tab, 'Data', stats);
if ((pressure<=290)&&(pressure>=270)) && ((temperature<=40)&&(temperature>=10)) && ((fluidrate<=110)&&(fluidrate>=100))
set(handles.warning, 'String','Normal','BackgroundColor','Green')
elseif ((pressure>260) && (pressure< 270)) || ((pressure>290) && (pressure< 300)) || ((temperature>40) && (temperature< 50)) || ((temperature>0) && (temperature<10)) || ((fluidrate>110) && (fluidrate< 120)) || ((fluidrate>90) && (fluidrate<100))
set(handles.warning, 'String','Safety Limit','BackgroundColor','Yellow')
else
set(handles.warning, 'String','Warning','BackgroundColor','Red')
end
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if strcmp(get(handles.s, 'Status'), 'open')
fclose(handles.s);
end
delete(handles.s)
% Hint: delete(hObject) closes the figure
delete(hObject);

1 commentaire

Jan
Jan le 8 Juin 2015
You post a large program in an unreadable form and expect that anybody takes hours to explain all little details?
The question is far to general to be answered seriously.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 8 Juin 2015

0 votes

What about it? It manages a list of serial ports and reads and plots pressure, temperature, and fluid readings read from the serial port. It keeps the last 60 points plotted.

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by