MATLAB环境下地串口通信软件.doc
《MATLAB环境下地串口通信软件.doc》由会员分享,可在线阅读,更多相关《MATLAB环境下地串口通信软件.doc(14页珍藏版)》请在三一办公上搜索。
1、word某某电子科技大学第二十一届“星火杯大学生课外学术科技作品竞赛科技发明制作类说明书作品名称:MATLAB环境下的串口通信软件作品类别:计算机软件开发和设计类作品作品编号:_作品功能简介与使用说明书MATLAB环境下的串口通信软件,图形化操作界面。 用于对计算机的串口进展设置,数据收发,数据处理。可实现串口开关,串口属性设置,串口状态检测。 可通过本软件对下位机发送指令。 根据回传的数据,绘制实时数据曲线,可切换显示模式,曲线图,回传数据可保存。可根据回传数据的变化情况发送相应的指令。演示视频中为此软件作为温度监测系统上位机软件的应用。此软件可作为通用的串口通信调试器。编译后生成EXE文件
2、,可脱离MATLAB环境运行。程序主界面:使用说明:光盘中有功能演示视频串口选择区如串口成功打开,按钮变为绿色,并弹出提示框串口设置区波特率设置 等待时间与奇偶校验设置 可选择或编辑波特率 默认为无奇偶校验串口状态检测按钮 点击显示串口名, 串口开关状态, 波特率 ,记录状态数据发送区点击Send Now按钮将编辑框中的数据通过串口发往下位机数据接收区文本框中为从计算机从串口接收到的数据。点击Clear按钮清空接收区。数据可点击工具栏中的相应按钮保存。温度控制局部 曲线显示模式选择 设置报警温度 局部显示按钮与整体显示按钮温度超过X围将提醒并发送相应指令代码到下位机数据曲线图曲线图显示模式可选
3、择,图片,数据可另存。点击Clear Figure按钮清空曲线图点击工具栏中的保存按钮,选择保存路径与存储格式。局部程序源代码:function varargout = MyfirstGui(varargin)%串口通信调试器与温度监控系统上位机软件% 2009.811%发送按钮回调函数function Send_Callback(hObject, eventdata, handles)global s;SendingSrting=get(handles.SendString,String);fprintf(s,%c,SendingSrting);%去除按钮回调函数function Clear
4、_Callback(hObject, eventdata, handles)set(handles.Received,String,Received:);global ReceivedFromMcu;ReceivedFromMcu=Reveived:;%串口设置局部%串口开关设置% - Executes on button press in 1.function 1_Callback(hObject, eventdata, handles)% Hint: get(hObject,Value) returns toggle state of 1global s;button_state = ge
5、t(hObject,Value);if button_state = get(hObject,Max) set(handles 1,BackgroundColor,default); set(handles 2,BackgroundColor,default); set(handles 3,BackgroundColor,default); set(handles 4,BackgroundColor,default); delete(s); s=serial(1); s.BytesAvailableFMode=byte; s.BytesAvailableFCount=1; s.BytesAva
6、ilableF=ReceiveButton; fopen(s); set(hObject,BackgroundColor,green); message=1 is Open; msgbox(message);elseif button_state = get(hObject,Min) fclose(s); set(hObject,BackgroundColor,default);end%编辑波特率function EditBaudRate_Callback(hObject, eventdata, handles)% Hints: get(hObject,String) returns cont
7、ents of EditBaudRate as text% str2double(get(hObject,String) returns contents of EditBaudRate% as a doubleglobal s;user_entry = str2double(get(hObject,string);if isnan(user_entry) errordlg(You must enter a numeric value,Bad Input,modal) uicontrol(hObject) returnends.BaudRate=user_entry;message=Baudr
8、ate= get(hObject,string);msgbox(message);% - Executes during object creation, after setting all properties.function EditBaudRate_CreateF(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and PUTER.if ispc & isequal(get(hObject,BackgroundColor), g
9、et(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end% 选择波特率function SelectBaundRate_Callback(hObject, eventdata, handles)% Hints: contents = get(hObject,String) returns SelectBaundRate contents as cell array% contentsget(hObject,Value) returns selected item from% SelectBaundR
10、ateglobal s;val = get(hObject,Value);switch val case 1 s.BaudRate=9600; set(handles.EditBaudRate,string, ); case 2 s.BaudRate=4800; set(handles.EditBaudRate,string, ); case 3 s.BaudRate=14400; set(handles.EditBaudRate,string, ); case 4 s.BaudRate=28800; set(handles.EditBaudRate,string, );end% 选择等待时间
11、function TimeOut_Callback(hObject, eventdata, handles)% Hints: contents = get(hObject,String) returns TimeOut contents as cell array% contentsget(hObject,Value) returns selected item from TimeOutglobal s;val = get(hObject,Value);switch val case 1 s.TimeOut=10; case 2 s.TimeOut=5; case 3 s.TimeOut=2;
12、 case 4 s.TimeOut=1;end% - Executes during object creation, after setting all properties.function TimeOut_CreateF(hObject, eventdata, handles)% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and PUTER.if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicont
13、rolBackgroundColor) set(hObject,BackgroundColor,white);end%奇偶校验设置function Parity_Callback(hObject, eventdata, handles)% Hints: contents = get(hObject,String) returns Parity contents as cell array% contentsget(hObject,Value) returns selected item from Parityglobal s;val = get(hObject,Value);switch va
14、l case 1 s.Parity=none; case 2 s.Parity=even; case 3 s.Parity=odd;end%检查串口属性按钮function CheckSerial_Callback(hObject, eventdata, handles)global s;item1=s.Name;set(handles.Check1,String,item1);item2=s.Status;set(handles.Check2,String,item2);item3=s.Baudrate;set(handles.Check3,String,item3);item4=s.Rec
15、ordStatus;set(handles.Check4,String,item4);%接收字符回调函数function ReceiveButton(hObject, eventdata, handles)global s;global ReceivedFromMcu;global Myhandles;global x;global y;global a;persistent Char_Buffer;persistent count;%initialize the persistent variableif isempty(Char_Buffer) Char_Buffer=;endif ise
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MATLAB 环境 下地 串口 通信 软件
链接地址:https://www.31ppt.com/p-1087700.html