Programming the Tektronix TDS 340 100MHz digital storage oscilloscope

5.00 avg. rating (94% score) - 1 vote

In my previous article I provided some information on the Tektronix TDS 340 100 MHz digital storage oscilloscope and instructions on how to install the Option 14 card to get VGA output and support for hard copy. This article will provide some further information on interfacing the oscilloscope with a computer using the RS-232 port to retrieve raw signal data and share some of my interesting findings.

Using the serial interface

The oscilloscope serial port must first be configured inside the Utility>System I/O menu and a cross-over serial cable is needed to connect the oscilloscope to the PC. It is best to turn off both hardware and software handshaking as they are not going to help much and will just cause problems. The recommended serial settings are 19200bps, 8 data bits, no parity, 1 stop bit and carriage-return (CR) line ending.

To check if the connection is working, use a terminal software such as Tera Term Web 3.1, configure it to echo characters locally with CR line ending, and type ID? followed by the ENTER key to ask the oscilloscope to return its identifier string, which should look like:

TEK/TDS340,CF:91.1CT,FV:v1.00
   
Commands are case-insensitive and multiple commands or responses are separated by a line ending character (CR, LF or CR/LF as configured). Commands ending with a question mark (?) are queries and a response from the oscilloscope is to be expected. Commands not ending with a question mark will simply be executed by the oscilloscope with no value returned. To check if there are any errors during command execution, use the following:

*ESR?   // Show the value of the Event Status Register
ALLE?   // Return the error log, which will show any errors with the commands previously sent

The following command set, extracted from the programmer manual, measures the frequency of the input signal at channel 1:

MEASU:IMM:SOURCE CH1  // Set measurement source to Channel 1
MEASU:IMM:TYPE FREQ   // Measure the signal frequency
MEASU:IMM:VAL?        // Get the measurement value

If the probe of channel 1 is connected to the 1kHz calibration point in front of the oscilloscope, the above command set would return a value of approximately 1.0000E3, indicating a frequency of 1000Hz.

Retrieving raw waveform data

Command CURV? is used to ask the oscilloscope for the raw measurement data of the waveform being displayed. The following code will return all 1000 data points in the oscilloscope data acquisition memory:

DAT:SOU CH1     // Measurement source to Channel 1
DAT:ENC ASCI    // ASCII format
DAT:WID 2       // 2 bytes data width
DAT:STAR 1      // first data point
DAT:STOP 1000   // last data point (1000th)           
CURV?           // get waveform data

The response will be a set of comma separated integers:

22784,23040,-6656,[…..],-6656,23040

The range of each returned integer value is –128 to 127 when DAT:WID is 1. Zero is center screen. The range is –32768 to 32767 when DAT:WID is 2. The upper limit is one division above the top of the screen and the lower limit is one division below the bottom of the screen.

To properly interpret the data, it will be useful to know the oscilloscope settings via the WFMPR? command, which will return the following:

2;16;ASC;RP;MSB;”Ch1, DC coupling, 2.0E0 V/div, 5.0E-4 s/div, 1000 points, Sample mode”;1000;Y;”s”;1.0E-5;500;”Volts”;3.125E-4;1.28E4;0.0E0

Among the returned values, the voltage per division, the time per division and sampling rate parameters (highlighted) will be needed to accurately analyze the returned data.

Taking a screenshot of the oscilloscope

A screenshot of the oscilloscope display can be captured progammatically using the following commands:

HARDC ABO           // abort any existing hard copy
HARDC:FORM BMP      // set hard copy format to bitmap
HARDC:PORT RS232    // hard copy port to RS232
HARDC STAR          // start hard copy

The image data will be sent via the serial link. Unlike other commands, there is no end of file marker for the HARDC STAR command. To identify when to stop receiving data programmatically, one way is to count the number of bytes received and compare with the expected value. As the file size could vary depending on the hard copy output settings, an easier way is to assume that the hard copy operation has ended if no data is received after a certain period, e.g. 2 seconds.

Custom PC interface software

With some free time I made a .NET application that allows the user to retrieve the frequency measurements, waveform data as well as taking a screenshot of the oscilloscope:

To use the application, first configure the serial port settings (port number, baud rate) and click on Open Port to initialize the serial interface. The Activity Log text box shows the commands sent and responses received. The Screenshot button will request for a screenshot from the oscilloscope and show it in the application. If option Show original color is checked, the application will convert the black-on-white image returned by the TDS340 to green-on-black, to make it look more like a real screenshot.The Event Log button will show all error messages currently in the oscilloscope event log.

The application is using the SerialPort component of the .NET framework.  It assumes that both hardware and software handshaking is disabled in the oscilloscope serial settings. Interestingly, even with handshaking disabled, the DTR (Data Terminal Ready) and RTS (Ready To Send) lines must be on, otherwise the oscilloscope will not respond to the data sent. This is done using the following C# code:

SerialPort1.Handshake = false;
SerialPort1.DtrEnable = true;
SerialPort1.RtsEnable = true;

Due to the asynchronous nature of the DataReceived event of the .NET SerialPort component and the limited time that I have, I did not attempt to make the application wait for all data to be received before enabling the action buttons. For this reason, you will need to wait for a while and check the activity log after pressing any button to make sure that the command has finished executing before peforming the next action, otherwise the application behavior may be unexpected.

Download the PC application here

The Visual Studio 2012 source code is included in the download package. Microsoft .NET Framework 2.0 (which is installed by default on Windows 7 or later) is required. The executable can be found in the bin folder.

Downloads for TDS 340A, TDS 360 & TDS 380 oscilloscopes:

User Manual
Technical Reference
Programmer Manual
Service Manual 

See also:
Exploring Tektronix TDS 340 100MHz digital storage oscilloscope 
Calibration and acquisition problems on Tektronix TDS 340 oscilloscope 

5.00 avg. rating (94% score) - 1 vote
ToughDev

ToughDev

A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

6 thoughts on “Programming the Tektronix TDS 340 100MHz digital storage oscilloscope

  • November 3, 2016 at 2:05 am
    Permalink

    I was enthusiast for your very good article.
    I’ve followed your article connecting my TDS340A to my laptop.
    After open port command I’ve found that no buttons (commands) sent to the instrument have an answer from it.
    If I push “hardcopy” button onto the instrument I see incrementing bytes received up a certain point in which it stops with an error “parameter not valid”.
    Can you help me to troubleshoot this?

  • ToughDev
    November 8, 2016 at 4:44 pm
    Permalink

    Hi,

    Sorry for the late reply.

    Are you using a USB to serial adapter? Make sure that your USB to serial driver is correctly installed and it can send/receive data from serial equipments properly. Being able to send but not to receive data (and vice versa) is a common problem when using USB to serial adapters.

    Also check the serial settings on both the oscilloscope and your laptop and make sure they match. Try to select a lower baudrate e.g. 9600bps and disable hardware / software handshaking. If everything is correct it should work.

    Let me know how it goes.

  • February 5, 2017 at 1:05 am
    Permalink

    Hello! Thank you for your work! You helped me a lot to deal with some problems. I bought myself the same oscilloscope with a small defect (menu is not displayed Components) first soldered adapter with DB9 to 15-pin on general schematic (without referring to the manual) and unfortunately Screen does not appear on the monitor (because of SCL SDA) problem was solved with the help of guides programmer, sent a team of bright, then the idea to write a programa that will perform terminal commands by pressing a simple button, but you have already made this!
    Once again many thanks for the interesting informative articles !!!

  • ToughDev
    February 7, 2017 at 11:03 am
    Permalink

    Hi Vyacheslav,

    Glad you find the article helpful. Let me know if you need any further info :)

  • ToughDev
    February 10, 2017 at 8:02 pm
    Permalink

    I played with a lot of floppy emulators, mostly using SD cards / USB drives to emulate 3.5″ PC floppy drives. Your link points to one of these models. The one I am currently playing with is FloppyEmu http://www.bigmessowires.com/floppy-emu/ which emulates Apple II / early Macintosh floppy drives. I bought a few weeks ago but it’s still in the packaging. When I have some time, probably next week, I will take a look and write another article about it :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>