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 DSA90000Series Library parts

Posted at

KeysightオシロスコープDSA90000シリーズのlibrary partsになります。
ご参考までに。

'''

import pyvisa

class KeysightOscilloscope:
    def __init__(self, resource):
        """Initialize connection to the oscilloscope."""
        self.rm = pyvisa.ResourceManager()
        self.scope = self.rm.open_resource(resource)
        self.scope.timeout = 10000  # Set timeout to 10 seconds

    def write(self, command):
        """Send a command to the oscilloscope."""
        self.scope.write(command)

    def query(self, command):
        """Send a query command and return the response."""
        return self.scope.query(command).strip()

    def reset(self):
        """Reset the oscilloscope."""
        self.write("*RST")

    def get_id(self):
        """Get the oscilloscope's identification string."""
        return self.query("*IDN?")

    def autoscale(self):
        """Perform an autoscale on the oscilloscope."""
        self.write(":AUToscale")

    def set_timebase(self, scale):
        """Set the time base scale."""
        self.write(f":TIMebase:SCALe {scale}")
    
    def set_trigger_level(self, level):
        """Set the trigger level."""
        self.write(f":TRIGger:LEVel {level}")
    
    def set_trigger_mode(self, mode):
        """Set the trigger mode (AUTO, NORMAL, SINGLE)."""
        self.write(f":TRIGger:MODE {mode}")
    
    def measure_voltage_peak(self, channel):
        """Measure peak-to-peak voltage on a specified channel."""
        self.write(f":MEASure:VPP CHAN{channel}")
        return self.query(f":MEASure:VPP? CHAN{channel}")
    
    def measure_frequency(self, channel):
        """Measure frequency on a specified channel."""
        self.write(f":MEASure:FREQuency CHAN{channel}")
        return self.query(f":MEASure:FREQuency? CHAN{channel}")
    
    def get_waveform(self, channel):
        """Retrieve waveform data from the oscilloscope."""
        self.write(f":WAVeform:SOURce CHANnel{channel}")
        self.write(":WAVeform:FORMat ASCII")
        return self.query(":WAVeform:DATA?")
    
    def save_waveform(self, filename):
        """Save the current waveform to a file."""
        self.write(f":DISK:SAVE:WAVeform '{filename}'")
    
    def load_setup(self, filename):
        """Load a setup file."""
        self.write(f":DISK:LOAD:SETup '{filename}'")
    
    def save_setup(self, filename):
        """Save the current setup to a file."""
        self.write(f":DISK:SAVE:SETup '{filename}'")
    
    def clear_errors(self):
        """Clear error queue."""
        self.write(":SYSTem:ERRor?")
    
    def get_errors(self):
        """Retrieve error messages."""
        return self.query(":SYSTem:ERRor?")
    
    def close(self):
        """Close the connection to the oscilloscope."""
        self.scope.close()
        
# Example usage
if __name__ == "__main__":
    osc = KeysightOscilloscope("TCPIP::192.168.1.100::INSTR")
    print("Oscilloscope ID:", osc.get_id())
    osc.autoscale()
    print("Waveform data:", osc.get_waveform(1))
    print("Peak-to-peak voltage:", osc.measure_voltage_peak(1))
    print("Frequency:", osc.measure_frequency(1))
    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?