📄 test.m
字号:
huipushtool3=uipushtool('tooltipstring','通道3',... %建立push3工具栏。
'CData',imread('3.jpg'));
huipushtool4=uipushtool('tooltipstring','通道4',... %建立push4工具栏。
'CData',imread('4.jpg'));
huipushtool5=uipushtool('tooltipstring','通道5' ,... %建立push5工具栏。
'CData',imread('5.jpg'));
huipushtool6=uipushtool('tooltipstring','通道6',... %建立push6工具栏。
'CData',imread('6.jpg'));
huipushtool7=uipushtool('tooltipstring','通道7' ,... %建立push7工具栏。
'CData',imread('7.jpg'));
huipushtool8=uipushtool('tooltipstring','通道8',... %建立push8工具栏。
'CData',imread('8.jpg'));
%下面这一段程序是用来建立控件和确定坐标轴的大小。
htext1=uicontrol(hmainfig,'style','text','position',[0.04,0.82,0.05,0.05],... %建立一个静态文本框用来显示测量单位(左上)。
'backgroundcolor',[0.8,0.8,0.8],'string','单位',...
'foregroundcolor','magenta','tag','htext1');
setappdata(hmainfig,'htext1',htext1);
htext2=uicontrol(hmainfig,'style','text','position',[0.04,0.38,0.05,0.05],... %建立一个静态文本框用来显示测量单位(左下)。
'backgroundcolor',[0.8,0.8,0.8],'string','',...
'foregroundcolor','magenta','tag','htext2');
setappdata(hmainfig,'htext2',htext2);
htext5=uicontrol(hmainfig,'style','text','position',[0.93,0.82,0.06,0.05],...
'backgroundcolor',[0.8,0.8,0.8],'string','',...
'tag','htext5');
setappdata(hmainfig,'htext5',htext5);
htext55=uicontrol(hmainfig,'style','text','position',[0.93,0.77,0.05,0.05],...
'backgroundcolor',[0.8,0.8,0.8],'string','',...
'foregroundcolor','blue','tag','htext55');
setappdata(hmainfig,'htext55',htext55);
htext6=uicontrol(hmainfig,'style','text','position',[0.93,0.38,0.06,0.05],...
'backgroundcolor',[0.8,0.8,0.8],'string',':',...
'tag','htext6');
setappdata(hmainfig,'htext6',htext6);
htext66=uicontrol(hmainfig,'style','text','position',[0.93,0.33,0.05,0.05],...
'backgroundcolor',[0.8,0.8,0.8],'string','',...
'foregroundcolor','blue','tag','htext66');
setappdata(hmainfig,'htext66',htext66);
htext21=uicontrol(hmainfig,'style','text','string','X:','backgroundcolor',[0.8 0.8 0.8],... %建立一个静态文本框用来显示“X:”。
'position',[0.15,0.96,0.08,0.04]);
setappdata(hmainfig,'htext21',htext21); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
htext22=uicontrol(hmainfig,'style','text','string','0.000','backgroundcolor',[0.8 0.8 0.8],... %建立一个静态文本用来显示当前点的横坐标。
'foregroundcolor','blue',...
'position',[0.20,0.96,0.08,0.04],'tag','htext22');
setappdata(hmainfig,'htext22',htext22);
htext31=uicontrol(hmainfig,'style','text','string','Y:','backgroundcolor',[0.8 0.8 0.8],... %建立一个静态文本用来显示“Y:"。
'position',[0.15,0.91,0.05,0.04]);
setappdata(hmainfig,'htext31',htext31);
htext32=uicontrol(hmainfig,'style','text','string','0.000','backgroundcolor',[0.8 0.8 0.8],... %建立一个静态文本用来当前点的纵坐标。
'foregroundcolor','red',...
'position',[0.20,0.91,0.08,0.04],'tag','htext32');
setappdata(hmainfig,'htext32',htext32);
htext41=uicontrol(hmainfig,'style','text','string','第','backgroundcolor',[0.8,0.8,0.8],... %建立一个静态文本框用来显示”第“。
'fontweight','bold','fontsize',13,...
'horizontalalignment','right',...
'position',[0.4,0.91,0.05,0.06]);
setappdata(hmainfig,'htext41',htext41);
htext42=uicontrol(hmainfig,'style','text','string','1','backgroundcolor',[0.8,0.8,0.8],... %建立一个静态文本用来显示当前是第几通道。
'fontweight','bold','fontsize',13,...
'position',[0.45,0.91,0.04,0.06]);
setappdata(hmainfig,'htext42',htext42);
htext43=uicontrol(hmainfig,'style','text','string','通道','backgroundcolor',[0.8,0.8,0.8],... %建立一个静态文本用来显示”通道“两字。
'fontweight','bold','fontsize',13,...
'horizontalalignment','left',...
'position',[0.49,0.91,0.08,0.06]);
setappdata(hmainfig,'htext43',htext43);
htext23=uicontrol(hmainfig,'style','text','string','温度:','backgroundcolor',[0.8 0.8 0.8],... %建立一个静态文本框用来显示“温度:”。
'position',[0.35,0.96,0.05,0.04]);
setappdata(hmainfig,'htext23',htext23); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
htext24=uicontrol(hmainfig,'style','text','string', num2str(tmp1),'backgroundcolor',[0.8 0.8 0.8],... %建立一个静态文本用来显示返回的温度值。
'foregroundcolor','blue',...
'position',[0.40,0.96,0.08,0.04],'tag','htext24');
setappdata(hmainfig,'htext24',htext24);
%下面这段程序是定义子菜单quit的对话框,用来提示用户。
set(hmenu15,'callback',...
['q=questdlg(''你确定要退出这个界面吗?别忘了存盘!'',''关闭'',''Yes'',''No'',''Yes'');',...
' if strcmp(q,''Yes'')',...
'delete(hmainfig);',...
' else',...
'return;',...
' end']);
% M-code for communicating with an instrument.
% create a serial port object.
obj1 = instrfind('Type', 'serial', 'Port', 'COM1', 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial('COM1');
else
fclose(obj1);
obj1 = obj1(1) ;
end
%下面这三行程序是用来对串口的属性进行设置,包括对比特率的设置,输入输出缓冲区的大小等等进行设置。
set(obj1,'BaudRate',38400,'FlowControl','hardware','Timeout',50) ;
set(obj1,'Inputbuffersize',4096,'Outputbuffersize',4096,'parity','none','databits',8,'stopbits',1);
%下面这句是设置终止符,ASCII码为10的字符是换行符(\n)。
set(obj1,'Terminator',10);
%打开串口
fopen(obj1);
y=1;
indata=[0 0]; %定义一个数组,用来接收串口发送过来的原始数据。
data=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
m=[0 0 0 0 0 0 0 0]; %定义一个数组,用来存放最新接收的8个数据。
%for j=1:16 %每个通道先接收2个数据,并用这两个数据来画出8个曲线。
% for i=1:2
% indata(i)=fscanf(obj1,'%',1);
%if indata(i)>97 %根据其ASCII码来进行相应的处理,以得到其相应的数值。
% indata(i)=indata(i)-87;
% else
% indata(i)=indata(i)-48;
% end
% end
% data(j)=indata(1).*16+indata(2); %将十六进制数据变成十进制的BCD码的数据。
%data(j)=data(j).*1/51;
% end
a1=[1,data(1);2,data(9)]; %定义8个数组,并且这个数组的元素就是由data的元素组成。
ct=datestr(now); %以下这一大段程序是对数据进行保存的,把数据分别保存成8个文件。
tt=' 你开始测的时间是: ';
tt=strcat(tt,ct); %每个文件名都是以通道名和该时刻的时间合并的字符串作为文件名。
dt=datestr(ct,30);
dt=strcat(dt,'.txt');
str1=strcat('1通道_',dt); %这段代码自我感觉很好,非常具有创新精神,在此表扬一下自己,再接再励。
fid1=fopen(str1,'at+');
fprintf(fid1,' 你好,这是第一通道的数据\n\n');
fprintf(fid1,tt);
fprintf(fid1,'\n\n');
fprintf(fid1,' %g %1.4g\n',a1');
fclose(fid1);
haxes1=axes('box','on','units','normalized','position',[0.12,0.1,0.8,0.78],'tag','haxes1');
hline1=plot(1:2,a1(:,2));
set(hline1,'markersize',10,'erasemode','none');
axis([0 1000 0 5]);
hold on;
grid on;
set(gcf,'currentaxes',haxes1);
hcurrent=haxes1;
hresult=hline1;
movegui(hmainfig,'center');
set(hmainfig,'visible','on');
set(hmainfig,'windowbuttondownfcn',...
['p=get(gca,''currentpoint'');',...
'global hmainfig;',...
'htext22=getappdata(hmainfig,''htext22'');',...
'htext32=getappdata(hmainfig,''htext32'');',...
'set(htext22,''string'',num2str(p(1)));',...
' set(htext32,''string'',num2str(p(3)));']);
allaxes=[haxes1];
allline=[hline1];
setappdata(hmainfig,'allaxes',allaxes);
setappdata(hmainfig,'allline',allline);
while 1
equation(1)=str2num(hinput2.equation1);
% for n=1:8
% for k=1:2
% indata(k)=fscanf(obj1,'%c',1);
% if indata(k)>97
% indata(k)=indata(k)-87;
% else
% indata(k)=indata(k)-48;
% end
% end
% m(n)=indata(1).*16+indata(2);
% m(n)=m(n)*equation(n);
% m(n)=m(n).*1/51;
%
% end
tmp1=tmp1+1;
if tmp1 > 100
tmp1 = 0;
end
%temp = num2str(tmp1);
b1=[y+2,m(1)];
fid1=fopen(str1,'at+');
fprintf(fid1,' %g %1.4g\n',b1);
fclose(fid1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -