Autoscale
This commit is contained in:
parent
460c070063
commit
5c5befacae
@ -1,4 +1,3 @@
|
|||||||
import wave
|
|
||||||
import time
|
import time
|
||||||
from pyvisa.resources.resource import Resource
|
from pyvisa.resources.resource import Resource
|
||||||
import pyvisa
|
import pyvisa
|
||||||
@ -29,6 +28,8 @@ class Channel:
|
|||||||
self.setProbe(self.probe)
|
self.setProbe(self.probe)
|
||||||
self.setVScale(self.scale_V)
|
self.setVScale(self.scale_V)
|
||||||
|
|
||||||
|
self.last_scale = 1 # V/div
|
||||||
|
|
||||||
def setProbe(self, probe: float):
|
def setProbe(self, probe: float):
|
||||||
self.instr.write(f":CHANnel{self.index}:PROBe {probe}")
|
self.instr.write(f":CHANnel{self.index}:PROBe {probe}")
|
||||||
|
|
||||||
@ -101,6 +102,37 @@ class Channel:
|
|||||||
|
|
||||||
return tim
|
return tim
|
||||||
|
|
||||||
|
def getVpp(self):
|
||||||
|
self.instr.write(f":MEASure:SOURce CHANnel{self.index}")
|
||||||
|
ret = self.instr.query(":MEASure:ITEM? VPP")
|
||||||
|
saturated = False
|
||||||
|
|
||||||
|
vpp = float(ret)
|
||||||
|
|
||||||
|
if vpp > 1e10:
|
||||||
|
saturated = True
|
||||||
|
|
||||||
|
return vpp, saturated
|
||||||
|
|
||||||
|
def getVrms(self):
|
||||||
|
self.instr.write(f":MEASure:SOURce CHANnel{self.index}")
|
||||||
|
ret = self.instr.query(":MEASure:ITEM? VRMS")
|
||||||
|
saturated = False
|
||||||
|
|
||||||
|
rms = float(ret)
|
||||||
|
|
||||||
|
if rms > 1e10:
|
||||||
|
saturated = True
|
||||||
|
|
||||||
|
return rms, saturated
|
||||||
|
|
||||||
|
def clampVscale(self, val):
|
||||||
|
if val > 100:
|
||||||
|
val = 100
|
||||||
|
if val < 0.001:
|
||||||
|
val = 0.001
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
class RigolOsc:
|
class RigolOsc:
|
||||||
def __init__(self, visa_address: str):
|
def __init__(self, visa_address: str):
|
||||||
@ -110,14 +142,21 @@ class RigolOsc:
|
|||||||
self.channels = [Channel(i + 1, self.instr) for i in range(CHANNEL_COUNT)]
|
self.channels = [Channel(i + 1, self.instr) for i in range(CHANNEL_COUNT)]
|
||||||
self.initialize()
|
self.initialize()
|
||||||
|
|
||||||
|
def getChannel(self, channel_id: int) -> Channel:
|
||||||
|
if 0 < channel_id <= CHANNEL_COUNT:
|
||||||
|
return self.channels[channel_id - 1]
|
||||||
|
else:
|
||||||
|
raise Exception("Invalid channel id")
|
||||||
|
|
||||||
def single(self): # arm single mode
|
def single(self): # arm single mode
|
||||||
self.instr.write(":SINGle")
|
self.instr.write(":SINGle")
|
||||||
self.instr.query("*OPC?")
|
self.instr.query("*OPC?")
|
||||||
time.sleep(0.01) # Either this, or RUN before triggering
|
time.sleep(0.01) # Either this, or RUN before triggering
|
||||||
print(self.getTrigStatus())
|
# print(self.getTrigStatus())
|
||||||
|
|
||||||
while self.getTrigStatus() != TrigState.STOP:
|
while self.getTrigStatus() != TrigState.STOP:
|
||||||
print(self.getTrigStatus())
|
continue
|
||||||
|
# print(self.getTrigStatus())
|
||||||
|
|
||||||
# continue
|
# continue
|
||||||
|
|
||||||
@ -135,7 +174,7 @@ class RigolOsc:
|
|||||||
return TrigState.STOP
|
return TrigState.STOP
|
||||||
else:
|
else:
|
||||||
print("error")
|
print("error")
|
||||||
print(ret)
|
# print(ret)
|
||||||
raise (Exception("Unknown state"))
|
raise (Exception("Unknown state"))
|
||||||
|
|
||||||
def setPoints(self, points):
|
def setPoints(self, points):
|
||||||
@ -149,7 +188,7 @@ class RigolOsc:
|
|||||||
|
|
||||||
ret = self.instr.query(":ACQuire:MDEPth?")
|
ret = self.instr.query(":ACQuire:MDEPth?")
|
||||||
depth = int(float(ret))
|
depth = int(float(ret))
|
||||||
print(depth)
|
# print(depth)
|
||||||
return depth
|
return depth
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user