Get data from realterm and show it on MATLAB GUI.
4 次查看(过去 30 天)
显示 更早的评论
I am sending continuous data from realterm to MATLAB and want to set baudrate of serial port same as of realterm thats why I have used actxserver command. It works well. Moreover, I want MATLAB to stop taking data on pressing "Stop button". After stopping data it should ask to input specific row number. And in last it should display that specific row in the text box. My demo code do not do not stops on pressing stop button. Also I do not get how to add input command in the code. Here is my code.
function varargout = showguide(varargin)
% SHOWGUIDE MATLAB code for showguide.fig
% SHOWGUIDE, by itself, creates a new SHOWGUIDE or raises the existing
% singleton*.
%
% H = SHOWGUIDE returns the handle to a new SHOWGUIDE or the handle to
% the existing singleton*.
%
% SHOWGUIDE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SHOWGUIDE.M with the given input arguments.
%
% SHOWGUIDE('Property','Value',...) creates a new SHOWGUIDE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before showguide_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to showguide_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 showguide
% Last Modified by GUIDE v2.5 04-Mar-2023 18:02:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @showguide_OpeningFcn, ...
'gui_OutputFcn', @showguide_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 showguide is made visible.
function showguide_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 showguide (see VARARGIN)
% Choose default command line output for showguide
handles.output = hObject;
handles.run=1
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes showguide wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = showguide_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)
realterm = actxserver ('realterm.realtermintf')
realterm.port = '5'
realterm.portopen=1
s = serial('COM4', 'Baudrate', 57600)
fclose(s)
fopen(s)
serial_baudrate = s.baudrate
data = ''
pause (15)
while (1)
handles=guidata(hObject);
if handles.run==1
new_data = fscanf(s)
data = [data, new_data]
realterm_baudrate = realterm.baud
set(handles.text3, 'String', num2str(realterm_baudrate))
serial_baudrate = realterm_baudrate
set(handles.text4, 'String', num2str(serial_baudrate))
arrange_data = textscan(data,'%s','Delimiter',' ') %arrange data in array
extract_data = arrange_data{:} % shows arranged data scanned by textscan
set(handles.text2, 'String', extract_data)
else
handles.run=1;
disp('stopped')
row_data = extract_data(3,:)
set(handles.text5, 'String',row_data)
break
end
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)
handles.run=0;
guidata(hObject,handles)
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Environment Customization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!