%创建
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
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