aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware/scope/rigolds1054z.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-07-18 22:17:16 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-07-18 22:17:16 -0400
commit24f0c5bed0d1ab6a4008fc40d141a670cf23cec3 (patch)
treeed93b01514c3cd3c37338d7cb120fbc3b8a69d32 /qolab/hardware/scope/rigolds1054z.py
parent4df06dbf3d779d74f0a0f522c5656ba7abf14770 (diff)
downloadqolab-24f0c5bed0d1ab6a4008fc40d141a670cf23cec3.tar.gz
qolab-24f0c5bed0d1ab6a4008fc40d141a670cf23cec3.zip
added heurestic to adjust chunk size for Waveform reader
If chunk very long it has probability to fail (at least over USB), but small chunk takes forever to obtain the full Waveform. So if get error, we decrease chunk size, otherwise increase it slowly
Diffstat (limited to 'qolab/hardware/scope/rigolds1054z.py')
-rw-r--r--qolab/hardware/scope/rigolds1054z.py53
1 files changed, 29 insertions, 24 deletions
diff --git a/qolab/hardware/scope/rigolds1054z.py b/qolab/hardware/scope/rigolds1054z.py
index a9ff9cb..c0bc114 100644
--- a/qolab/hardware/scope/rigolds1054z.py
+++ b/qolab/hardware/scope/rigolds1054z.py
@@ -160,36 +160,41 @@ class RigolDS1054z(ScopeSCPI):
print(preamble)
Npnts = int(preamble[2])
wfRaw = np.zeros(Npnts, dtype=np.int8)
- maxreadable = 200000 # 250000 is the maximum number of bytes readable in one go
+ maxreadable = 250000 # the maximum number of bytes readable in one go
+ chunk_size = maxreadable
+ errCnt = 0
strt = 1
- stp = min(maxreadable,Npnts)
+ stp = min(maxreadable, Npnts)
while (strt <= Npnts):
- import time
- stp = strt - 1 + maxreadable
+ stp = strt - 1 + chunk_size
stp = min(stp, Npnts)
- print(f"{strt=} {stp=}")
- # reading requested number of points in chunks of maxreadable
- print("strt cnt")
+ # reading requested number of points in chunks
self.write(f":WAVeform:STARt {strt}")
- print(f"{self.wait_until_finished()}")
- time.sleep(.1)
- print("stop cnt")
self.write(f":WAVeform:STOP {stp}")
- print(f"{self.wait_until_finished()}")
- time.sleep(.1)
qstr = ":WAVeform:DATA?"
- wfRawChunk = self.query_binary_values(
- qstr,
- datatype="b",
- header_fmt="ieee",
- container=np.array,
- chunk_size=(maxreadable + 100),
- )
- print(f"{self.wait_until_finished()}")
- wfRaw[strt-1:stp] = wfRawChunk
- strt += maxreadable
- print("waiting")
- time.sleep(1)
+ try:
+ wfRawChunk = self.query_binary_values(
+ qstr,
+ datatype="b",
+ header_fmt="ieee",
+ container=np.array,
+ chunk_size=(chunk_size + 100),
+ )
+ if len(wfRawChunk) == 0:
+ continue # we need to repeat chunk read
+ wfRaw[strt-1:stp] = wfRawChunk
+ chunk_size = min(maxreadable, int(chunk_size*1.2))
+ strt += chunk_size
+ except VisaIOError:
+ errCnt += 1
+ print(f"ERROR count is {errCnt} while reading raw chunk the scope")
+ print(f"Current pointers are {strt=} {stp=} with {chunk_size=}")
+ chunk_size = max(1, int(np.ceil(chunk_size/2)))
+ print(f"new {chunk_size=}")
+ pass # we repeat this loop iteration again
+
+
+ print(f"final {chunk_size=}")
if True:
return wfRaw