Keithley 194/194A High Speed Voltmeter driver discussion

Hey everybody.

The Keithley 194/194A High Speed Voltmeter is the predecessor for Keithley’s line of data aquisition instruments (DAQxxxx). It records 16 Bit voltage values with up to 100.000 Samples per second and 8 Bit values with up to 1 MS/s. Especially the 16 Bit mode is still of interest today as it surpasses many digital multimeters even today.

In addition to output all samples as a waveform similar to an oscilloscope, it can also perform calculations on all samples internally and return a single value instead, e.g. the RMS, integral, peak-to-peak or average value. This not only causes this instrument to belong to two different instrument classes, namely Scope and Logger, but also requiring a different handling of data transfer. While the simple ASCII data transfer works well for the return of a single value, it takes far to long to transfer all up to 32.768 16-Bit values or even all 65.536 8-Bit values as the instrument (due to its age) does not support to transfer them all in a single string like modern scopes but rather transfers them one after the other with each call of a result command via GPIB. Generously consider a transfer rate of 30 Samples per second and do the math, it ain’t pretty.

As a consequence and after discussion with the SweepMe team, I implemented a binary transfer of the RAW data by accessing the GPIB port directly and processing it within the device driver. Because the instrument natively defaults to 16-Bit values whenever possible and rounding errors when calculating the amount of samples due to the choice of input parameters, it was necessary to switch from the original concept of mathematically prediciting the bit depth of the result to rather use the included information in the result header to determine the bit depth when the result is already transfered and available in the buffer.

Before releasing this driver into Github, I would like to put it online here for discussion whether this still follows “best practise”.

Cheers,
Christian

# This Device Class is published under the terms of the MIT License.
# Required Third Party Libraries, which are included in the Device Class
# package for convenience purposes, may have a different license. You can
# find those in the corresponding folders or contact the maintainer.
#
# MIT License
#
# Copyright (c) 2025 SweepMe! GmbH (sweep-me.net)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# SweepMe! driver
# * Module: Scope
# * Instrument: Keithley 194


from pysweepme.EmptyDeviceClass import EmptyDevice
import time
import numpy as np

class Device(EmptyDevice):
    description = """<p><strong>Keithley 194/194A High Speed Voltmeter</strong></p>
                     <p>4.5/3.5 digit voltmeter with up to 1MS/s sampling rate.</p>
                     <p>This Scope module only offers the waveform capture mode for a single channel.</p>
                     <p>Use the corresponding Logger module for single value results.</p>
                    """


    def __init__(self):
        EmptyDevice.__init__(self)

        self.shortname = "Keithley194Waveform"

        self.variables = ["Time"]
        self.units = ["s"]
        self.plottype = [True] # True to plot data
        self.savetype = [True]  # True to save data
        
        self.port_manager = True
        self.port_types = ["GPIB"]

        self.port_properties = {
            "timeout": 10,
            "delay": 0.05
        }

        # measuring range
        self.ranges = {
            # Auto ranging not available in Waveform Mode
            #"Auto": "R0",
            "320 mV": "R1",
            "3.2 V": "R2",
            "32 V": "R3",
            "200 V": "R4",
        }
        
        # range scales used for calculating measurement result
        self.rangescales = {
            "320 mV": 1E-05,
            "3.2 V": 1E-04,
            "32 V": 1E-03,
            "200 V": 1E-02,
        }
        
        # choice of trigger; T26&T27 are executed on X command immediately, T6&T7 on external trigger signal, T20-23 on slope of signal
        self.triggers = {
            "Continuous (int)": "T26",
            "Single (int)": "T27",
            "Continuous (ext)": "T6",
            "Single (ext)": "T7",
            "Continuous (pos. slope)": "T20",
            "Single (pos. slope)": "T21",
            "Continuous (neg. slope)": "T22",
            "Single (neg. slope)": "T23",               
        }
        
        # filter settings
        self.filters = {
            "Off": "P0",
            "500kHz": "P1",
            "50kHz": "P2",
        }
        
        # coupling
        self.couplings = {
            "DC": "I0",
            "AC": "I1",
            "Ground": "I2",
        }
        
    def update_gui_parameters(self, parameters):
        # retrieve currently set "Trigger" setting, default to "Single (int)" if unset
        self.trigger = parameters.get("TriggerSource", "Single (int)")  
       
        # if the source signal should be used for triggering, setting the trigger level is offered additionally 
        if self.trigger.endswith("slope)"):
            new_parameters = {
            "SamplingRate": "1E+04",
            "SamplingRateType": ["Samples per s"],
            "TimeRange": ["Time range in s"],
            "TimeRangeValue": "1E-04",
            "TriggerSource": list(self.triggers.keys()),
            "TriggerLevel": 0.000,
            "Filter": list(self.filters.keys()),
            "TriggerDelay": 0.000,
        }
        else:
            new_parameters = {
            "SamplingRate": "1E+04",
            "SamplingRateType": ["Samples per s"],
            "TimeRange": ["Time range in s"],
            "TimeRangeValue": "1E-04",
            "TriggerSource": list(self.triggers.keys()),
            "Filter": list(self.filters.keys()),
            "TriggerDelay": 0.000,
        }
        
        # apply channel settings for CH1 and CH2:
        for i in range(1, 3):
            new_parameters["Channel%i" % i] = True if i == 1 else False
            new_parameters["Channel%i_Name" % i] = "CH%i" % i
            new_parameters["Channel%i_Range" % i] = list(self.ranges.keys())
            new_parameters["Channel%i_Coupling" % i] = list(self.couplings.keys())
        
        return new_parameters

    def apply_gui_parameters(self, parameters):
    
        self.trigger = parameters.get("TriggerSource", "Single (int)")
        self.srate = parameters.get("SamplingRate")
        self.acqtime = parameters.get("TimeRangeValue")
        self.trigger = parameters.get("TriggerSource")
        if self.trigger.endswith("slope)"):
            self.triggerlevel = parameters.get("TriggerLevel")
        self.filter = parameters.get("Filter")
        self.delay = parameters.get("TriggerDelay")
        self.port_string = parameters.get("Port")

        # reset measurement parameters
        self.variables = ["Time"]
        self.units = ["s"]
        self.plottype = [True]  # True to plot data
        self.savetype = [True]  # True to save data

        self.channels = []
        self.channel_names = {}
        self.channel_ranges = {}
        self.channel_couplings = {}

        # True to plot data
        self.plottype = [True]
        # True to save data
        self.savetype = [True]
        
        for i in range(1, 3):
            if parameters["Channel%i" % i]:
                self.channels.append(i)
                self.variables.append(parameters["Channel%i_Name" % i])
                self.units.append("V")
                self.plottype.append(True)
                self.savetype.append(True)
                self.channel_names[i] = parameters["Channel%i_Name" % i]
                self.channel_ranges[i] = parameters["Channel%i_Range" % i]
                self.channel_couplings[i] = parameters["Channel%i_Coupling" % i]

    def initialize(self):
        
        if len(self.channels) == 0:
            msg = "Please select one channel for recording."
            raise Exception(msg)
        elif len(self.channels) > 1:
            msg = "Please select only one channel for recording."
            raise Exception(msg)
        
        # K0 is used to enable EOI on GPIB communication and disable the holding of the bus
        self.port.write("K2X")
        
        # Data output format; sets output to binary
        self.port.write("G7X")
        
        # Clear waveform output, decrement reading buffer pointer
        self.port.write("B0X")

    def configure(self):

        # Waveform Mode; 
        # IMPORTANT: setting modes on both channels also disarmes the ADC on both
        # This makes sure that the unused channel won't feed results into the output buffer which
        # accidentially get retrieved instead of the ones from the selected channel
        self.port.write("C1XF0X")
        self.port.write("C2XF0X")
        
        # Channel
        # if channel 1 is selected, transmit selection to instrument
        if 1 in self.channels:
            # set channel 2 to external trigger to disable it
            self.port.write("C2T7X")
            #switch back to channel 1
            self.port.write("C1X")
        # if channel 2 is selected, transmit selection to instrument
        elif 2 in self.channels:
            self.port.write("C1T7X")
            self.port.write("C2X")

        # Sampling Rate (Hz)
        self.port.write("S1,%sX" % "{:.5E}".format(round(float(self.srate))))
        self.port.write("U6X")
        
        # Acquisition time (s)
        self.port.write("N1,%sX" % "{:.5E}".format(float(self.acqtime)))
        self.port.write("U5X")
        
        # Range
        # the channels list will always contain just one channel number at index position 0 so it is used as a key to select the measuring range
        self.port.write("%sX" % self.ranges[self.channel_ranges[self.channels[0]]])

        # Filter
        self.port.write("%sX" % self.filters[self.filter])
        
        # Coupling
        # uses same logic as in "Range"
        self.port.write("%sX" % self.couplings[self.channel_couplings[self.channels[0]]])
        
        # Delay
        self.port.write("W1,%sX" % self.delay)
        
        # reading buffer disabled
        self.port.write("Q0X")
        
    def unconfigure(self):
        
        # sets the trigger back to continous trigger
        self.port.write("T0X")

    def measure(self):
        
        # Trigger arming and releasing for different sources
        if self.trigger.endswith("(int)"):
            self.port.write("%sX" % self.triggers[self.trigger])
        elif self.trigger.endswith("(ext)"):
            self.port.write("%sX" % self.triggers[self.trigger])
        elif self.trigger.endswith("slope)"):
            self.port.write("%s,%sX" % (self.triggers[self.trigger], self.triggerlevel))
            
    def read_result(self):
        # retrieving the raw data over the GPIB bus
        rawdata = self.port.port.read_raw()
        # get only the first byte from the buffer to analyse header information; header is always unsigned integer 'u1'
        bitmodecheck = np.frombuffer(rawdata,dtype='u1',offset=0, count=1)
        # unpack bit number 6 which indicates 8-bit (=0) or 16-bit (=1) values
        bitmodecheckflag = np.unpackbits(bitmodecheck)[6]
        
        # the choice between 8-bit (= 1 Byte) and 16-bit (= 2 Byte) sampling values is made by the instrument depending on
        # a) sampling rate being above 100kHz (forces 8-bit instead of 16-bit)
        # b) total amount of samples above 32.768 (forces 8-bit instead of 16-bit)
        # due to rounding errors when entering sampling rate and sampling time instead of the precise amount of sampling points, we determine the used bitdepth by the headerinformation received earlier
        if bitmodecheckflag == 0:
            self.bytecount = 1
            self.bitweight = 256
        else:
            self.bytecount = 2
            self.bitweight = 1
        
        # processing binary buffer into array;
        if self.bytecount == 1:
            # convert 8-bit raw byte stream behind header bytes (6) into array using 8-bit signed integer
            voltages_received=np.frombuffer(rawdata,dtype='i1',offset=6)
        else:
            # for 16-bit values, we need to inform "frombuffer" that the data is in big endian format by setting dtype ">" integer 16-bit (2-bytes)
            voltages_received=np.frombuffer(rawdata,dtype='>i2',offset=6)
  
        # create emtpy array to process data in, identical in size to the array that contains the received data
        # warning: the array created by np.frombuffer is writeprotected; even if made writeable via certain means, it does not suit to float modifications
        self.voltages = np.zeros(len(voltages_received))
        
        for i in range(len(voltages_received)):
            # taking the bitweight of the ADC reading into account and calculate value according to programming manual
            if voltages_received[i] > 0:
                self.voltages[i] = (voltages_received[i]*self.bitweight)-32768
            if voltages_received[i] < 0:
                self.voltages[i] = (voltages_received[i]*self.bitweight)+32768
            # the range to be used for scaling depends on the selected channel
            if 1 in self.channels:
                self.voltages[i]=float(self.voltages[i])*self.rangescales[self.channel_ranges[1]]
            else:
                self.voltages[i]=float(self.voltages[i])*self.rangescales[self.channel_ranges[2]]
        # generate linear time array FROM, TO, STEPSAMOUNT
        self.timecode = np.linspace(0, float(self.acqtime), len(self.voltages))

    def call(self):
        return [self.timecode] + [self.voltages]

1 Like

Hello Christian,

thanks for contributing another driver!
I had already created a pull request to the instrument-drivers repo here: Keithley194 by franz-sweepMe · Pull Request #195 · SweepMe/instrument-drivers · GitHub

I did some minor changes to the GUI parameter functions, but other than that the driver looks well written.

2 Likes

Hi Franz.

Thanks for the modifications, they are sensible and I learned something new as well (the trailed “if” statement was unfamiliar to me).

Regarding Gemini’s critical comment ( Keithley194 by franz-sweepMe · Pull Request #195 · SweepMe/instrument-drivers · GitHub ): no, it is all OK. The way in which the Keithley outputs the values requires this calculation and it is stated so within the corresponding example in the programming manual as well.

Cheers,

Christian

1 Like

Hello all.

The Logger driver offers the option to activate the internal low-pass filter option for 50kHz and 500kHz. This has now proven to be useful for us for the Scope module as well but I am unsure where to put this option as I guess we would have to mis-use one of the existing GUI options like “Aquisition”. What do you think, any ideas?

Best wishes,

Christian

EDIT: I just realized that I did not commit the Logger driver yet. I’ll do that next and then we can think about adding the filter option afterwards.

1 Like

Hello Christian,

for drivers that require additional parameters, we usually use the Custom Parameter Box. For example, if you add a non-module specific parameter to an SMU driver, the SweepMe! GUI will be extended by a Parameter Box:

We will add this parameter box to the Scope module as well and will notify you here once it is available.

1 Like

The new Scope module (2025-10-27) supports the custom parameter box and is now online. Please update SweepMe! to Version >= 1.5.7.6 before downloading this module.

2 Likes

Works as expected, thanks Franz.

2 Likes