-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
414f3de
commit 13278f3
Showing
2 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
qualang_tools/control_panel/voltage_control/voltage_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from typing import Any | ||
import pyvisa as visa | ||
|
||
|
||
# VoltageParameter Class remains unchanged | ||
class Parameter: | ||
def __init__(self, name, label=None, initial_value=0.0, units="V"): | ||
self.name = name | ||
self.label = label | ||
self.latest_value = initial_value | ||
self._value = initial_value | ||
self.units = units | ||
# logging.debug(f"{self.name} initialized with value {self.latest_value} {self.units}") | ||
|
||
def get(self): | ||
# time.sleep(0.2) # Simulate a 200ms delay | ||
self.latest_value = self._value | ||
# logging.debug(f"Getting {self.name}: {self.latest_value} {self.units}") | ||
return self.latest_value | ||
|
||
def set(self, new_value): | ||
self._value = new_value | ||
updated_value = self.get() # Return the value after setting | ||
# logging.debug(f"Setting {self.name} to {new_value}: Actual value is {updated_value} {self.units}") | ||
return updated_value | ||
|
||
def get_latest(self): | ||
return self.latest_value | ||
|
||
# QDAC2 instrument class | ||
class QDACII: | ||
def __init__( | ||
self, | ||
communication_type: str, | ||
IP_address: str = None, | ||
port: int = 5025, | ||
USB_device: int = None, | ||
lib: str = "@py", | ||
): | ||
""" | ||
Open the communication to a QDAC2 instrument with python. The communication can be enabled via either Ethernet or USB. | ||
:param communication_type: Can be either "Ethernet" or "USB". | ||
:param IP_address: IP address of the instrument - required only for Ethernet communication. | ||
:param port: port of the instrument, 5025 by default - required only for Ethernet communication. | ||
:param USB_device: identification number of the device - required only for USB communication. | ||
:param lib: use '@py' to use pyvisa-py backend (default). | ||
""" | ||
rm = visa.ResourceManager(lib) # To use pyvisa-py backend, use argument '@py' | ||
if communication_type == "Ethernet": | ||
self._visa = rm.open_resource(f"TCPIP::{IP_address}::{port}::SOCKET") | ||
self._visa.baud_rate = 921600 | ||
# self._visa.send_end = False | ||
elif communication_type == "USB": | ||
self._visa = rm.open_resource(f"ASRL{USB_device}::INSTR") | ||
elif communication_type == "dummy": | ||
print("QDACII connected!") | ||
|
||
if communication_type != "dummy": | ||
self._visa.write_termination = "\n" | ||
self._visa.read_termination = "\n" | ||
print(self._visa.query("*IDN?")) | ||
print(self._visa.query("syst:err:all?")) | ||
|
||
def query(self, cmd): | ||
return self._visa.query(cmd) | ||
|
||
def write(self, cmd): | ||
self._visa.write(cmd) | ||
|
||
def write_binary_values(self, cmd, values): | ||
self._visa.write_binary_values(cmd, values) | ||
|
||
|
||
|
||
def __exit__(self): | ||
self.close() | ||
|
||
|
||
class qdac_ch(Parameter): | ||
def __init__(self, QDAC: QDACII, channel_number, name, label=None, initial_value=0.0, units="V"): | ||
super().__init__(name, label, initial_value, units) | ||
self.qdac = QDAC | ||
self.ch_nb = channel_number | ||
|
||
def get(self): | ||
# time.sleep(0.2) # Simulate a 200ms delay | ||
self.latest_value = self._value | ||
# assert(self.latest_value == self.qdac.write(f'sour{self.ch_nb}:volt ?')) | ||
print(f"Send: self.qdac.write(f'sour{self.ch_nb}:volt ?')") | ||
# logging.debug(f"Getting {self.name}: {self.latest_value} {self.units}") | ||
return self.latest_value | ||
|
||
def set(self, new_value): | ||
self._value = new_value | ||
print(f"Send: self.qdac.write(f'sour{self.ch_nb}:volt {new_value}')") | ||
updated_value = self.get() # Return the value after setting | ||
# logging.debug(f"Setting {self.name} to {new_value}: Actual value is {updated_value} {self.units}") | ||
return updated_value | ||
|
||
def __call__(self, *args: Any, **kwargs: Any) -> float | None: | ||
if len(args) == 0 and len(kwargs) == 0: | ||
return self.get() | ||
else: | ||
self.set(*args, **kwargs) |