This commit is contained in:
Zychlix 2026-03-26 12:15:50 +01:00
parent 741ffb74bf
commit 3438754409
5 changed files with 115 additions and 4 deletions

View File

@ -1,5 +1,5 @@
[project] [project]
name = "rigol-py-rig" name = "rigol_dho_lib"
version = "0.1.0" version = "0.1.0"
description = "Add your description here" description = "Add your description here"
readme = "README.md" readme = "README.md"

View File

@ -1,15 +1,23 @@
from rigol_py_rig.rigol import RigolOsc from rigol_py_rig.rigol import RigolOsc
from rigol_py_rig.siglent import SiglentGen, ChannelID
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
# uv # uv
def main(): def main():
osc = RigolOsc("TCPIP::10.112.1.9::INSTR")
gen = SiglentGen("TCPIP::10.112.1.17::INSTR")
gen.channels[ChannelID.CH1].apply_sine(2e3, 1, 0)
gen.channels[ChannelID.CH1].set_output(1)
return
# osc = RigolOsc("TCPIP::10.112.1.9::INSTR")
print(osc.getTrigStatus()) print(osc.getTrigStatus())
osc.single() osc.single()
depth = osc.getMemoryDepth()
# osc.setPoints(depth) # osc.setPoints(depth)
ret = osc.channels[0].getWaveform() ret = osc.channels[0].getWaveform()
@ -22,7 +30,7 @@ def main():
print(f"Y orogin {osc.channels[0].getYOrigin()}") print(f"Y orogin {osc.channels[0].getYOrigin()}")
print(f"Y reference {osc.channels[0].getYReference()}") print(f"Y reference {osc.channels[0].getYReference()}")
plt.plot(ret) plt.plot(osc.channels[0].genTimeArray(ret), ret)
plt.show() plt.show()

View File

@ -6,6 +6,7 @@ from enum import Enum
import numpy as np import numpy as np
CHANNEL_COUNT = 4 CHANNEL_COUNT = 4
# Rigol DHO4804
class TrigState(Enum): class TrigState(Enum):
@ -99,6 +100,12 @@ class Channel:
ret = self.instr.query(":WAVeform:YREFerence?") ret = self.instr.query(":WAVeform:YREFerence?")
return int(ret) return int(ret)
def genTimeArray(self, waveform):
x_delta = self.getXincrement()
time = np.arange(0, len(waveform) * x_delta, x_delta)
return time
class RigolOsc: class RigolOsc:
def __init__(self, visa_address: str): def __init__(self, visa_address: str):

View File

@ -0,0 +1,96 @@
import wave
from pyvisa.resources.resource import Resource
import pyvisa
from enum import Enum
import numpy as np
class Waveform(Enum):
SINE = "SINE"
SQUARE = "SQUARE"
RAMP = "RAMP"
PULSE = "PULSE"
NOISE = "NOISE"
ARB = "ARB"
class ChannelID(Enum):
CH1 = 1
CH2 = 2
CHANNEL_COUNT = 2
class Channel:
def __init__(self, channel_id: ChannelID, instr: Resource):
self.id = channel_id
self.index = channel_id.value
self.instr = instr
# ---- Basic waveform ----
def set_waveform(self, waveform: Waveform):
self.instr.write(f"C{self.index}:BSWV WVTP,{waveform.value}")
def set_frequency(self, freq: float):
self.instr.write(f"C{self.index}:BSWV FRQ,{freq}")
def set_amplitude(self, amplitude: float):
self.instr.write(f"C{self.index}:BSWV AMP,{amplitude}")
def set_offset(self, offset: float):
self.instr.write(f"C{self.index}:BSWV OFST,{offset}")
# ---- Output control (merged) ----
def set_output(self, state: bool):
cmd = "ON" if state else "OFF"
self.instr.write(f"C{self.index}:OUTP {cmd}")
# ---- Convenience ----
def apply_sine(self, freq: float, amp: float, offset: float = 0):
self.set_waveform(Waveform.SINE)
self.set_frequency(freq)
self.set_amplitude(amp)
self.set_offset(offset)
# ---- Query ----
def get_frequency(self) -> float:
response = self.instr.query(f"C{self.index}:BSWV?")
return float(response.split(",")[1])
class GenChannels:
def __init__(self, instr: Resource):
self.instr = instr
self.channels = {
ChannelID.CH1: Channel(ChannelID.CH1, instr),
ChannelID.CH2: Channel(ChannelID.CH2, instr),
}
def __getitem__(self, ch: ChannelID) -> Channel:
return self.channels[ch]
class SiglentGen:
def __init__(self, visa_address: str):
rm = pyvisa.ResourceManager()
self.instr: Resource = rm.open_resource(visa_address)
self.channels = GenChannels(self.instr)
self.initialize()
# ---- Initialization ----
def initialize(self):
self.instr.write("*RST")
self.instr.write("*CLS")
# ---- Global commands ----
def identify(self) -> str:
return self.instr.query("*IDN?")
def close(self):
self.instr.close()
def get_error(self):
return self.instr.query("SYST:ERR?")