




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
西安电子科技大学第二十一届“星火杯”大学生课外学术科技作品竞赛科技发明制作类说明书作品名称:MATLAB环境下的串口通信软件作品类别:计算机软件开发与设计类作品作品编号:_作品功能简介及使用说明书MATLAB环境下的串口通信软件,图形化操作界面。 用于对计算机的串口进行设置,数据收发,数据处理。可实现串口开关,串口属性设置,串口状态检测。 可通过本软件对下位机发送指令。 根据回传的数据,绘制实时数据曲线,可切换显示模式,曲线图,回传数据可保存。可根据回传数据的变化情况发送相应的指令。演示视频中为此软件作为温度监测系统上位机软件的应用。 此软件可作为通用的串口通信调试器。编译后生成EXE文件,可脱离MATLAB环境运行。程序主界面:使用说明: 光盘中有功能演示视频 串口选择区如串口成功打开,按钮变为绿色,并弹出提示框 串口设置区波特率设置 等待时间与奇偶校验设置 可选择或编辑波特率 默认为无奇偶校验 串口状态检测按钮 点击显示串口名, 串口开关状态, 波特率 ,记录状态数据发送区点击Send Now按钮将编辑框中的数据通过串口发往下位机数据接收区文本框中为从计算机从串口接收到的数据。点击Clear按钮清空接收区。数据可点击工具栏中的相应按钮保存。温度控制部分 曲线显示模式选择 设置报警温度 局部显示按钮与整体显示按钮温度超过范围将提醒并发送相应指令代码到下位机数据曲线图曲线图显示模式可选择,图片,数据可另存。点击Clear Figure按钮清空曲线图点击工具栏中的保存按钮,选择保存路径与存储格式。部分程序源代码:function varargout = MyfirstGui(varargin)% MyfirstGui M-file for MyfirstGui.fig%串口通信调试器与温度监控系统上位机软件% 2009.811%发送按钮回调函数function Send_Callback(hObject, eventdata, handles)global s;SendingSrting=get(handles.SendString,String);fprintf(s,%c,SendingSrting);%清除按钮回调函数function Clear_Callback(hObject, eventdata, handles)set(handles.Received,String,Received:);global ReceivedFromMcu;ReceivedFromMcu=Reveived:;%串口设置部分%串口开关设置% - Executes on button press in COM1.function COM1_Callback(hObject, eventdata, handles)% Hint: get(hObject,Value) returns toggle state of COM1global s;button_state = get(hObject,Value);if button_state = get(hObject,Max) set(handles.COM1,BackgroundColor,default); set(handles.COM2,BackgroundColor,default); set(handles.COM3,BackgroundColor,default); set(handles.COM4,BackgroundColor,default); delete(s); s=serial(com1); s.BytesAvailableFcnMode=byte; s.BytesAvailableFcnCount=1; s.BytesAvailableFcn=ReceiveButton; fopen(s); set(hObject,BackgroundColor,green); message=COM1 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 contents 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=Baudrate= get(hObject,string);msgbox(message);% - Executes during object creation, after setting all properties.function EditBaudRate_CreateFcn(hObject, eventdata, handles)% 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 SelectBaundRate_Callback(hObject, eventdata, handles)% Hints: contents = get(hObject,String) returns SelectBaundRate contents as cell array% contentsget(hObject,Value) returns selected item from% SelectBaundRateglobal 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% 选择等待时间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; case 4 s.TimeOut=1;end% - Executes during object creation, after setting all properties.function TimeOut_CreateFcn(hObject, eventdata, handles)% 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 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 val 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.RecordStatus;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 isempty(count) count=0;endReceived_Char=fscanf(s,%c,1);%ReceivedFromMcu will be displayed in the received zoneReceivedFromMcu=ReceivedFromMcu Received_Char;%Char_Buffer will be converted to numbersChar_Buffer=Char_Buffer Received_Char;%When the port has received a ,it means the begining of another%converting action.if Received_Char= ; Char_Buffer=;end%Check the Char_Buffer,if available,it will be sent to ySizeof_Char_Buffer=size(Char_Buffer);if (Sizeof_Char_Buffer(2)=4)&(Char_Buffer(3)=.); %Give numbers to the figure y=y sscanf(Char_Buffer,%g); x=x count; count=count+1;end%Get the last value of ya,b=size(y);if(b0) a=y(1,end);end%Plot the Temperature Lineif aMyhandles.High plot(Myhandles.axes1,x,y,m);elseif a50 slope=y(b)-y(b-49);endif slope0.2 set(Myhandles.Warning,Visible,on); set(Myhandles.Warning,String,WARNING:Temperature is going up quickly!);elseif slope500 ReceivedFromMcu=Rcecived:;endset(Myhandles.Received,String,ReceivedFromMcu);%清除图像按钮function ClearFigure_Callback(hObject, eventdata, handles)global x;global y;x=x(end);y=y(end);plot(handles.axes1,x,y,r.);%曲线显示模式选择% - Executes on button press in Part.function Part_Callback(hObject, eventdata, handles)global Myhandles;global a;state = get(hObject,Value);if state = get(hObject,Max) %Change mode Myhandles.DisplayMode=0;end%Set axes according to DisplayModeif Myhandles.DisplayMode=0 set(Myhandles.axes1,YLim,a-1.5 a+1.5);else set(Myhandles.axes1,YLim,a-10 a+10);end% - Executes on button press in Whole.function Whole_Callback(hObject, eventdata, handles)global Myhandles;global a;state = get(hObject,Value);if state = get(hObject,Max) %Change mode Myhandles.DisplayMode=1;end%Set axes according to DisplayModeif Myhandles.DisplayMode=0 set(Myhandles.axes1,YLim,a-1.5 a+1.5);else set(Myhandles.axes1,YLim,a-10 a+10);end%设置报警温度function Low_Callback(hObject, eventdata, handles)% Hints: get(hObject,String) returns contents of Low as text% str2double(get(hObject,String) returns contents of Low as a doubleglobal Myhandles;user_entry = str2double(get(hObject,string);if isnan(user_entry)|user_entry =Myhandles.High errordlg(You must enter a rightful numeric value,Bad Input,modal) uicontrol(hObject) returnendMyhandles.Low=user_entry;message=Warning Low Temperature= get(hObject,string);msgbox(message);function High_Callback(hObject, eventdata, handles)% Hints: get(hObject,String) returns contents of High as text% str2double(get(hObject,String) returns contents of High as a doubleglobal Myhandles;user_entry = str2double(get(hObject,string);if isnan(user_entry)|user_entry =Myhandles.Low errordlg(You must enter a rightful numeric value,Bad Input,modal) uicontrol(hObject) returnendMyhandles.High=user_entry;message=Warning High Temperature= get(hObject,string);msgbox(message);%工具栏部分% -保存图片-function Save_ClickedCallback(hObject, eventdata, handles)file,path = uiputfile ( *.jpg;*.png;*.bmp;*.tif,Save Figure);if isequal(file,0) | isequal(path,0) return;endf=fullfile(path,file);h=getframe(handles.axes1);h=frame2im(h);imwrite(h, f);% -新任务 -function New_ClickedCallback(hObject, eventdata, handles)global s;Clear_Callback(hObject, eventdata, handles);ClearFigure_Callback(hObject, eventdata, handles);delete(s);set(handles.COM1,Value,0);set(handles.COM2,Value,0);set(handles.COM3,Value,0);set(handles.COM4,Value,0);set(handles.COM1,Value,0);set(handles.COM1,BackgroundColor,default);set(handles.COM2,BackgroundColor,default);set(handles.COM3,BackgroundColor,default);set(handles.COM4,BackgroundColor,default);set(handles.Warning,Visible,off);set(handles.Current_Tempe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度房产置换合伙协议中介主导条款及佣金分配合同
- 2025版货车运输承包合同(含智能调度系统)
- 二零二五年度物业租赁居间服务合同范本正规范本
- 二零二五年度厂区特色屋顶绿化景观施工合同
- 2025版环保产业污染治理设施抵押借款合同
- 二零二五年度荒山承包合同范本:生态修复与景观建设
- 二零二五年度劳动合同补充协议:企业可持续发展与员工权益保障
- 2025版房地产信托附加协议书范本
- 二零二五年度典当公司担保与保险服务合同
- 2025至2030年中国浴擦行业市场发展现状及投资战略咨询报告
- 消防桌面应急预案方案(3篇)
- (2025年标准)校车修理协议书
- 服装厂 安全生产管理制度
- 2025年山东省教育厅直属事业单位招聘18人笔试模拟试题带答案详解
- 2025年汽车驾驶员(高级)考试题及汽车驾驶员(高级)试题及答案
- 2025年“艾梅乙”母婴阻断培训试题(附答案)
- 2025年中小学体育教师招聘考试专业基础知识考试题库及答案(共2687题)
- Unit1SectionA1a-1c课件-人教版九年级英语全册
- 360上网行为管理系统产品白皮书
- 2025年全国中小学校党组织书记网络培训示范班在线考试题库及答案
- 酒店股东消费管理办法
评论
0/150
提交评论