updates
This commit is contained in:
@@ -72,7 +72,7 @@ def configure():
|
||||
rigol.write(":CHANnel1:DISPlay 1")
|
||||
rigol.write(":CHANnel2:DISPlay 0")
|
||||
rigol.write(":CHANnel1:COUPling DC")
|
||||
rigol.write(":CHANnel1:PROBe 1")
|
||||
rigol.write(":CHANnel1:PROBe 10")
|
||||
rigol.write(f":CHANnel1:SCALe {V18_SCALE:.3f}")
|
||||
rigol.write(f":CHANnel1:OFFSet {V18_OFFSET:.3f}")
|
||||
rigol.write(f":TIMebase:MAIN:SCALe {V18_TIMEBASE:.2E}")
|
||||
@@ -82,9 +82,11 @@ def configure():
|
||||
rigol.write(f":TRIGger:EDGe:LEVel {V18_TRIG_LEVEL:.3f}")
|
||||
rigol.write(":TRIGger:SWEep AUTO") # auto: captures even without a droop trigger
|
||||
time.sleep(0.3)
|
||||
rigol.write(":RUN") # start acquiring immediately after configure
|
||||
time.sleep(0.2)
|
||||
|
||||
print(f"[RIGOL] Configured: 1.8 V rail, {int(V18_TIMEBASE*1e6)} µs/div, "
|
||||
f"trigger <{V18_TRIG_LEVEL} V falling (AUTO sweep)")
|
||||
f"trigger <{V18_TRIG_LEVEL} V falling (AUTO sweep, running)")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -92,8 +94,9 @@ def configure():
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def arm():
|
||||
"""Arm for a single acquisition. Non-blocking — returns immediately."""
|
||||
rigol.write(":SINGle")
|
||||
"""Ensure scope is running so it is actively acquiring when the LP event occurs.
|
||||
The waveform is frozen with :STOP inside read_waveform_csv() at collection time."""
|
||||
rigol.write(":RUN")
|
||||
|
||||
|
||||
def wait_captured(timeout_s: float = TRIG_TIMEOUT_S) -> bool:
|
||||
@@ -117,32 +120,52 @@ def wait_captured(timeout_s: float = TRIG_TIMEOUT_S) -> bool:
|
||||
def read_waveform_csv(path: Path) -> int:
|
||||
"""
|
||||
Read Ch1 waveform from Rigol over SCPI and write to CSV.
|
||||
The Rigol returns ASCII voltage values; we reconstruct the time axis
|
||||
from the waveform preamble.
|
||||
Sends :STOP first to ensure acquisition is complete before reading —
|
||||
this is reliable regardless of trigger/status state.
|
||||
|
||||
Returns the number of samples written, or 0 on error.
|
||||
"""
|
||||
try:
|
||||
rigol.write(":WAVeform:SOURce CHANnel1")
|
||||
rigol.write(":WAVeform:FORMat ASCII")
|
||||
rigol.write(":WAVeform:MODE NORMal")
|
||||
rigol.write(":STOP")
|
||||
time.sleep(0.3)
|
||||
|
||||
rigol.write(":WAVeform:SOURce CHANnel1")
|
||||
rigol.write(":WAVeform:FORMat ASC") # Rigol DS1000Z uses ASC not ASCII
|
||||
time.sleep(0.1)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[RIGOL] Waveform setup error: {e}")
|
||||
return 0
|
||||
|
||||
try:
|
||||
preamble = rigol.ask(":WAVeform:PREamble?").strip().split(",")
|
||||
# [0]=fmt [1]=type [2]=points [3]=count [4]=x_incr [5]=x_orig [6]=x_ref
|
||||
# [7]=y_incr [8]=y_orig [9]=y_ref
|
||||
x_incr = float(preamble[4])
|
||||
x_orig = float(preamble[5])
|
||||
x_ref = float(preamble[6])
|
||||
except Exception as e:
|
||||
print(f"[RIGOL] Preamble error: {e}")
|
||||
return 0
|
||||
|
||||
try:
|
||||
raw = rigol.ask(":WAVeform:DATA?").strip()
|
||||
|
||||
# Strip any TMC binary header (#<digit><length>) if present
|
||||
# Strip TMC binary header (#<n_digits><byte_count>...) if present
|
||||
if raw.startswith("#"):
|
||||
n_digits = int(raw[1])
|
||||
raw = raw[2 + n_digits:]
|
||||
|
||||
vals = [float(v) for v in raw.split(",") if v.strip()]
|
||||
except Exception as e:
|
||||
print(f"[RIGOL] Data read error: {e}")
|
||||
return 0
|
||||
|
||||
if not vals:
|
||||
print("[RIGOL] No samples parsed — check scope channel and format settings")
|
||||
return 0
|
||||
|
||||
try:
|
||||
path.parent.mkdir(exist_ok=True)
|
||||
with open(path, "w", newline="") as f:
|
||||
writer = csv.writer(f)
|
||||
@@ -150,9 +173,7 @@ def read_waveform_csv(path: Path) -> int:
|
||||
for i, v in enumerate(vals):
|
||||
t = x_orig + (i - x_ref) * x_incr
|
||||
writer.writerow([f"{t:.9f}", f"{v:.6f}"])
|
||||
|
||||
return len(vals)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[RIGOL] Waveform read error: {e}")
|
||||
print(f"[RIGOL] CSV write error: {e}")
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user