Controling a Tektronix Oscilloscope Model: DPO5204B-5RL

3 visualizaciones (últimos 30 días)
William Grefe
William Grefe el 20 de Sept. de 2016
Respondida: Walter Roberson el 21 de Sept. de 2016
I am having problems with using num2str with controlling the scope. I am not getting the correct setting. When I put the number directly in without num2str everything works. Is there a bug.
Code sample of what I am having errors with.
%fprintf(myScope,strcat('HORIZONTAL:MODE:SCAle ',num2str(5e-4))); % Sets the Time/Division
a=num2str(.5e-3)
fprintf(myScope,strcat('HORizontal:MODE:SCAle ',num2str(a))); % Sets the Time/Division
fprintf(myScope,strcat('HORIZONTAL:MODE:SAMPLERATE 1e9'));
fprintf(myScope,strcat('HORizontal:MODE:RECOrdlength 5*1e6'));
%fprintf(myScope,strcat('HORizontal:MODE:SCAle ',num2str(Time_Division*1e-3))); % Sets the Time/Division
%fprintf(myScope,strcat('HORIZONTAL:MODE:SAMPLERATE ',num2str(Sample_Rate*1e6))); % Sets the Sample_Rate
%fprintf(myScope,strcat('HORIZONTAL:MODE:SAMPLERATE 5e6'));
%fprintf(myScope,strcat('HORIZONTAL:MODE:SAMPLERATE?'))
%fprintf(myScope,strcat('HORizontal:MODE:RECOrdlength ',num2str(Record_Length*1e6))); % Sets the Record_Length
Below is the full program
% Program Name: Instrument Program
% Program Date: 8/11/2016
% Program Version: 1.0
% Written By: William K. Grefe M.S.
% Required Software & Software Version that the program has been verified with
% MATLAB Version 9.0 (R2016a)
% Instrument Control Toolbox Version 3.9 (R2016a)
% Signal Processing Toolbox Version x.xx (R2016a)
% Works with the Following Hardware
% Tektronix Oscilloscope Model: DPO5204B-5RL driver has been written to be used in this code
% Instrument Program Description:
% Automatically connects to the Oscilloscope,sets up the parameters, saves
% data to a file on the computer that it is connected to.
%
% clrdevice % clrdevice
% fopen % Connect interface object to instrument
% set % Configure or display instrument object properties
%doc oscilloscope
% Set Time Division (msec/div)
% Read Time Division (msec/div) and write into excel
% Set Sample Rate (MHz)
% Read Sample Rate (MHz) and write into excel
% Read and write Record Length (M) into excel
% Program Name: Configuration
% Program Date: 8/30/2016
% Program Version: 1.0
% Written By: William K. Grefe M.S.
% Required Software & Software Version that the program has been verified with
% MATLAB Version 9.0 (R2016a)
% Instrument Control Toolbox Version 3.9 (R2016a)
% Signal Processing Toolbox Version 7.2 (R2016a)
% Works with the Following Hardware
% Tektronix Oscilloscope Model: DPO5204B-5RL driver has been written to be used in this code
% Configuration:
% Reads the configuration Excel File sets up the instrument and then after
% the test auto populates the analysis file
filename='Scope_Configuration.xlsx';
sheet=1; % Sheet # that data is being read from
Row_to_Read=2;
xlRange=strcat('B',num2str(Row_to_Read)); % Cell # that data is being read from
[~,~,raw]=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
Laser_Model=raw;
xlRange=strcat('C',num2str(Row_to_Read)); % Cell # that data is being read from
[~,~,raw]=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
Laser_Power=raw; % Reads the configuration data from an excel file
xlRange=strcat('D',num2str(Row_to_Read)); % Cell # that data is being read from
[~,~,raw]=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
Oscilloscope_Model=raw;
xlRange=strcat('E',num2str(Row_to_Read)); % Cell # that data is being read from
Time_Division=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
Time_Division
xlRange=strcat('F',num2str(Row_to_Read)); % Cell # that data is being read from
Sample_Rate=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
Sample_Rate
xlRange=strcat('G',num2str(Row_to_Read)); % Cell # that data is being read from
Record_Length=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
Record_Length
xlRange=strcat('K',num2str(Row_to_Read)); % Cell # that data is being read from
Slot_Width=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
xlRange=strcat('L',num2str(Row_to_Read)); % Cell # that data is being read from
L_Bits_Per_Pulse=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
xlRange=strcat('M',num2str(Row_to_Read)); % Cell # that data is being read from
[~,~,raw]=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
Sequence=raw;
xlRange=strcat('N',num2str(Row_to_Read)); % Cell # that data is being read from
SET_PRF=xlsread(filename,sheet,xlRange); % Reads the configuration data from an excel file
instrreset
visaAddress = 'TCPIP::169.254.28.185::INSTR'; % Setting the ip address.
myScope = visa('tek', visaAddress);
myScope.InputBufferSize = 1024;
% Set the |ByteOrder| to match the requirement of the instrument
myFgen.ByteOrder = 'littleEndian';
% Open the connection to the oscilloscope
fopen(myScope);
% Reset the oscilloscope to a known state
fprintf(myScope, '*RST');
fprintf(myScope, '*CLS');
% Turn headers off, this makes parsing easier
fprintf(myScope, 'HEADER OFF');
% Autoset the oscilloscope
%fprintf(myScope, 'AUTOS EXECute');
% Ensure that the start and stop values for CURVE query match the full
% record length
fprintf(myScope, ['DATA:START 1;DATA:STOP ' Record_Length*1e6]);
% Automatically configuring the instrument
fprintf(myScope,['SELECT:CH1 ON']); % Enabling Channel 1
fprintf(myScope,['SELECT:CH2 ON']); % Enabling Channel 2
fprintf(myScope,['SELECT:CH3 OFF']); % Disabling Channel 3
fprintf(myScope,['SELECT:CH4 OFF']); % Disabling Channel 4
% What are the vertical channel settings the voltage range for the channel
% 1 and channel 2 volts per division
% What the trigger level is set to 1 to 2 volts on rising edge channel 1
%fprintf(myScope,strcat('HORIZONTAL:MODE:SCAle ',num2str(5e-4))); % Sets the Time/Division
a=num2str(.5e-3)
fprintf(myScope,strcat('HORizontal:MODE:SCAle ',num2str(a))); % Sets the Time/Division
fprintf(myScope,strcat('HORIZONTAL:MODE:SAMPLERATE 1e9'));
fprintf(myScope,strcat('HORizontal:MODE:RECOrdlength 5*1e6'));
%fprintf(myScope,strcat('HORizontal:MODE:SCAle ',num2str(Time_Division*1e-3))); % Sets the Time/Division
%fprintf(myScope,strcat('HORIZONTAL:MODE:SAMPLERATE ',num2str(Sample_Rate*1e6))); % Sets the Sample_Rate
%fprintf(myScope,strcat('HORIZONTAL:MODE:SAMPLERATE 5e6'));
%fprintf(myScope,strcat('HORIZONTAL:MODE:SAMPLERATE?'))
%fprintf(myScope,strcat('HORizontal:MODE:RECOrdlength ',num2str(Record_Length*1e6))); % Sets the Record_Length
% Clean up Close the connection
fclose(myScope);
% Clear the variable
clear myScope;

Respuestas (2)

Vinod Cherian
Vinod Cherian el 21 de Sept. de 2016
Editada: Vinod Cherian el 21 de Sept. de 2016
The fact that it works when you have actual numbers tells me this is not so much an instrument issue as it is a code issue. It is really difficult to parse your post because of the formatting, so I can't be sure this is what it is.
My recommendation to debug the issue you are seeing is to execute each line of code, one line at a time, and see which line causes an error.
PS: To make the post readable, consider using the {}code button to denote what parts of your posting is code.

Walter Roberson
Walter Roberson el 21 de Sept. de 2016
I really recommend that you use fprintf format specifiers to do the conversion so you will know exactly how they will be converted. For example,
a = .5e-3;
fprintf(myScope,'HORizontal:MODE:SCAle %0.4f\n', a); % Sets the Time/Division
Have an closer look at your current code:
a=num2str(.5e-3)
fprintf(myScope,strcat('HORizontal:MODE:SCAle ',num2str(a))); % Sets the Time/Division
On the first of those two lines you make a a string with the representation of 0.5e-3, and in the second of those two lines you tell it to use num2str() on what is already a string. Testing, it appears that the second num2str() will leave the string unchanged, but can you be sure?
What number formats does the device accept? How many decimal places? Easiest to code the % format to fit the exact requirement.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by