Skip to content

Commit

Permalink
voltage control without qcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLaudatQM committed Oct 23, 2024
1 parent 414f3de commit 13278f3
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 4 deletions.
8 changes: 4 additions & 4 deletions qualang_tools/control_panel/voltage_control/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import threading
from typing import Any

import pyvisa as visa
from PyQt5.QtWidgets import QApplication

from qualang_tools.control_panel.voltage_control.voltage_control_dialog import VoltageControlDialog
Expand Down Expand Up @@ -39,11 +39,11 @@ def start_voltage_control(use_thread: bool = False, gui_name: str = "Voltage con
qApp.exec_()
return qApp


if __name__ == "__main__":
from qcodes.parameters import ManualParameter
import numpy as np
from voltage_parameters import QDACII, qdac_ch

qdac = QDACII("dummy")
# Create dummy parameters
parameters = [ManualParameter(f"V{idx}", initial_value=np.round(np.random.rand(), 3)) for idx in range(15)]
parameters = [qdac_ch(qdac, idx, f"V{idx}", initial_value=np.round(np.random.rand(), 3)) for idx in range(5)]
start_voltage_control(parameters=parameters, mini=True, use_thread=False)
105 changes: 105 additions & 0 deletions qualang_tools/control_panel/voltage_control/voltage_parameters.py
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)

0 comments on commit 13278f3

Please sign in to comment.