Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

Reading 6157B using Python

6514, 6517 Support
Post Reply
Posts: 2
Joined: August 27th, 2014, 2:13 am
Country: Germany

Reading 6157B using Python

Post by rockwentz » August 27th, 2014, 2:18 am


I am trying to read from 6157B through a GPIB connection. I need to control the reading using Python, LabView is not available at the moment.
If possible, I need the necessary libraries, drivers, perhaps a guide?, etc. to be able to read 6157B using Python.


Posts: 2
Joined: August 27th, 2014, 2:13 am
Country: Germany

Re: Reading 6157B using Python

Post by rockwentz » August 28th, 2014, 3:47 am

Okay, I have made a progress. I have installed NI-VISA and PyVisa for Python.

I was able to use some SCPI commands such as: *IDN? and *RST.

Still cannot figure out how to read input data. What I have made so far:

Code: Select all

import visa

rm = visa.ResourceManager()
keithley = rm.get_instrument("GPIB::27")
keithley.write("*rst; status:preset; *cls")
Any help is appreciated.

Posts: 1
Joined: September 2nd, 2014, 6:15 am
Country: Switzerland

Re: Reading 6157B using Python

Post by csoerens » September 2nd, 2014, 6:39 am

The supplementary information on the pyvisa documentation webpage helped me get started properly. Judging from the syntax, you've also found the first pages, so my suggestion is to carry on. I wasn't able to make the binary transfer work, though.

I've attached the code I'm using to initiate the 6517B for a rapid voltage sampling.


Code: Select all

import visa as pv
from pyvisa.highlevel import ascii, single, double
Initiation of instrument:

Code: Select all

#Generate resourcemanager, and initiate instrument on GPIB::24.
rm = pv.ResourceManager()
kt = rm.get_instrument('GPIB::24', values_format = ascii)
print kt.read(), 'is initiated - Prepare for vogon poetry!'
Preparing the instrument for measurement:

Code: Select all

#### Prepare for measurement

# Turn of guard shield.
kt.write('sense:voltage:guard 0')

#Disable math
kt.write('calculate:state 0')

#Disable filters and reference
kt.write('sense:voltage:average:state 0')
kt.write('sense:voltage:median:state 0')
kt.write('sense:voltage:reference:state 0')

#Fix the voltage range
kt.write('sense:voltage:range 2')

#Enable user input text shown on screen
kt.write('display:text:state 1')

#Disable zerocheck
kt.write('system:zcheck 0')

#To achieve higher resolution in the timestamps, I use relative timing
kt.write('system:tstamp:type relative')

#I'm not awfully concerned with noise from the powerline, so the sync
# is turned off. This also increases the sample rate drastically.
kt.write('system:lsync:state 0') 

#display a confirmation on the screen.
kt.write("display:text:data 'rst succesfull'")

#Setting absolute timestamps from initiation
kt.write('trace:timestamp:format absolute')

#immediate triggering
#enable and set trigger to be immediate - i.e. without delay
kt.write('trigger:source immediate')

#Quickest measurement averaging time
kt.write('voltage:nplc 0.01')

#A sufficiently high resolution is selected (6digit)
kt.write('voltage:digits 6')

#Definition of read prepare function
def readmeas(n):
    #clear internal memory
    #Select number of points and the feed control
    kt.write('trace:points ',str(n))
    kt.write('trace:feed:control next')

#Return to ordinary display
kt.write('display:text:state 0')
And finally, the actual reading and data extraction:

Code: Select all

#Turns off display - gives slight increase in sample rate.
#kt.write('display:enable 0')

#The beginning of everything. Widely regarded as a bad move.
kt.write('initiate:continuous 1')

#Reading out a list of values.
I'm furthermore using a small function to rewrap the output into a pandas dataframe, for easy handling.

I hope that helps!

Posts: 1
Joined: April 13th, 2021, 10:27 am
Country: Armenia

Re: Reading 6157B using Python

Post by aditya123 » April 13th, 2021, 10:33 am

Is this is the way to control 6517B electrometer? Actually I have a visual basic program to control the 6517B to draw the I vs V graph. But I am unable to convert it in python using tkinter window. can anyone please help me.

Post Reply

Return to “Electrometers”

Who is online

Users browsing this forum: No registered users and 1 guest