Python controls Tektronix oscilloscope to capture trigger waveform

For some problems with occasional startup exceptions when switching on and off, it is necessary to capture the waveform of the abnormal situation. However, the abnormal situation is not triggered every time, so it is necessary to automatically capture the waveform and then analyze it. Here is an introduction to using python to control the Tektronix oscilloscope. Set up a single trigger and save the data after acquiring the trigger.

1: Driver installation (here we introduce the windows version of visa driver installation)

1. First, you need to install ni-visa to the driver. This is the driver for the computer to communicate with the oscilloscope. It must be installed. If you want to know more, go to Baidu. The download link is as follows:

下载NI-VISA - NI

There are two installation methods provided here. One is to download and install online, which takes up little space and requires an Internet connection. Click [Download] to do this. However, it is not particularly recommended. The installation may require other dependent environments; the other is offline installation. You need to download all the installation packages. Click [Offline Installation] to download the complete offline package, which is about 1.4G.

To install offline files, click directly on the iso file to enter the installation directory:

Click Install.exe, it may need to be updated, just click Next first.

The following interface appears to enter the installation interface. Here we only need visa driver support. Other environments and IDEs for writing programs do not need to be installed.

Then wait for the installation;

2: Oscilloscope connection

 The oscilloscope used here is Tektronix's MDO4104C. The connection methods of different oscilloscopes are basically the same. There are two ways to communicate between the computer and the oscilloscope, one is to use the USB interface, and the other is to communicate through a wired network.

If you are using a USB device, it is normal to check that this driver is available in My Computer-Management-Device Manager after USB connection, and the Tektronix oscilloscope can be controlled by the computer.

If you are using a network cable, you first need to set an IP address for the oscilloscope in the oscilloscope. The computer and the oscilloscope IP addresses communicate on the same network segment.

Ping on the computer or open the IP address of the instrument to check whether the WEB is normal. When this interface appears, the communication between the computer and the instrument is normal.

Three: python environment installation

  The python3.6 version is used here. You need to install the pyvisa library file first. You can install it in cmd or pycharm.

Check the configuration first:

>>> import pyvisa

>>> rm = pyvisa.ResourceManager()

>>> rmlist = rm.list_resources()

>>> print(rmlist)

('USB0::0x0xxxx9::xxxxxx::xxxxx:INSTR',) #Return is a tuple of USB interface.

 The above test shows that python and the instrument are successfully connected using USB. Now you can write your program.

If using TCP, the interface: TCPIP::xxx.xxx.xxx.xxx::INSTR

 Choose a more commonly used description

Connect the instrument first

 rm = pyvisa.ResourceManager()      

my_instrument = rm.open_resource(TCP_connect)

 my_instrument.write('TRIGGER:STATE?') Get the status of the oscilloscope

TRIGGER_STATE =my_instrument.read()        

print(TRIGGER_STATE)        

if TRIGGER_STATE[0] == "S": When SAVE is read, it stops after triggering.

#The following two sentences are more critical, that is to say, to stop after triggering, you need to execute these two sentences to return to the auto state before setting it to single trigger mode again.

my_instrument.write('ACQUIRE:STOPAFTER RUNSTOP')             my_instrument.write('ACQuire:STATE RUN')            

else:            

print(TRIGGER_STATE) 

After the infinite loop is captured, the waveform is then saved in an external USB flash drive:

while True:            

time.sleep(1)            

my_instrument.write('TRIGGER:STATE?')            

TRIGGER_STATE =my_instrument.read()            

if TRIGGER_STATE[0] == "S":                  

print('have triggered')                  

dt = datetime.datetime.now()                

 fileName = dt.strftime("%Y%m%d_%H%M%S")                  

my_instrument.write('SAVE:IMAGE "F:/re_%s.bmp"' %fileName)                  

time.sleep(1)                  

my_instrument.write('FILESYSTEM:READFILE "F:/re_%s.bmp"' %fileName)                  

break

Guess you like

Origin blog.csdn.net/qq_19294353/article/details/127927857