|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
这部分matlab代码可以实现对示波器的控制。可以设置触发延迟,触发水平,采样时间,采样率,选择采样通道,说才信号都被还原成真实大小。希望对看这个的人有用啊。
关键字: matlab visa 示波器 虚拟仪器
如有使用,请注明引用。如有需要探讨,请q我
g=visa('tek', 'TCPIP::192.168.0.110::INSTR');
handles.g=g;
guidata(hObject,handles);
set(g,'inputbuffersize',200000);
fopen(g);
fprintf(g,'header off');
mt=str2double(get(handles.mainscale,'String'));
samplerat=str2double(get(handles.samplerate,'String'));
fprintf(g,'hor:main:scale %d', mt);
fprintf(g,'hor:main:samplerate %d',samplerat);
px5=query(g,'hor:main:scale?');
px6=query(g,'hor:main:samplerate?');
px5=str2double(px5);
px6=str2double(px6);
set(handles.mainscale,'string',(px5));
set(handles.samplerate,'string',(px6));
fprintf(g,'DATA:SOURCE ch1,ch2,ch3,ch4');
fprintf(g,'DATA:ENCDG SRIBINARY');
fprintf(g,'DATA WIDTH 2');
trilev=str2double(get(handles.trilevel,'String'));
fprintf(g,'hor:trig:position %d',trilev);
%选择触发信号
trigchanel=get(handles.selecttrigch,'value');
switch trigchanel
case 1
fprintf(g,'trigger:a:edge:source ch1');
case 2
fprintf(g,'trigger:a:edge:source ch2');
case 3
fprintf(g,'trigger:a:edge:source ch3');
case 4
fprintf(g,'trigger:a:edge:source ch4');
end
%设定触发电平,根据两个单选框被选中情况选择触发模式
trigtemp=get(handles.selecttri1,'value');
switch trigtemp
case 1
trigleveltemp=str2double(query(g,'trig:a:level?'));
set(handles.triglevel,'string',(trigleveltemp));
case 0
trigleveltemp=str2double(get(handles.triglevel,'String'));
fprintf(g,'trig:a:level %d',trigleveltemp);
set(handles.triglevel,'string',trigleveltemp);
end
trilev=query(g,'hor:trig:position?');
trilev=str2num(trilev);
set(handles.trilevel,'string',(trilev));
fprintf(g,'ACQUIRE:STATE OFF');
fprintf(g,'ACQUIRE:MODE NORMALSAMPLE');
fprintf(g,'ACQUIRE:STOPAFTER SEQUENCE');
fprintf(g,'ACQUIRE:STATE RUN');
while query(g,'BUSY?','%s','%e'); end;
horizLen = query(g,'HORIZONTAL:RECORD?','%s','%e');
fprintf(g,'DATA:START 1');
fprintf(g,'DATA:STOP %d',4*horizLen);
fprintf(g,'CURVE?');
%读取数据
waveform=zeros(horizLen,4);
for i=1:4
dummy_string1=fscanf(g,'%c',1);
dummy_string1=fscanf(g,'%c',1);
dummy_string2=fscanf(g,'%c',str2num(dummy_string1));
[waveform(:,i),count] = fread(g,str2num(dummy_string2)/2,'int16');
end
xttt=waveform;
sampleInterval = query(g,'WFMOUTPRE:XINCR?','%s','%e');
handles.sampleInterval=sampleInterval;
fprintf(g,'data:source ch1');
ymult1 = query(g,'WFMOUTPRE:YMULT?','%s','%e');
yoff1= query(g,'WFMOUTPRE:YOFF?','%s','%e');
yzero1 = query(g,'WFMOUTPRE:YZERO?','%s','%e');
xttt(:,1)=ymult1.*(xttt(:,1)-yoff1)-yzero1;
fprintf(g,'data:source ch2');
ymult2 = query(g,'WFMOUTPRE:YMULT?','%s','%e');
yoff2 = query(g,'WFMOUTPRE:YOFF?','%s','%e');
yzero2 = query(g,'WFMOUTPRE:YZERO?','%s','%e');
xttt(:,2)=ymult2.*(xttt(:,2)-yoff2)-yzero2;
fprintf(g,'data:source ch3');
ymult3=query(g,'WFMOUTPRE:YMULT?','%s','%e');
yoff3=query(g,'WFMOUTPRE:YOFF?','%s','%e');
yzero3=query(g,'WFMOUTPRE:YZERO?','%s','%e');
xttt(:,3)=ymult3.*(xttt(:,3)-yoff3)-yzero3;
fprintf(g,'data:source ch4');
ymult4=query(g,'WFMOUTPRE:YMULT?','%s','%e');
yoff4=query(g,'WFMOUTPRE:YOFF?','%s','%e');
yzero4=query(g,'WFMOUTPRE:YZERO?','%s','%e');
xttt(:,4)=ymult4.*(xttt(:,4)-yoff4)-yzero4;
set(handles.tabwave,'Visible','on');
set(handles.tabposition2,'Visible','off');
set(handles.addition,'Visible','off');
axes(handles.locate_face1);
drawnow;
plot([1:length(xttt(:,1))]/25,xttt(:,1));
axes(handles.locate_face2);
drawnow;
plot([1:length(xttt(:,1))]/25,xttt(:,2));
axes(handles.locate_face3);
drawnow;
plot([1:length(xttt(:,1))]/25,xttt(:,3));
axes(handles.locate_face4);
drawnow;
plot([1:length(xttt(:,1))]/25,xttt(:,4));
handles.xttt=xttt;
handles.sampleInterval=sampleInterval;
guidata(hObject,handles);
fclose(g);
delete(g);
[ 本帖最后由 1021830113 于 2008-8-3 16:37 编辑 ] |
|