Skip to content

Commit

Permalink
Attempt at readin back waveform data from AFG
Browse files Browse the repository at this point in the history
This doesn't completely work. For some reason, after the query, the
AFG keeps spitting out data (self.visa_handle.read_raw() returns
some data), and I couldn't figure out what to do with it based on
the manual. So this is mostly a curiosity that I will revert.
  • Loading branch information
Aalto QCD labs committed May 5, 2022
1 parent abaf0b9 commit 0dbf56b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions qcodes_contrib_drivers/drivers/Tektronix/AFG3000.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,15 @@ def __init__(self, name: str, address: str, **kwargs: Any):
vals=vals.Enum('INTernal', 'INT', 'EXTernal', 'EXT')
)

self.add_parameter(
name='ememory_points',
label='Number of points in the editable memory',
get_cmd='DATA:POINts? EMEM',
get_parser=int,
set_cmd='DATA:POINts EMEM, {}',
vals=vals.Ints(MIN_WAVEFORM_LENGTH, MAX_WAVEFORM_LENGTH),
)

# Trigger parameters
self.add_parameter(
name='trigger_slope',
Expand Down Expand Up @@ -679,6 +688,31 @@ def upload_waveform(self, waveform: List[float], memory: int):
# copy data from editable memory to USER.
self.write(f"DATA:COPY USER{memory},EMEM")

def read_waveform(self, memory: int) -> np.ndarray:
"""
Copy the waveform stored in one of the user memories to the edit memory
and read the waveform data from the device.
"""
if memory not in [1, 2, 3, 4]:
raise ValueErorr(f"Invalid value for memory: '{memory}'")

# copy the requested memory contents to the edit memory
self.write(f"DATA:COPY EMEM,USER{memory}")

self.write("DATA:DATA? EMEM")
self.visa_handle.read_bytes(1) # the first character is '#', skip it
# how many digits does the size of the data have?
n_digits_in_n_bytes = int(self.visa_handle.read_bytes(1))
# the actual size of the data in bytes
n_bytes = int(self.visa_handle.read_bytes(n_digits_in_n_bytes))
# actually read the data
wf_bytes = self.visa_handle.read_bytes(n_bytes)

# convert bytes to numbers and apply appropriate scaling
# ">u2" means "two-byte unsigned integer in big endian format"
wf_codes = np.frombuffer(wf_bytes, dtype=">u2")
return (wf_codes * 1.0 / (2**14-2) - 0.5) * 2


class AFG3252(AFG3000):
pass
Expand Down

0 comments on commit 0dbf56b

Please sign in to comment.