Skip to content

Commit

Permalink
E498xA -> Fix readout
Browse files Browse the repository at this point in the history
  • Loading branch information
franz-sweepMe committed Aug 7, 2024
1 parent 62ac49d commit a6ee632
Showing 1 changed file with 47 additions and 24 deletions.
71 changes: 47 additions & 24 deletions src/LCRmeter-Keysight_E498xA/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def __init__(self) -> None:
self.sweepmode: str = "None"
self.stepmode: str = "None"

self.sweepmode_commands = {
"None": "None",
"Frequency in Hz": "FREQ",
"Voltage bias in V": "BIAS:VOLT",
"Current bias in A": "BIAS:CURR",
"Voltage RMS in V": "VOLT",
}

# Bias
self.bias_modes_variables = {"VOLT": "Voltage bias", "CURR": "Current bias"}
self.bias_modes_units = {"VOLT": "V", "CURR": "A"}
Expand Down Expand Up @@ -118,15 +126,15 @@ def set_GUIparameter(self) -> dict: # noqa: N802
"""Set standard GUI parameter."""
return {
"Average": ["1", "2", "4", "8", "16", "32", "64"],
"SweepMode": ["None", "Frequency in Hz", "Voltage bias in V", "Current bias in A", "Voltage RMS in V"],
"SweepMode": list(self.sweepmode_commands),
"SweepValue": ["List"],
"StepMode": ["None", "Frequency in Hz", "Voltage bias in V", "Current bias in A", "Voltage RMS in V"],
"StepMode": list(self.sweepmode_commands),
"ValueTypeRMS": ["Voltage RMS in V:", "Current RMS in A:"],
"ValueRMS": 0.02,
"ValueTypeBias": ["Voltage bias in V:", "Current bias in A:"],
"ValueBias": 0.0,
"Frequency": 1000.0,
"OperatingMode": list(self.operating_modes.keys()),
"OperatingMode": list(self.operating_modes),
"ALC": ["Off", "On"],
"Integration": ["Short", "Medium", "Long"],
"Trigger": ["Software", "Internal", "External"],
Expand Down Expand Up @@ -163,7 +171,7 @@ def get_GUIparameter(self, parameter: dict) -> None: # noqa: N802
self.trigger_type = parameter["Trigger"]

# List Mode
if parameter["SweepValue"] == "List":
if parameter["SweepValue"] == "List sweep":
self.use_list_sweep = True
self.handle_list_sweep_parameter(parameter)

Expand Down Expand Up @@ -245,7 +253,7 @@ def handle_list_sweep_parameter(self, parameter: dict) -> None:
self.list_sweep_values = np.append(self.list_sweep_values, self.list_sweep_values[::-1])

# Add time staps to return values
self.variables.append("Time")
self.variables.append("Time stamp")
self.units.append("s")
self.plottype.append(True)
self.savetype.append(True)
Expand Down Expand Up @@ -405,30 +413,44 @@ def measure(self) -> None:
def request_result(self) -> None:
"""Request the measured values for R+X (depending on measurement mode), F, and bias."""
if self.use_list_sweep:
# Request list sweep data and time stamps
self.port.write("FETC?;LIST:SEQ:TST:DATA?")
# Request measured values and list sweep values
# The device cannot handle more than two requests for list values.
# Therefore, time stamps and bias are requested in the read_results step
request_command = f"FETC?;LIST:{self.sweepmode_commands[self.sweepmode]}?"
self.port.write(request_command)
else:
# Request measured values, frequency, and bias
self.port.write("FETC?;FREQ?;BIAS:VOLT?")
# TODO: Question Axel: Why always bias volt?
self.port.write(f"FETC?;FREQ?;BIAS:{self.bias_mode}?")

def read_result(self) -> None:
"""Read the measured values for R+X (depending on measurement mode), F, and bias."""
if self.use_list_sweep:
answer = self.port.read().split(",")
reshaped_answer = np.array(answer).reshape(-1, 5)

# TODO: Check this
self.value_1 = reshaped_answer[:, 0].astype(float).tolist()
self.value_2 = reshaped_answer[:, 1].astype(float).tolist()
self.measured_frequency = reshaped_answer[:, 2].astype(float).tolist()
self.bias = reshaped_answer[:, 3].astype(float).tolist()
self.time_stamps = reshaped_answer[:, 4].astype(float).tolist()

# resistance = [float(answer[i]) for i in range(0, len(answer), 4)]
# reactance = [float(answer[i + 1]) for i in range(1, len(answer), 4)]
# # TODO: Check this
# frequency = [float(answer[i + 2]) for i in range(2, len(answer), 4)]
# bias = [float(answer[i + 3]) for i in range(3, len(answer), 4)]
answer = self.port.read().split(";")

# Measured Values R+X
value_list = answer[0].split(",")
reshaped_values = np.array(value_list).reshape(-1, 4)
self.value_1 = reshaped_values[:, 0].astype(float).tolist()
self.value_2 = reshaped_values[:, 1].astype(float).tolist()

# List Sweep Values
if self.sweepmode.startswith("Frequency"):
self.measured_frequency = [float(frequency) for frequency in answer[1].split(",")]

self.port.write("BIAS:VOLT?")
self.bias = float(self.port.read())
else:
self.bias = [float(bias) for bias in answer[1].split(",")]

self.port.write("FREQ?")
self.measured_frequency = float(self.port.read())

# Time Stamps
self.port.write("LIST:SEQ:TST:DATA?")
answer = self.port.read()
self.time_stamps = [float(time_stamp) for time_stamp in answer.split(",")]

else:
answer = self.port.read().split(";")
self.value_1, self.value_2 = map(float, answer[0].split(",")[0:2])
Expand Down Expand Up @@ -485,8 +507,9 @@ def set_list_mode(self) -> None:
self.port.write("DISP:PAGE LIST")

# TODO: Check Clear the list sweep setup
self.port.write("LIST:CLE:ALL")
# self.port.write("LIST:CLE:ALL")

# Set sequential list sweep
self.port.write("LIST:MODE SEQ")
# Clear the time stamp
self.port.write("LIST:SEQ:TST:CLE")
Expand Down

0 comments on commit a6ee632

Please sign in to comment.