?? test.m
字號(hào):
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'));
%下面這一段程序是用來建立控件和確定坐標(biāo)軸的大小。
htext1=uicontrol(hmainfig,'style','text','position',[0.04,0.82,0.05,0.05],... %建立一個(gè)靜態(tài)文本框用來顯示測量單位(左上)。
'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],... %建立一個(gè)靜態(tài)文本框用來顯示測量單位(左下)。
'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],... %建立一個(gè)靜態(tài)文本框用來顯示“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],... %建立一個(gè)靜態(tài)文本用來顯示當(dāng)前點(diǎn)的橫坐標(biāo)。
'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],... %建立一個(gè)靜態(tài)文本用來顯示“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],... %建立一個(gè)靜態(tài)文本用來當(dāng)前點(diǎn)的縱坐標(biāo)。
'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],... %建立一個(gè)靜態(tài)文本框用來顯示”第“。
'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],... %建立一個(gè)靜態(tài)文本用來顯示當(dāng)前是第幾通道。
'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],... %建立一個(gè)靜態(tài)文本用來顯示”通道“兩字。
'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],... %建立一個(gè)靜態(tài)文本框用來顯示“溫度:”。
'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],... %建立一個(gè)靜態(tài)文本用來顯示返回的溫度值。
'foregroundcolor','blue',...
'position',[0.40,0.96,0.08,0.04],'tag','htext24');
setappdata(hmainfig,'htext24',htext24);
%下面這段程序是定義子菜單quit的對(duì)話框,用來提示用戶。
set(hmenu15,'callback',...
['q=questdlg(''你確定要退出這個(gè)界面嗎?別忘了存盤!'',''關(guān)閉'',''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
%下面這三行程序是用來對(duì)串口的屬性進(jìn)行設(shè)置,包括對(duì)比特率的設(shè)置,輸入輸出緩沖區(qū)的大小等等進(jìn)行設(shè)置。
set(obj1,'BaudRate',38400,'FlowControl','hardware','Timeout',50) ;
set(obj1,'Inputbuffersize',4096,'Outputbuffersize',4096,'parity','none','databits',8,'stopbits',1);
%下面這句是設(shè)置終止符,ASCII碼為10的字符是換行符(\n)。
set(obj1,'Terminator',10);
%打開串口
fopen(obj1);
y=1;
indata=[0 0]; %定義一個(gè)數(shù)組,用來接收串口發(fā)送過來的原始數(shù)據(jù)。
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]; %定義一個(gè)數(shù)組,用來存放最新接收的8個(gè)數(shù)據(jù)。
%for j=1:16 %每個(gè)通道先接收2個(gè)數(shù)據(jù),并用這兩個(gè)數(shù)據(jù)來畫出8個(gè)曲線。
% for i=1:2
% indata(i)=fscanf(obj1,'%',1);
%if indata(i)>97 %根據(jù)其ASCII碼來進(jìn)行相應(yīng)的處理,以得到其相應(yīng)的數(shù)值。
% indata(i)=indata(i)-87;
% else
% indata(i)=indata(i)-48;
% end
% end
% data(j)=indata(1).*16+indata(2); %將十六進(jìn)制數(shù)據(jù)變成十進(jìn)制的BCD碼的數(shù)據(jù)。
%data(j)=data(j).*1/51;
% end
a1=[1,data(1);2,data(9)]; %定義8個(gè)數(shù)組,并且這個(gè)數(shù)組的元素就是由data的元素組成。
ct=datestr(now); %以下這一大段程序是對(duì)數(shù)據(jù)進(jìn)行保存的,把數(shù)據(jù)分別保存成8個(gè)文件。
tt=' 你開始測的時(shí)間是: ';
tt=strcat(tt,ct); %每個(gè)文件名都是以通道名和該時(shí)刻的時(shí)間合并的字符串作為文件名。
dt=datestr(ct,30);
dt=strcat(dt,'.txt');
str1=strcat('1通道_',dt); %這段代碼自我感覺很好,非常具有創(chuàng)新精神,在此表揚(yáng)一下自己,再接再勵(lì)。
fid1=fopen(str1,'at+');
fprintf(fid1,' 你好,這是第一通道的數(shù)據(jù)\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);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -