【发布时间】:2019-07-19 00:45:12
【问题描述】:
我无法通过 Matlab 中的仪器控制工具箱将任意波形上传到 DS345 函数发生器。
我已使用提供的手册here(参见第 3-8 页)来尝试实现此目的。我使用的代码是:
%% Instrument Control of DS345 Signal Generator
clear all
clc
COMtype = 'COM4';
% Find the a serial port object
obj1 = instrfind('Type', 'serial', 'Port', COMtype , 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial(COMtype);
else
fclose(obj1);
obj1 = obj1(1);
end
N = 512;
Sum = 0;
number = 10;
data = zeros(number,1);
X = zeros(number,1);
Y = zeros(number,1);
obj1.OutputBufferSize = N;
fopen(obj1);
checkConnection =strcat( query(obj1,'*IDN?') );
if strcmp(checkConnection,'StanfordResearchSystems,DS345,43862,1.04') ~=1
disp(['Device Connection not working... Query msg ' ...
checkConnection])
else
disp(['Connection to ' checkConnection(25:29) ' established.'])
end
% Generating Function
for i = 1:number
X(i) = 1*i;
Y(i) = 0;
data(2*i-1) = i;
data(2*i) = 0; %8*i*(-1 + 2*(mod(i,2)));
Sum = Sum + (data(2*i-1) + data(2*i));
end
figure(1)
plot(X,Y)
grid minor
checksumdata = sum(data);
data(2*number+1) = checksumdata;
% size(data)
% convert into 16-bit binary array
data = int16(data);
dataBin = dec2bin(data,16);
checkLDWF = strcat(query(obj1,['LDWF? 1,' num2str(2*number)]));
if checkLDWF =='1'
disp('Ready to Download...')
end
pause(1)
disp('downloading...')
disp('sending DataBin...')
fwrite(obj1,dataBin,'short','async')
stopasync(obj1)
fclose(obj1);
在代码中,我生成了一个直线数组,我想上传一个任意矢量波形,这意味着使用 LDWF 命令。 手册建议我应该发送 16 位二进制数据,后跟校验和,校验和只是数据数组的总和。
我得到的错误是“加载错误...”,这意味着它已经等待了 10 秒的数据流并且没有任何东西到达。所以它因“加载错误”而超时。将不胜感激任何可能的帮助/指导。
【问题讨论】:
-
你从哪里得到加载错误?也许您可以发布脚本的完整输出日志。阅读手册我猜是在你上传数据点的最后。
-
据我所知没有输出日志。错误发生在 DS345 函数发生器上。是的,它在 fwrite 命令之后