%创建
t = tcpip('sonytekawg.yourdomain.com',4000);



%创建缓存区
set(t,'OutputBufferSize',3000)



%连接
fopen(t)



%设置读写
set(t,'ByteOrder','littleEndian')



%生成发送数据
x = (0:499).*8*pi/500;
data = sin(x);
marker = zeros(length(data),1);
marker(1) = 3;


%告诉对方发送格式
fprintf(t,'%s',['MMEMORY:DATA "sin.wfm",#42544MAGIC 1000' 13 10])
fprintf(t,'%s','#42500')




%发送数据
for (i = 1:length(data)),
fwrite(t,data(i),'float32');
fwrite(t,marker(i));
end


%设置频率
fprintf(t,'%s',['CLOCK 1.0000000000e+008' 13 10 10])


%关闭
fclose(t)
set(t,'InputBufferSize',3000)




%重新打开
fopen(t)


%读取数据
fprintf(t,'MMEMORY:DATA? "sin.wfm" ')
data = fread(t,t.BytesAvailable);


%The next set of commands reads the same waveform as a float32 array. To begin, write the waveform to the AWG.
fprintf(t,'MMEMORY:DATA? "sin.wfm" ')


%Read the file header as ASCII characters.
header1 = fscanf(t)
% header1 =
%42544MAGIC 1000


%Read the next six bytes, which specify the length of data.
header2 = fscanf(t,'%s',6)
% header2 =
% #42500


%Read the waveform using float32 precision and read the markers using uint8 precision. Note that one float32 value consists of four bytes. Therefore, the following commands read 2500 bytes.
data = zeros(500,1);
marker = zeros(500,1);
for i = 1:500,
data(i) = fread(t,1,'float32');
marker(i) = fread(t,1,'uint8');
end


%Read the remaining data, which consists of clock information and termination characters.
clock = fscanf(t);
cleanup = fread(t,2);


%Disconnect and clean up — When you no longer need t, you should disconnect it from the host, and remove it from memory and from the MATLAB workspace.
fclose(t)
delete(t)
clear t
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐