function varargout = comdraw(varargin)
% COMDRAW M-file for comdraw.fig
% COMDRAW, by itself, creates a new COMDRAW or raises the existing
% singleton*.
%
% H = COMDRAW returns the handle to a new COMDRAW or the handle to
% the existing singleton*.
%
% COMDRAW('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in COMDRAW.M with the given input arguments.
%
% COMDRAW('Property','Value',...) creates a new COMDRAW or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before comdraw_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to comdraw_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 comdraw
% Last Modified by GUIDE v2.5 29-May-2007 16:33:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @comdraw_OpeningFcn, ...
'gui_OutputFcn', @comdraw_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
global handle_com;
global serial_buf;
% --- Executes just before comdraw is made visible.
function comdraw_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 comdraw (see VARARGIN)
% Choose default command line output for comdraw
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes comdraw wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = comdraw_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 during object creation, after setting all properties.
function popup_com_port_CreateFcn(hObject, eventdata, handles)
% hObject handle to popup_com_port (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function comport_callback(obj, event)
%warning( 'COM recevice 16 bytes' );
global seriala_buf;
%get( obj )
send_len = get( obj, 'BytesAvailable' );
serial_buf = fread( obj, 16,'uint8')
%get( event )
% --- Executes on selection change in popup_com_port.
function popup_com_port_Callback(hObject, eventdata, handles)
global handle_com;
% hObject handle to popup_com_port (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popup_com_port contents as cell array
% contents{get(hObject,'Value')} returns selected item from popup_com_port
sel_val = get(hObject,'Value');
com_str = get(hObject,'String'); %get COM ports list
sel_str = com_str{ sel_val }; %get old COM port name
handle_com = serial( sel_str );
baud_rate = get( handles.popup_baud_rate,'Value' );
data_bit = get( handles.popup_data_bit,'Value' );
stop_bit = get( handles.popup_stop_bit,'Value' );
parity = get( handles.popup_parity,'Value' );
%warning( 'COM port set-----------------------------' );
try
switch baud_rate
case 1
handle_com.BaudRate=115200;
case 2
handle_com.BaudRate=57600;
case 3
handle_com.BaudRate=38400;
case 4
handle_com.BaudRate=19200;
otherwise
handle_com.BaudRate=9600;
end
% warning( 'COM baud rate-----------------------------' );
switch data_bit
case 1
handle_com.DataBits=8;
case 2
handle_com.DataBits=7;
case 3
handle_com.DataBits=6;
case 4
handle_com.DataBits=5;
otherwise
handle_com.DataBits=8;
end
switch stop_bit
case 1
handle_com.StopBits=1;
case 2
handle_com.StopBits=1.5;
case 3
handle_com.StopBits=2;
otherwise
handle_com.StopBits=1;
end
switch parity
case 1
handle_com.Parity='none';
case 2
handle_com.Parity='odd';
case 3
handle_com.Parity='even';
otherwise
handle_com.Parity='none';
end
handle_com.InputBufferSize=1024;
handle_com.timeout=0.5;
handle_com.Terminator='LF';
handle_com.FlowControl='none';
handle_com.BytesAvailableFcnMode = 'byte';
handle_com.BytesAvailableFcnCount = 16;
handle_com.BytesAvailableFcn = @comport_callback;
% handle_com.BytesAvailableFcn = @instrcallback;
% handle_com.OutputEmptyFcn = @instrcallback;
get( handle_com )
fopen( handle_com );
% warning( 'open COM ok' );
set( hObject, 'Enable', 'off' );
set( handles.popup_baud_rate,'Enable','off' );
set( handles.popup_data_bit,'Enable','off' );
set( handles.popup_stop_bit,'Enable','off' );
set( handles.popup_parity,'Enable','off' );
% fwrite(handle_com,'COM init OK');
% out_data=fread(handle_com,16,'uint8')%接收32个数据(8位),并存入out数组中
% warning( out_data );
% fclose( handle_com );
% delete( handle_com );
% clear( handle_com );
catch
fclose( handle_com );
info_str = sprintf( '%s open failure, please select another!\n', sel_str);
errordlg( info_str,'COM PORT ERROR','modal');
end
% --- Executes during object creation, after setting all properties.
function popup_baud_rate_CreateFcn(hObject, eventdata, handles)
% hObject handle to popup_baud_rate (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in popup_baud_rate.
function popup_baud_rate_Callback(hObject, eventdata, handles)
% hObject handle to popup_baud_rate (see GCBO)
% eventdata reserved - to be defined in a future vers
没有合适的资源?快使用搜索试试~ 我知道了~
基于MATLAB实现的串口发送接收数据可配置端口,波特率等+使用说明文档
共3个文件
md:1个
m:1个
fig:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 36 浏览量
2024-05-22
17:32:14
上传
评论
收藏 11KB RAR 举报
温馨提示
CSDN IT狂飙上传的代码均可运行,功能ok的情况下才上传的,直接替换数据即可使用,小白也能轻松上手 【资源说明】 基于MATLAB实现的串口发送接收数据可配置端口,波特率等 发送可选择ASCII方式或HEX方式 中断方式接收数据 可以通过ADC和MCU可以把数据通过 串口直接发送到PC上让MATLAB分析+使用说明文档 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2020b;若运行有误,根据提示GPT修改;若不会,私信博主(问题描述要详细); 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可后台私信博主; 4.1 期刊或参考文献复现 4.2 Matlab程序定制 4.3 科研合作 功率谱估计: 故障诊断分析: 雷达通信:雷达LFM、MIMO、成像、定位、干扰、检测、信号分析、脉冲压缩 滤波估计:SOC估计 目标定位:WSN定位、滤波跟踪、目标定位 生物电信号:肌电信号EMG、脑电信号EEG、心电信号ECG 通信系统:DOA估计、编码译码、变分模态分解、管道泄漏、滤波器、数字信号处理+传输+分析+去噪、数字信号调制、误码率、信号估计、DTMF、信号检测识别融合、LEACH协议、信号检测、水声通信 5、欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
基于MATLAB实现的串口发送接收数据可配置端口,波特率等 发送可选择ASCII方式或HEX方式 中断方式接收数据 可以通过ADC和MCU可以把数据通过 串口直接发送到PC上让MATLAB分析+使用说明文档.rar (3个子文件)
comdraw.m 19KB
使用说明文档.md 13KB
comdraw.fig 43KB
共 3 条
- 1
资源评论
IT狂飙
- 粉丝: 4779
- 资源: 2640
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功