MATLAB中GUI界面开发上位机 您所在的位置:网站首页 atm机界面设计优缺点 MATLAB中GUI界面开发上位机

MATLAB中GUI界面开发上位机

2024-06-14 09:15| 来源: 网络整理| 查看: 265

function varargout = uartchat(varargin) % UARTCHAT MATLAB code for uartchat.fig %      UARTCHAT, by itself, creates a new UARTCHAT or raises the existing %      singleton*. % %      H = UARTCHAT returns the handle to a new UARTCHAT or the handle to %      the existing singleton*. % %      UARTCHAT('CALLBACK',hObject,eventData,handles,...) calls the local %      function named CALLBACK in UARTCHAT.M with the given input arguments. % %      UARTCHAT('Property','Value',...) creates a new UARTCHAT or raises the %      existing singleton*.  Starting from the left, property value pairs are %      applied to the GUI before uartchat_OpeningFcn gets called.  An %      unrecognized property name or invalid value makes property application %      stop.  All inputs are passed to uartchat_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 uartchat

% Last Modified by GUIDE v2.5 23-Sep-2019 10:39:30

% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name',       mfilename, ...                    'gui_Singleton',  gui_Singleton, ...                    'gui_OpeningFcn', @uartchat_OpeningFcn, ...                    'gui_OutputFcn',  @uartchat_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 uartchat is made visible. function uartchat_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 uartchat (see VARARGIN)

% Choose default command line output for uartchat handles.output = hObject; % Update handles structure guidata(hObject, handles);

% UIWAIT makes uartchat wait for user response (see UIRESUME) % uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout = uartchat_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 clearbutton. function clearbutton_Callback(hObject, eventdata, handles) % hObject    handle to clearbutton (see GCBO) % eventdata  reserved - to be defined in a future version of MATLAB % handles    structure with handles and user data (see GUIDATA) set(handles.receivemessage,'String',''); clear a;

% --- Executes on button press in openbutton. function openbutton_Callback(hObject, eventdata, handles) % hObject    handle to openbutton (see GCBO) % eventdata  reserved - to be defined in a future version of MATLAB % handles    structure with handles and user data (see GUIDATA) % set(handles.device_port_current,'BaudRate',9600,'Parity','none','stopbits',1,'databits',8,'FlowControl','none'); global rate; set(handles.device_port_current,'BaudRate',rate); set(handles.device_port_current,'DataBits',8); set(handles.device_port_current,'StopBits',1); set(handles.device_port_current,'Parity','none'); set(handles.device_port_current,'FlowControl','none'); handles.device_port_current.BytesAvailableFcnCount = 1; handles.device_port_current.BytesAvailableFcnMode = 'byte'; handles.device_port_current.BytesAvailableFcn = {@ReceiveBytesAvailableFcn,handles};

% handles.output=hObject; guidata(hObject,handles);

fopen(handles.device_port_current); set(handles.openbutton,'enable','off');%打开串口后,该按钮变灰,无法再次点击该按钮 set(handles.commenu,'enable','off'); set(handles.closebutton,'enable','on'); guidata(hObject,handles);

% --- Executes on button press in closebutton. function closebutton_Callback(hObject, eventdata, handles) % hObject    handle to closebutton (see GCBO) % eventdata  reserved - to be defined in a future version of MATLAB % handles    structure with handles and user data (see GUIDATA) fclose(handles.device_port_current); set(handles.openbutton,'enable','on');%打开串口后,该按钮变灰,无法再次点击该按钮 set(handles.commenu,'enable','on'); set(handles.closebutton,'enable','off'); clear a; guidata(hObject,handles);

% --- Executes on button press in sendbutton. function sendbutton_Callback(hObject, eventdata, handles) % hObject    handle to sendbutton (see GCBO) % eventdata  reserved - to be defined in a future version of MATLAB % handles    structure with handles and user data (see GUIDATA) senddata=get(handles.sendmessage,'String'); fprintf(handles.device_port_current,'%s',senddata);

% --- Executes on selection change in commenu. function commenu_Callback(hObject, eventdata, handles) % hObject    handle to commenu (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 commenu contents as cell array %        contents{get(hObject,'Value')} returns selected item from commenu str=get(hObject,'String'); val=get(hObject,'value'); switch str{val}     case 'COM1'         handles.device_port_current=serial('COM1');     case 'COM2'         handles.device_port_current=serial('COM2');     case 'COM3'         handles.device_port_current=serial('COM3');     case 'COM4'         handles.device_port_current=serial('COM4');     case 'COM5'         handles.device_port_current=serial('COM5');     case 'COM6'         handles.device_port_current=serial('COM6');     case 'COM7'         handles.device_port_current=serial('COM7');     case 'COM8'         handles.device_port_current=serial('COM8');     case 'COM9'         handles.device_port_current=serial('COM9'); end guidata(hObject,handles);%保存配置

% --- Executes during object creation, after setting all properties. function commenu_CreateFcn(hObject, eventdata, handles) % hObject    handle to commenu (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 selection change in baudmenu2. function baudmenu2_Callback(hObject, eventdata, handles) % hObject    handle to baudmenu2 (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 baudmenu2 contents as cell array %        contents{get(hObject,'Value')} returns selected item from baudmenu2 global rate; val2=get(hObject,'value'); switch val2     case 2         rate=1200;     case 3         rate=4800;     case 4         rate=9600; end %set(handles.receivemessage,'String',rate); guidata(hObject,handles);

% --- Executes during object creation, after setting all properties. function baudmenu2_CreateFcn(hObject, eventdata, handles) % hObject    handle to baudmenu2 (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 sendmessage_Callback(hObject, eventdata, handles) % hObject    handle to sendmessage (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 sendmessage as text %        str2double(get(hObject,'String')) returns contents of sendmessage as a double sendtext=get(handles.sendmessage,'String'); fprintf(handles.device_port_current,'%s',sendtext);

% --- Executes during object creation, after setting all properties. function sendmessage_CreateFcn(hObject, eventdata, handles) % hObject    handle to sendmessage (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 ReceiveBytesAvailableFcn(hObject,evendata,handles) global a; Receivedata=setstr(fread(handles.device_port_current,1)); a=strcat(a,Receivedata); set(handles.receivemessage,'String',a);



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有