Read Waveform from Tektronix TDS 1002 Scope Using SCPI Commands
This example shows how to configure a Tektronix TDS 1002 scope and read a waveform from the scope using the scope specific SCPI commands.
Connect to the Scope
Connect a Tektronix TDS 1002 scope to your computer. On the scope, press the Utility button, then select Options followed by RS232 Setup. Set the following configuration:
EOL string to "CR/LF"
Baud to 9600
Flow control to None
Parity to None
Connect to the scope using the
serialport function. Specify the port that your scope is connected to on your computer. In this example, the port is
"COM1". Set the
BaudRate to 9600 to match what you set on the scope.
s = serialport("COM1",9600)
s = Serialport with properties: Port: "COM1" BaudRate: 9600 NumBytesAvailable: 0 Show all properties, all methods
Configure the Terminator
Terminator property for the
serialport object using
Terminator property matches the EOL string of the scope.
configureTerminator(s,"CR/LF") terminator = s.Terminator
terminator = 1×1 string "CR/LF"
Query the scope with the new
Terminator value using the SCPI Command
writeread. If your scope is connected and
Terminator is configured properly, then this returns a string that uniquely identifies the scope.
scopeID = writeread(s,"*IDN?")
scopeID = 1×1 string "TEKTRONIX,TDS 1002,0,CF:91.1CT FV:v2.12 TDS2CM:CMV:v1.04"
Configure the Channel
Configure Channel 1 of the scope using
writeline. Write the SCPI commands as ASCII terminated string data to the
serialport object. Then, confirm that Channel 1 is set as the source using
writeline(s,"HEADER OFF") writeline(s,"DATA:SOURCE CH1") scopeSource = writeread(s,"DATA:SOURCE?")
scopeSource = 1×1 string "CH1"
Set the waveform data encoding method to Most Significant Bit (MSB) transferred first, using
writeline. Confirm the encoding method using
writeline(s,"DATA:ENCDG RIBINARY"); scopeEncodingMethod = writeread(s,"DATA:ENCDG?")
scopeEncodingMethod = 1×1 string "RIB"
Get Waveform Information
Get the waveform transmission and formatting settings.
scopeWaveformPreamble = writeread(s,"WFMpre?")
scopeWaveformPreamble = 1×1 string "1;8;BIN;RI;MSB;2500;"Ch1, DC coupling, 2.0E0 V/div, 5.0E-4 s/div, 2500 points, Sample mode";Y;2.0E-6;0;-2.5E-3;"s";8.0E-2;0.0E0;0.0E0;"Volts""
Get the number of points in the waveform.
scopeNumPoints = writeread(s,"WFMpre:NR_Pt?")
scopeNumPoints = 1×1 string "2500"
Read and Plot the Waveform
Get the waveform data from the scope to MATLAB using the
"CURVE?" command and read the waveform back into MATLAB using
writeline(s,"CURVE?") scopeWaveform = readbinblock(s,"int16");
Plot the waveform.
Clear the Connection
When you are finished working with the scope, clear the