声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4403|回复: 2

[LabView] 一段使用matlab对示波器控制的程序,希望能对一些兄弟有用

[复制链接]
发表于 2008-8-3 16:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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 编辑 ]
回复
分享到:

使用道具 举报

发表于 2008-11-8 11:00 | 显示全部楼层
??? Error using ==> visa.visa
Invalid RSRCNAME specified. Type 'instrhelp visa' for more information.

弱弱问下,是不是还需要硬件支持?没搞这个这东西,只是想找个现成的例子
 楼主| 发表于 2008-11-28 00:35 | 显示全部楼层

回复 沙发 花如月 的帖子

这个是示波器、电脑同时安装visa,
之间用双头网线互联。
示波器的网址设成192.168.0.110
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-28 17:36 , Processed in 0.069291 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表