SCPI encabulator to keep the trigger time shifted inside display - Rigol DS1054 - Page 1
Forum section: electronics / projects

author: RoGeorge
author_rank: Super Contributor
timestamp: May 21, 2022, 06:24:05 pm
content: Usually we look at an oscilloscope trace at the part coming after the trigger point, not before.The DS1054Z oscilloscope from Rigol likes to put the trigger moment in the middle of the screen, thus wasting the first half of the display with something not needed.The trigger point can be shifted left/right manually, but any time base zoom is calculated relative to the center of the screen. As an effect to this, unless the trigger point is in the center then any change in the time base will also move the position of the trigger point relative to the screen. Often the trigger point will lend outside of the screen area.Would be nice to have the trigger point always fixed in the same position relative to the screen.This is what this script does. It reads the time base, then adjusts the trace position to always start from the place on the screen. It does that at each 2 seconds. If the time base of the oscilloscope is changed, then the trigger moment will be brought in the screen at the same position it was before.The oscilloscope was connected by LAN. Replace the IP address with the address of your instrument. Tested with Kubuntu 20.04 LTS, Python 3, pyvisa and PySimpleGUI. Should work the same for Windows, but I only tested in Kubuntu.The program can be controlled by mouse or keyboard (the arrow keys, Enter and Escape), and it looks like this:Dependencies to install:Code:pip install pyvisa-pypip install pysimpleguisudo apt-get install python3-tkPython script to run:Code:import PySimpleGUI as sg# docs at pysimplegui dot orgimport pyvisa as visa# connect to ds1054zIP_address = '192.168.1.3'try:rm = visa.ResourceManager()ds1054z = rm.open_resource('TCPIP::' + IP_address + '::INSTR')answer = ds1054z.query('*IDN?')answer = answer.replace(answer.split(','), 'DS1Z_7654321_')# the SCPI commands list for DS1000Z can be found at# https://beyondmeasure.rigoltech.com/acton/attachment/1579/f-0386/1/-/-/-/-/DS1000Z_Programming%20Guide_EN.pdfexcept:answer = 'ERROR: Could not connect.'# GUIlayout = [[sg.Frame('Trigger point position in the oscillosope screen (divs from center)',[[sg.Slider((-6,6), key= '-DIVS-', enable_events=True, default_value=-5, orientation='h', expand_x= True)]],expand_x= True)],[sg.Button('Exit (Esc)', key= '-EXIT-', expand_x= True)],[sg.Text(answer, key= '-ANSWER-', expand_x= True)]]window = sg.Window('DS1000Z Trigger Mover', layout, finalize= True)window.bind('<Escape>', '-ESCAPE-')window.bind('<Up>', '-UARROW-')window.bind('<Down>', '-DARROW-')window.bind('<Left>', '-LARROW-')window.bind('<Right>', '-RARROW-')while True:event, values = window.Read(timeout= 2000)if event in (sg.WIN_CLOSED, '-EXIT-', '-ESCAPE-'):break# react to arrow keysif event in ('-UARROW-', '-RARROW-'):values['-DIVS-'] += 1window['-DIVS-'].update(values['-DIVS-'])if event in ('-DARROW-', '-LARROW-'):values['-DIVS-'] -= 1window['-DIVS-'].update(values['-DIVS-'])# find the current timebase and set the trigger display offsetanswer = ds1054z.query(':TIMebase:SCALe?')ds1054z.write(':TIMebase:OFFSet ' + str(-values['-DIVS-'] * float(answer)))# byeds1054z.close()rm.close()window.Close()