What does the "invalid port" error mean?

6 views (last 30 days)
Thomas Stokes
Thomas Stokes on 26 May 2015
Hi, I'm currently completing an assignment and when I run my code and GUI, I receive the error "invalid port". Would anyone be able to help me in identifying why this error is occurring?
My code and GUI are attached.
function varargout = Assignment3(varargin)
% ASSIGNMENT3 MATLAB code for Assignment3.fig
% ASSIGNMENT3, by itself, creates a new ASSIGNMENT3 or raises the existing
% singleton*.
%
% H = ASSIGNMENT3 returns the handle to a new ASSIGNMENT3 or the handle to
% the existing singleton*.
%
% Assignment3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in Assignment3.M with the given input arguments.
%
% ASSIGNMENT3('Property','Value',...) creates a new ASSIGNMENT3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Assignment3_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Assignment3_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 Assignment3
% Last Modified by GUIDE v2.5 26-May-2015 14:59:05
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Assignment3_OpeningFcn, ... 'gui_OutputFcn', @Assignment3_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 Assignment3 is made visible. function Assignment3_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 Assignment3 (see VARARGIN)
% Choose default command line output for Assignment3 handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% % set(handles.coms,'UserData',getAvailableCOM5); % set(handles.FlowData,'UserData',zeros(1,2)); % set(handles.PreasureData,'UserData',zeros(1,2)); % set(handles.Time,'UserData',0); % set(handles.COM,'UserData','COM8');
% UIWAIT makes Assignment3 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = Assignment3_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;
function FlowValue_Callback(hObject, eventdata, handles) % hObject handle to FlowValue (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 FlowValue as text % str2double(get(hObject,'String')) returns contents of FlowValue as a double
% --- Executes during object creation, after setting all properties. function FlowValue_CreateFcn(hObject, eventdata, handles) % hObject handle to FlowValue (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
% --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (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 popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (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 PreasureValue_Callback(hObject, eventdata, handles) % hObject handle to PreasureValue (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 PreasureValue as text % str2double(get(hObject,'String')) returns contents of PreasureValue as a double
% --- Executes during object creation, after setting all properties. function PreasureValue_CreateFcn(hObject, eventdata, handles) % hObject handle to PreasureValue (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
% --- Executes on selection change in popupmenu3. function popupmenu3_Callback(hObject, eventdata, handles) % hObject handle to popupmenu3 (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 popupmenu3 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties. function popupmenu3_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu3 (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
% --- Executes on button press in LiveDataRadio. function LiveDataRadio_Callback(hObject, eventdata, handles) % hObject handle to LiveDataRadio (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of LiveDataRadio
% --- Executes on button press in EfficencyTrendRadio. function EfficencyTrendRadio_Callback(hObject, eventdata, handles) % hObject handle to EfficencyTrendRadio (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of EfficencyTrendRadio
% --- Executes on button press in radiobutton6. function radiobutton6_Callback(hObject, eventdata, handles) % hObject handle to radiobutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton6
% -------------------------------------------------------------------- function File_Callback(hObject, eventdata, handles) % hObject handle to File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% -------------------------------------------------------------------- function Untitled_2_Callback(hObject, eventdata, handles) % hObject handle to Untitled_2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% -------------------------------------------------------------------- function Save_Callback(hObject, eventdata, handles) % hObject handle to Save (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in LiveDataBtn. function pushbutton23_Callback(hObject, eventdata, handles) % hObject handle to LiveDataBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.pushbutton22,'UserData',0) set(handles.pushbutton23,'UserData',1)
while get(handles.pushbutton22,'UserData')==0 if (ismember((get(handles.edit6,'string')),(get(handles.coms,'UserData'))))==1 delete (instrfind) s = serial('COM8');
fopen(s)
set(handles.PreasureData,'UserData',zeros(1,2));
set(handles.Time,'UserData',0);
set(handles.FlowData,'UserData',zeros(1,2));
set(handles.FlowData,'UserData',zeros(1,2));
set(handles.pushbutton25,'UserData',zeros(1,2));
set(handles.pushbutton26,'UserData',0);
cla(handles.axes14)
cla(handles.axes15)
cla(handles.axes16)
while get(handles.pushbutton23,'UserData')==1
if (get(handles.Time,'UserData'))== 0
flushinput(s)
t=(get(handles.Time,'UserData'))+1;
set(handles.Time,'UserData',t)
FlowDataColected(t,1) = fscanf(s,'%i L/Hr');
FlowDataColected(t,2) = t;
set(handles.FlowData,'UserData',FlowDataColected);
PreasureDataColected(t,1) = fscanf(s,'%f kPa');
PreasureDataColected(t,2) = t;
set(handles.PreasureData,'UserData',PreasureDataColected);
else
flushinput(s)
t=(get(handles.Time,'UserData'))+1;
set(handles.Time,'UserData',t)
FlowDataColected = get(handles.FlowData,'UserData');
a(1,1) = fscanf(s,'%i L/Hr');
a(1,2) = t;
FlowDataColected = vertcat(FlowDataColected,a);
set(handles.FlowData,'UserData',FlowDataColected);
PreasureDataColected = get(handles.PreasureData,'UserData');
a(1,1) = fscanf(s,'%f kPa');
a(1,2) = t;
PreasureDataColected = vertcat(PreasureDataColected,a);
set(handles.PreasureData,'UserData',PreasureDataColected);
end
set(handles.text37,'String',num2str(FlowDataColected(t,1)));
set(handles.text39,'String',num2str(PreasureDataColected(t,1)));
axes(handles.axes15);
plot(FlowDataColected(:,1))
xlim([t-20 t])
axes(handles.axes16);
plot(PreasureDataColected(:,1),'g')
xlim([t-20 t])
axes(handles.axes14);
PreasureDataColected = get(handles.PreasureData,'UserData');
FlowDataColected = get(handles.FlowData,'UserData');
if t>1
delta = abs((PreasureDataColected((t-1),1))-(PreasureDataColected((t),1)));
Tol = get(handles.edit7,'string');
if get(handles.edit7,'string')> delta
if get(handles.pushbutton26,'UserData')>=1
STABLEDATAC = ([PreasureDataColected(t,1) FlowDataColected(t,1)]);
STABLEDATAO = get(handles.pushbutton25,'Userdata');
STABLEDATA = vertcat(STABLEDATAO,STABLEDATAC);
set(handles.pushbutton25,'Userdata',STABLEDATA);
PLOT = get(handles.pushbutton26,'UserData')+1;
set(handles.pushbutton26,'UserData',PLOT)
else
STABLEDATA = ([PreasureDataColected(t,1) FlowDataColected(t,1)]);
set(handles.pushbutton25,'Userdata',STABLEDATA)
PLOT = get(handles.pushbutton26,'UserData')+1;
set(handles.pushbutton26,'UserData',PLOT)
end
cla
STABLEDATA = get(handles.pushbutton25,'Userdata');
STABLEDATA(:,1) = STABLEDATA(:,1)/10;
STABLEDATA;
scatter(STABLEDATA(:,2),(STABLEDATA(:,1)),100,'b.');
hold all
minimum = min(STABLEDATA,[],1);
maximum = max(STABLEDATA,[],1);
sz = size(STABLEDATA);
p = polyfit((STABLEDATA(:,1)),STABLEDATA(:,2),2);
x1 = linspace(minn(1,2), maxx(1,2), sz(1,1));
y1 = polyval(p,x1);
plot(x1,y1,'r');
axis auto
end
end
pause(1)
end
else
COMerror = errordlg('INVALID PORT');
set(handles.pushbutton22,'UserData',1)
set(handles.pushbutton23,'UserData',0)
set(handles.ErrorStat,'UserData',1)
break
end
end
delete (instrfind)
% --- Executes on button press in StopBtn. function pushbutton22_Callback(hObject, eventdata, handles) % hObject handle to StopBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.pushbutton22,'UserData',1) set(handles.pushbutton23,'UserData',0)
% -------------------------------------------------------------------- function Setup_Callback(hObject, eventdata, handles) % hObject handle to Setup (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% -------------------------------------------------------------------- function Untitled_4_Callback(hObject, eventdata, handles) % hObject handle to Untitled_4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in StopBtn. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to StopBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton8. function pushbutton8_Callback(hObject, eventdata, handles) % hObject handle to pushbutton8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton10. function pushbutton10_Callback(hObject, eventdata, handles) % hObject handle to pushbutton10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Time. function Time_Callback(hObject, eventdata, handles) % hObject handle to Time (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in FlowData. function FlowData_Callback(hObject, eventdata, handles) % hObject handle to FlowData (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in PreasureData. function PreasureData_Callback(hObject, eventdata, handles) % hObject handle to PreasureData (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press 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)
% --- Executes on button press in coms. function coms_Callback(hObject, eventdata, handles) % hObject handle to coms (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes when selected object is changed in uipanel5. function uipanel5_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to the selected object in uipanel5 % eventdata structure with the following fields (see UIBUTTONGROUP) % EventName: string 'SelectionChanged' (read only) % OldValue: handle of the previously selected object or empty if none was selected % NewValue: handle of the currently selected object % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in ErrorStat. function ErrorStat_Callback(hObject, eventdata, handles) % hObject handle to ErrorStat (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
function edit6_Callback(hObject, eventdata, handles) % hObject handle to edit6 (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 edit6 as text % str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties. function edit6_CreateFcn(hObject, eventdata, handles) % hObject handle to edit6 (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 edit7_Callback(hObject, eventdata, handles) % hObject handle to edit7 (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 edit7 as text % str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles) % hObject handle to edit7 (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
% --- Executes on button press in pushbutton25. function pushbutton25_Callback(hObject, eventdata, handles) % hObject handle to pushbutton25 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton26. function pushbutton26_Callback(hObject, eventdata, handles) % hObject handle to pushbutton26 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton27. function pushbutton27_Callback(hObject, eventdata, handles) % hObject handle to pushbutton27 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) StableData = get(handles.pushbutton25,'Userdata'); StableData(:,1) = StableData(:,1)/10; filename = [get(handles.edit8,'String') '.xlsx']; sheet = get(handles.edit9,'String'); xlswrite(filename,StableData,sheet)
function edit8_Callback(hObject, eventdata, handles) % hObject handle to edit8 (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 edit8 as text % str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties. function edit8_CreateFcn(hObject, eventdata, handles) % hObject handle to edit8 (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 edit9_Callback(hObject, eventdata, handles) % hObject handle to edit9 (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 edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double
% --- Executes during object creation, after setting all properties. function edit9_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (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
% --- Executes on button press in pushbutton28. function pushbutton28_Callback(hObject, eventdata, handles) % hObject handle to pushbutton28 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.pushbutton22,'UserData',1) set(handles.pushbutton23,'UserData',0)
filename = [get(handles.edit10,'String') '.xlsx']; sheet = get(handles.edit11,'String'); LoadedData = xlsread(filename,sheet); axes(handles.axes14); cla scatter(LoadedData(:,2),(LoadedData(:,1)),100,'b.'); hold all
minimum = min(LoadedData,[],1); maximum = max(LoadedData,[],1);
sz = size(LoadedData);
plot = polyfit((LoadedData(:,1)),LoadedData(:,2),2);
x1 = linspace(minimum(1,2), maximum(1,2), sz(1,1)); y1 = polyval(plot,x1);
plot(x1,y1,'r');
axis auto
function edit10_Callback(hObject, eventdata, handles) % hObject handle to edit10 (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 edit10 as text % str2double(get(hObject,'String')) returns contents of edit10 as a double
% --- Executes during object creation, after setting all properties. function edit10_CreateFcn(hObject, eventdata, handles) % hObject handle to edit10 (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 edit11_Callback(hObject, eventdata, handles) % hObject handle to edit11 (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 edit11 as text % str2double(get(hObject,'String')) returns contents of edit11 as a double
% --- Executes during object creation, after setting all properties. function edit11_CreateFcn(hObject, eventdata, handles) % hObject handle to edit11 (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

Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!