1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Keysight UXR Library parts

Posted at

Keysightオシロスコープをご使用の方で参考になるかもしれないと思い作成しました。

'''python:UXR.py

import pyvisa

class KeysightUXR:
    def __init__(self, resource):
      
        Initialize the oscilloscope connection.
        :param resource: VISA resource string (e.g., 'TCPIP0::192.168.1.100::inst0::INSTR')
        self.rm = pyvisa.ResourceManager()
        self.scope = self.rm.open_resource(resource)
        self.scope.timeout = 5000  # Set timeout to 5 seconds
    
    def get_id(self):
        """ Get the oscilloscope ID. """
        return self.scope.query('*IDN?')
    
    def reset(self):
        """ Reset the oscilloscope. """
        self.scope.write('*RST')
    
    def autoscale(self):
        """ Perform autoscale on the oscilloscope. """
        self.scope.write(':AUToscale')
    
    def set_timebase(self, scale):
        """
        Set the timebase scale.
        :param scale: Timebase scale in seconds per division
        """
        self.scope.write(f':TIMebase:SCALe {scale}')
    
    def set_channel(self, channel, state=True):
        """
        Enable or disable a channel.
        :param channel: Channel number (1, 2, 3, ...)
        :param state: True to enable, False to disable
        """
        self.scope.write(f':CHANnel{channel}:DISPlay {int(state)}')
    
    def set_trigger(self, level):
        """
        Set the trigger level.
        :param level: Trigger level in volts
        """
        self.scope.write(f':TRIGger:LEVel {level}')
    
    def measure_voltage_peak_to_peak(self, channel):
        """
        Measure the peak-to-peak voltage of a channel.
        :param channel: Channel number
        """
        self.scope.write(f':MEASure:VPP CHAN{channel}')
        return self.scope.query(':MEASure:VPP?')
    
    def measure_frequency(self, channel):
        """
        Measure the frequency of a channel.
        :param channel: Channel number
        """
        self.scope.write(f':MEASure:FREQuency CHAN{channel}')
        return self.scope.query(':MEASure:FREQuency?')
    
    def get_waveform(self, channel):
        """
        Get waveform data from a specified channel.
        :param channel: Channel number
        """
        self.scope.write(f':WAVeform:SOURce CHAN{channel}')
        self.scope.write(':WAVeform:FORMat ASCII')
        return self.scope.query(':WAVeform:DATA?')
    
    def save_setup(self, filename):
        """
        Save oscilloscope setup to a file.
        :param filename: File name
        """
        self.scope.write(f':DISK:SAVE:SETup "{filename}"')
    
    def load_setup(self, filename):
        """
        Load oscilloscope setup from a file.
        :param filename: File name
        """
        self.scope.write(f':DISK:LOAD:SETup "{filename}"')
    
    def save_waveform(self, filename):
        """
        Save waveform data to a file.
        :param filename: File name
        """
        self.scope.write(f':DISK:SAVE:WAVeform "{filename}"')
    
    def load_waveform(self, filename):
        """
        Load waveform data from a file.
        :param filename: File name
        """
        self.scope.write(f':DISK:LOAD:WAVeform "{filename}"')
    
    def close(self):
        """ Close the oscilloscope connection. """
        self.scope.close()
        self.rm.close()

# Example Usage
if __name__ == "__main__":
    osc = KeysightUXR('TCPIP0::192.168.1.100::inst0::INSTR')
    print(osc.get_id())
    osc.autoscale()
    osc.set_timebase(0.001)
    osc.set_trigger(0.5)
    print(osc.measure_voltage_peak_to_peak(1))
    print(osc.measure_frequency(1))
    osc.save_setup('setup.stp')
    osc.load_setup('setup.stp')
    osc.save_waveform('waveform.wfm')
    osc.load_waveform('waveform.wfm')
    osc.close()

'''

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?