Skip to content

Commit

Permalink
AR Amplifier -> fix return unit
Browse files Browse the repository at this point in the history
  • Loading branch information
franz-sweepMe committed Feb 3, 2025
1 parent 28ec4cd commit 26a9abe
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Switch-AR_Amplifier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self) -> None:
"""Initialize the device class and the instrument parameters."""
super().__init__()

self.shortname = "AR 12S1G3"
self.shortname = "AR Amplifier"

self.variables = ["Gain"]
self.units = [""]
Expand Down Expand Up @@ -85,6 +85,8 @@ def get_GUIparameter(self, parameter: dict) -> None: # noqa: N802
self.port_string = parameter["Port"]
self.mode = parameter["SweepMode"]

self.units = [""] if self.mode == "Amplification (12 Bit)" else ["%"]

def connect(self) -> None:
"""Connect to the device. This function is called only once at the start of the measurement."""

Expand All @@ -107,16 +109,25 @@ def apply(self) -> None:

def call(self) -> int:
"""Measure the value of the device."""
self.port.write("G?")
ret = self.port.read()
return int(ret[1:])
gain = self.get_gain()

if self.mode == "Amplification in Percent":
gain = int(gain / 4095 * 100)

return gain

def set_gain(self, gain: int) -> None:
"""Set the gain of the device."""
"""Set the gain of the device as 12 Bit value."""
if gain < 0 or gain > 4095:
msg = "Gain must be between 0 and 4095."
raise ValueError(msg)

# Command string must be of format 0000 - 4095
gain = f"{int(gain):04}"
self.port.write(f"G{gain}")

def get_gain(self) -> int:
"""Get the gain of the device as 12 Bit value."""
self.port.write("G?")
ret = self.port.read()
return int(ret[1:])

0 comments on commit 26a9abe

Please # to comment.