From c2fa418f31bce1d8fb8fa6faa34914623e685869 Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:47:15 -0700 Subject: [PATCH 01/27] pin pyvisa to 1.11.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 10f9f8a3096..2ec208ee15e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -61,7 +61,7 @@ pyparsing~=2.4.7 pyrsistent~=0.17.3 python-dateutil~=2.8.1 pytz~=2020.1 -PyVISA~=1.10.1 +PyVISA~=1.11.1 pywin32==228; sys_platform == 'win32' pywinpty~=0.5.7; sys_platform == 'win32' pyzmq~=19.0.2 From 7d692ceb77f3ae5f28b7f46d7b11adfe36251664 Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:48:13 -0700 Subject: [PATCH 02/27] imnport pyvisa as visa change --- qcodes/tests/test_visa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/tests/test_visa.py b/qcodes/tests/test_visa.py index d4ee057c677..22af2ccfcb3 100644 --- a/qcodes/tests/test_visa.py +++ b/qcodes/tests/test_visa.py @@ -1,6 +1,6 @@ from unittest import TestCase from unittest.mock import patch -import visa +import pyvisa as visa from qcodes.instrument.visa import VisaInstrument from qcodes.utils.validators import Numbers import warnings From 0e0e8c45b3806c0d46f5211e0bd4cc5b963dfd4a Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:50:05 -0700 Subject: [PATCH 03/27] update to write_raw method that checks return --- qcodes/instrument/visa.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index b24491030aa..cb5473411c5 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -3,7 +3,7 @@ import warnings import logging -import visa +import pyvisa as visa import pyvisa.constants as vi_const import pyvisa.resources @@ -209,8 +209,11 @@ def write_raw(self, cmd: str) -> None: """ with DelayedKeyboardInterrupt(): self.visa_log.debug(f"Writing: {cmd}") - nr_bytes_written, ret_code = self.visa_handle.write(cmd) - self.check_error(ret_code) + response = self.visa_handle.write(cmd) + + if isinstance(response, tuple) and len(response) == 2: + ret_code = response[1] + self.check_error(ret_code) def ask_raw(self, cmd: str) -> str: """ From 9bada8dd80f55b60ffb1a42f9f99452ff8a98ca4 Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:40:11 -0700 Subject: [PATCH 04/27] chane import visa to pyvisa visa --- qcodes/instrument_drivers/QDev/QDac.py | 2 +- qcodes/instrument_drivers/QDev/QDac_channels.py | 2 +- qcodes/instrument_drivers/QDevil/QDevil_QDAC.py | 2 +- .../instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qcodes/instrument_drivers/QDev/QDac.py b/qcodes/instrument_drivers/QDev/QDac.py index 5a22d6b67a6..feccb223f54 100644 --- a/qcodes/instrument_drivers/QDev/QDac.py +++ b/qcodes/instrument_drivers/QDev/QDac.py @@ -1,7 +1,7 @@ # QCoDeS driver for QDac. Based on Alex Johnson's work. import time -import visa +import pyvisa as visa import logging import numpy as np diff --git a/qcodes/instrument_drivers/QDev/QDac_channels.py b/qcodes/instrument_drivers/QDev/QDac_channels.py index d80f7e26cf1..3adf718407a 100644 --- a/qcodes/instrument_drivers/QDev/QDac_channels.py +++ b/qcodes/instrument_drivers/QDev/QDac_channels.py @@ -1,7 +1,7 @@ # QCoDeS driver for QDac using channels import time -import visa +import pyvisa as visa import logging import numpy as np diff --git a/qcodes/instrument_drivers/QDevil/QDevil_QDAC.py b/qcodes/instrument_drivers/QDevil/QDevil_QDAC.py index 8021e31d753..494eea2f97b 100644 --- a/qcodes/instrument_drivers/QDevil/QDevil_QDAC.py +++ b/qcodes/instrument_drivers/QDevil/QDevil_QDAC.py @@ -4,7 +4,7 @@ # Version 2.1 QDevil 2020-02-10 import time -import visa +import pyvisa as visa import logging from functools import partial diff --git a/qcodes/instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py b/qcodes/instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py index 564016945eb..fd147f8db00 100644 --- a/qcodes/instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py +++ b/qcodes/instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py @@ -3,7 +3,7 @@ import warnings from time import sleep -from visa import VisaIOError +from pyvisa import VisaIOError import numpy as np from qcodes.instrument.visa import VisaInstrument From c2030066b1bb7b20d6ecad205f84950a41ec35df Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:40:44 -0700 Subject: [PATCH 05/27] GPIB address change due to changes in pyvisa_sim --- qcodes/tests/test_wrong_address.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcodes/tests/test_wrong_address.py b/qcodes/tests/test_wrong_address.py index ed1f42beea1..3f239d17751 100644 --- a/qcodes/tests/test_wrong_address.py +++ b/qcodes/tests/test_wrong_address.py @@ -12,7 +12,7 @@ def test_wrong_address(): - wrong_address = 'GPIB::2::INSTR' + wrong_address = 'GPIB0::2::0::INSTR' match_str = re.escape(f'ERROR: resource {wrong_address} not found') with pytest.raises(Exception, match=match_str) as exc_info: @@ -20,7 +20,7 @@ def test_wrong_address(): address=wrong_address, visalib=visalib) - right_address = 'GPIB::1::INSTR' # from the simulation yaml file + right_address = 'GPIB0::1::0::INSTR' # from the simulation yaml file inst = Keysight_34465A('keysight_34465A_sim', address=right_address, From 9898ecc9bb40c2201044201c927b61c30f29cf0d Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:47:15 -0700 Subject: [PATCH 06/27] pin pyvisa to 1.11.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2de210eb39d..b22a4bb94f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -61,7 +61,7 @@ pyparsing~=2.4.7 pyrsistent~=0.17.3 python-dateutil~=2.8.1 pytz~=2020.1 -PyVISA~=1.10.1 +PyVISA~=1.11.1 pywin32==228; sys_platform == 'win32' pywinpty~=0.5.7; sys_platform == 'win32' pyzmq~=19.0.2 From 96d3052f02e22b0e8afac1c8f46d09437e241636 Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:48:13 -0700 Subject: [PATCH 07/27] imnport pyvisa as visa change --- qcodes/tests/test_visa.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qcodes/tests/test_visa.py b/qcodes/tests/test_visa.py index 824223baa2c..9824923a4f6 100644 --- a/qcodes/tests/test_visa.py +++ b/qcodes/tests/test_visa.py @@ -1,7 +1,8 @@ import warnings import pytest -import visa +import pyvisa as visa + from qcodes.instrument.visa import VisaInstrument from qcodes.utils.validators import Numbers From ef7a0cc6002dc0355da66a235cb357ae2ec4e907 Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:50:05 -0700 Subject: [PATCH 08/27] update to write_raw method that checks return --- qcodes/instrument/visa.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index b24491030aa..cb5473411c5 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -3,7 +3,7 @@ import warnings import logging -import visa +import pyvisa as visa import pyvisa.constants as vi_const import pyvisa.resources @@ -209,8 +209,11 @@ def write_raw(self, cmd: str) -> None: """ with DelayedKeyboardInterrupt(): self.visa_log.debug(f"Writing: {cmd}") - nr_bytes_written, ret_code = self.visa_handle.write(cmd) - self.check_error(ret_code) + response = self.visa_handle.write(cmd) + + if isinstance(response, tuple) and len(response) == 2: + ret_code = response[1] + self.check_error(ret_code) def ask_raw(self, cmd: str) -> str: """ From e0ea1ef9c99ab3ad821bc072bdf0ae61ac54ef9c Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:40:11 -0700 Subject: [PATCH 09/27] chane import visa to pyvisa visa --- qcodes/instrument_drivers/QDev/QDac.py | 2 +- qcodes/instrument_drivers/QDev/QDac_channels.py | 2 +- qcodes/instrument_drivers/QDevil/QDevil_QDAC.py | 2 +- .../instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qcodes/instrument_drivers/QDev/QDac.py b/qcodes/instrument_drivers/QDev/QDac.py index 5a22d6b67a6..feccb223f54 100644 --- a/qcodes/instrument_drivers/QDev/QDac.py +++ b/qcodes/instrument_drivers/QDev/QDac.py @@ -1,7 +1,7 @@ # QCoDeS driver for QDac. Based on Alex Johnson's work. import time -import visa +import pyvisa as visa import logging import numpy as np diff --git a/qcodes/instrument_drivers/QDev/QDac_channels.py b/qcodes/instrument_drivers/QDev/QDac_channels.py index d80f7e26cf1..3adf718407a 100644 --- a/qcodes/instrument_drivers/QDev/QDac_channels.py +++ b/qcodes/instrument_drivers/QDev/QDac_channels.py @@ -1,7 +1,7 @@ # QCoDeS driver for QDac using channels import time -import visa +import pyvisa as visa import logging import numpy as np diff --git a/qcodes/instrument_drivers/QDevil/QDevil_QDAC.py b/qcodes/instrument_drivers/QDevil/QDevil_QDAC.py index 8021e31d753..494eea2f97b 100644 --- a/qcodes/instrument_drivers/QDevil/QDevil_QDAC.py +++ b/qcodes/instrument_drivers/QDevil/QDevil_QDAC.py @@ -4,7 +4,7 @@ # Version 2.1 QDevil 2020-02-10 import time -import visa +import pyvisa as visa import logging from functools import partial diff --git a/qcodes/instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py b/qcodes/instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py index 564016945eb..fd147f8db00 100644 --- a/qcodes/instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py +++ b/qcodes/instrument_drivers/QuantumDesign/DynaCoolPPMS/DynaCool.py @@ -3,7 +3,7 @@ import warnings from time import sleep -from visa import VisaIOError +from pyvisa import VisaIOError import numpy as np from qcodes.instrument.visa import VisaInstrument From 4de8b599d1add183a6c9addeedecf5f32949e69e Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:40:44 -0700 Subject: [PATCH 10/27] GPIB address change due to changes in pyvisa_sim --- qcodes/tests/test_wrong_address.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcodes/tests/test_wrong_address.py b/qcodes/tests/test_wrong_address.py index ed1f42beea1..3f239d17751 100644 --- a/qcodes/tests/test_wrong_address.py +++ b/qcodes/tests/test_wrong_address.py @@ -12,7 +12,7 @@ def test_wrong_address(): - wrong_address = 'GPIB::2::INSTR' + wrong_address = 'GPIB0::2::0::INSTR' match_str = re.escape(f'ERROR: resource {wrong_address} not found') with pytest.raises(Exception, match=match_str) as exc_info: @@ -20,7 +20,7 @@ def test_wrong_address(): address=wrong_address, visalib=visalib) - right_address = 'GPIB::1::INSTR' # from the simulation yaml file + right_address = 'GPIB0::1::0::INSTR' # from the simulation yaml file inst = Keysight_34465A('keysight_34465A_sim', address=right_address, From c16e9ab8ee7c23cee430f20efcf9b18da996aa09 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 09:47:30 +0200 Subject: [PATCH 11/27] allow pyvisa in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 38822978af6..c5d42e5ddc6 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def readme(): install_requires = [ 'numpy>=1.10', - 'pyvisa>=1.9.1, <1.11', + 'pyvisa>=1.9.1, <1.12', 'h5py>=2.6', 'websockets>=7.0', 'jsonschema', From 1cf69985808a557159aa7966c1ebe348696283a1 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 10:07:15 +0200 Subject: [PATCH 12/27] dont use removed ask from pyvisa --- qcodes/instrument_drivers/tektronix/Keithley_2600.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/instrument_drivers/tektronix/Keithley_2600.py b/qcodes/instrument_drivers/tektronix/Keithley_2600.py index 41edb23c441..16c702c524f 100644 --- a/qcodes/instrument_drivers/tektronix/Keithley_2600.py +++ b/qcodes/instrument_drivers/tektronix/Keithley_2600.py @@ -35,7 +35,7 @@ def __init__(self, name: str, address: str, channel: str, self._channel = channel - model = self.visa_handle.ask('print(localnode.model)') + model = self.visa_handle.query('print(localnode.model)') knownmodels = ['2601B', '2602A', '2602B', '2604B', '2611B', '2612B', '2614B', '2635B', '2636B'] From 5a10974b9e6775431178722a76641f467d07c3e7 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 10:08:32 +0200 Subject: [PATCH 13/27] don't rely on return from clean --- qcodes/instrument/visa.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index cb5473411c5..af844788c5e 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -138,10 +138,7 @@ def device_clear(self) -> None: self.visa_handle.flush( vi_const.VI_READ_BUF_DISCARD | vi_const.VI_WRITE_BUF_DISCARD) else: - status_code = self.visa_handle.clear() - if status_code is not None: - self.visa_log.warning( - f"Cleared visa buffer with status code {status_code}") + self.visa_handle.clear() def set_terminator(self, terminator: str) -> None: r""" From ba86c0a2a3cbfe632de9d3623a2ad0d2fecdebaf Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 10:08:52 +0200 Subject: [PATCH 14/27] use enum for constants --- qcodes/instrument/visa.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index af844788c5e..9d3669bea34 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -136,7 +136,8 @@ def device_clear(self) -> None: if isinstance(self.visa_handle, pyvisa.resources.SerialInstrument): self.visa_handle.flush( - vi_const.VI_READ_BUF_DISCARD | vi_const.VI_WRITE_BUF_DISCARD) + vi_const.BufferOperation.discard_read_buffer_no_io | vi_const.BufferOperation.discard_write_buffer + ) else: self.visa_handle.clear() From dc1fdcc31dfcc4c83f373db4684d5cd66ad0c903 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 10:09:09 +0200 Subject: [PATCH 15/27] simplify type signature --- qcodes/instrument/visa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index 9d3669bea34..482ca41432f 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -156,7 +156,7 @@ def set_terminator(self, terminator: str) -> None: if self.visabackend == 'sim': self.visa_handle.write_termination = terminator - def _set_visa_timeout(self, timeout: Optional[Union[float, int]]) -> None: + def _set_visa_timeout(self, timeout: Optional[float]) -> None: if timeout is None: self.visa_handle.timeout = None From 8d7637f0fc50537dc53626fad4e27faafabc2d4e Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 10:23:25 +0200 Subject: [PATCH 16/27] fix typechecking by asserting that this is really a serial instrument --- qcodes/instrument_drivers/stahl/stahl.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qcodes/instrument_drivers/stahl/stahl.py b/qcodes/instrument_drivers/stahl/stahl.py index 7708186c8f7..db54fe4b20e 100644 --- a/qcodes/instrument_drivers/stahl/stahl.py +++ b/qcodes/instrument_drivers/stahl/stahl.py @@ -9,6 +9,8 @@ from collections import OrderedDict from functools import partial +from pyvisa.resources.serial import SerialInstrument + from qcodes import VisaInstrument, InstrumentChannel, ChannelList from qcodes.utils.validators import Numbers @@ -144,6 +146,8 @@ class Stahl(VisaInstrument): def __init__(self, name: str, address: str, **kwargs): super().__init__(name, address, terminator="\r", **kwargs) + assert isinstance(self.visa_handle, SerialInstrument) + self.visa_handle.baud_rate = 115200 instrument_info = self.parse_idn_string( From cf9b607e13349197be355f809f905cc908c7a778 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 10:24:10 +0200 Subject: [PATCH 17/27] we only support messsagebasedresource --- qcodes/instrument/visa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index 482ca41432f..53ae523b2f2 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -52,7 +52,7 @@ def __init__(self, name: str, address: str, timeout: Union[int, float] = 5, super().__init__(name, **kwargs) self.visa_log = get_instrument_logger(self, VISA_LOGGER) self.visabackend: str - self.visa_handle: visa.ResourceManager + self.visa_handle: visa.resources.MessageBasedResource self.visalib: Optional[str] self.add_parameter('timeout', From dbede88de7f522e0986ab96b4906e2f7838f1108 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 10:35:00 +0200 Subject: [PATCH 18/27] raise on a non MessageBasedResource --- qcodes/instrument/visa.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index 53ae523b2f2..669983b8d50 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -119,7 +119,11 @@ def set_address(self, address: str) -> None: self.visabackend = 'ni' self.visa_log.info(f'Opening PyVISA resource at address: {address}') - self.visa_handle = resource_manager.open_resource(address) + resouce = resource_manager.open_resource(address) + if not isinstance(resouce, visa.resources.MessageBasedResource): + raise TypeError("QCoDeS only support MessageBasedResource " + "Visa resources") + self.visa_handle = resouce self._address = address def device_clear(self) -> None: From 4f156451948a198ae269e761f4b96c6d6cecd303 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 10:41:53 +0200 Subject: [PATCH 19/27] dont try to set timeout to None fixes typing issue --- qcodes/instrument/visa.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index 669983b8d50..2a0f054266b 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -161,9 +161,11 @@ def set_terminator(self, terminator: str) -> None: self.visa_handle.write_termination = terminator def _set_visa_timeout(self, timeout: Optional[float]) -> None: - + # according to https://pyvisa.readthedocs.io/en/latest/introduction/resources.html#timeout + # both float('+inf') and None are accepted as meaning infinite timeout + # however None does not pass the typechecking in 1.11.1 if timeout is None: - self.visa_handle.timeout = None + self.visa_handle.timeout = float('+inf') else: # pyvisa uses milliseconds but we use seconds self.visa_handle.timeout = timeout * 1000.0 From a04dcd241693c79b59130f02faad5751f04ad5f5 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 11:05:30 +0200 Subject: [PATCH 20/27] let the mock handle inherite from the real handle --- qcodes/tests/test_visa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/tests/test_visa.py b/qcodes/tests/test_visa.py index 9824923a4f6..6e6df40c5ea 100644 --- a/qcodes/tests/test_visa.py +++ b/qcodes/tests/test_visa.py @@ -20,7 +20,7 @@ def set_address(self, address): self.visabackend = self.visalib -class MockVisaHandle: +class MockVisaHandle(visa.resources.MessageBasedResource): """ mock the API needed for a visa handle that throws lots of errors: From 662bb448f51bea09f01b41b6acb32e6baaeb493d Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 12:12:01 +0200 Subject: [PATCH 21/27] add methods so this can run as a subclass --- qcodes/tests/test_visa.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qcodes/tests/test_visa.py b/qcodes/tests/test_visa.py index 6e6df40c5ea..3c53a28eb99 100644 --- a/qcodes/tests/test_visa.py +++ b/qcodes/tests/test_visa.py @@ -70,6 +70,14 @@ def query(self, cmd): raise ValueError("I'm out of fingers") return self.state + def set_visa_attribute( + self, name, state + ): + setattr(self, str(name), state) + + def __del__(self): + pass + # error args for set(-10) args1 = [ From 291c33faeaaf211c8d58944bddb68d8ecbeab985 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 13:38:37 +0200 Subject: [PATCH 22/27] remove visa tests requireing fork --- qcodes/tests/test_wrong_address.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 qcodes/tests/test_wrong_address.py diff --git a/qcodes/tests/test_wrong_address.py b/qcodes/tests/test_wrong_address.py deleted file mode 100644 index 3f239d17751..00000000000 --- a/qcodes/tests/test_wrong_address.py +++ /dev/null @@ -1,28 +0,0 @@ -import re - -import pytest - -import qcodes.instrument.sims as sims -from qcodes.instrument_drivers.Keysight.Keysight_34465A_submodules import \ - Keysight_34465A -from qcodes.tests.common import error_caused_by - - -visalib = sims.__file__.replace('__init__.py', 'Keysight_34465A.yaml@sim') - - -def test_wrong_address(): - wrong_address = 'GPIB0::2::0::INSTR' - - match_str = re.escape(f'ERROR: resource {wrong_address} not found') - with pytest.raises(Exception, match=match_str) as exc_info: - _ = Keysight_34465A('keysight_34465A_sim', - address=wrong_address, - visalib=visalib) - - right_address = 'GPIB0::1::0::INSTR' # from the simulation yaml file - - inst = Keysight_34465A('keysight_34465A_sim', - address=right_address, - visalib=visalib) - inst.close() From 51031887df78fea3a89baeb3cb47c82ca38e9001 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 13:38:59 +0200 Subject: [PATCH 23/27] use official pyvisasim --- docs_requirements.txt | 2 +- test_requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs_requirements.txt b/docs_requirements.txt index a14723b84be..12d4960c658 100644 --- a/docs_requirements.txt +++ b/docs_requirements.txt @@ -52,7 +52,7 @@ pyrsistent==0.17.3 python-dateutil==2.8.1 pytz==2020.1 PyVISA==1.10.1 -PyVISA-sim-QCoDeS @ git+https://github.com/QCoDeS/pyvisa-sim.git@c23b02520e1966cd89c62e93b6db6790cb60f693 +PyVISA-sim==0.4.0 pywin32==228; sys_platform == 'win32' pywinpty==0.5.7; sys_platform == 'win32' PyYAML==5.3.1 diff --git a/test_requirements.txt b/test_requirements.txt index 5de3384dcd3..0ec26f7104b 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -31,7 +31,7 @@ pytest-mock==3.3.1 pytest-rerunfailures==9.1.1 pytest-xdist==2.1.0 PyVISA==1.10.1 -PyVISA-sim-QCoDeS @ git+https://github.com/QCoDeS/pyvisa-sim.git@c23b02520e1966cd89c62e93b6db6790cb60f693 +PyVISA-sim==0.4.0 PyYAML==5.3.1 requests==2.24.0 six==1.15.0 From 31b9ab530521462aec8cb49c4ac412b758b38c71 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Mon, 19 Oct 2020 13:41:53 +0200 Subject: [PATCH 24/27] also add pyvisa 1.11.1 to docs test reqs --- docs_requirements.txt | 2 +- test_requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs_requirements.txt b/docs_requirements.txt index 12d4960c658..6bca20833fb 100644 --- a/docs_requirements.txt +++ b/docs_requirements.txt @@ -51,7 +51,7 @@ pyparsing==2.4.7 pyrsistent==0.17.3 python-dateutil==2.8.1 pytz==2020.1 -PyVISA==1.10.1 +PyVISA==1.11.1 PyVISA-sim==0.4.0 pywin32==228; sys_platform == 'win32' pywinpty==0.5.7; sys_platform == 'win32' diff --git a/test_requirements.txt b/test_requirements.txt index 0ec26f7104b..7b57f8e5d65 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -30,7 +30,7 @@ pytest-forked==1.3.0 pytest-mock==3.3.1 pytest-rerunfailures==9.1.1 pytest-xdist==2.1.0 -PyVISA==1.10.1 +PyVISA==1.11.1 PyVISA-sim==0.4.0 PyYAML==5.3.1 requests==2.24.0 From 3580f8ce57dc1c2c008af84b32d8cfaa56d4a5fc Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Mon, 19 Oct 2020 11:14:35 -0700 Subject: [PATCH 25/27] remove error check from write_raw --- qcodes/instrument/visa.py | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index 2a0f054266b..066a9504d7a 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -185,25 +185,6 @@ def close(self) -> None: self.visa_handle.close() super().close() - def check_error(self, ret_code: int) -> None: - """ - Default error checking, raises an error if return code ``!=0``. - - Does not differentiate between warnings or specific error messages. - Override this function in your driver if you want to add specific - error messages. - - Args: - ret_code: A Visa error code. See eg: - https://github.com/hgrecco/pyvisa/blob/master/pyvisa/errors.py - - Raises: - visa.VisaIOError: if ``ret_code`` indicates a communication - problem. - """ - if ret_code != 0: - raise visa.VisaIOError(ret_code) - def write_raw(self, cmd: str) -> None: """ Low-level interface to ``visa_handle.write``. @@ -213,11 +194,7 @@ def write_raw(self, cmd: str) -> None: """ with DelayedKeyboardInterrupt(): self.visa_log.debug(f"Writing: {cmd}") - response = self.visa_handle.write(cmd) - - if isinstance(response, tuple) and len(response) == 2: - ret_code = response[1] - self.check_error(ret_code) + self.visa_handle.write(cmd) def ask_raw(self, cmd: str) -> str: """ From 44cf927de0031af7a771fc3c2d9197fff9b8fe7a Mon Sep 17 00:00:00 2001 From: Trevor Morgan <63689909+trevormorgan@users.noreply.github.com> Date: Mon, 19 Oct 2020 15:21:23 -0700 Subject: [PATCH 26/27] modified test due to changes at local write_raw --- qcodes/tests/test_visa.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/qcodes/tests/test_visa.py b/qcodes/tests/test_visa.py index 3c53a28eb99..fe0b1d36e1d 100644 --- a/qcodes/tests/test_visa.py +++ b/qcodes/tests/test_visa.py @@ -52,11 +52,9 @@ def write(self, cmd): raise ValueError('be more positive!') if num == 0: - ret_code = visa.constants.VI_ERROR_TMO - else: - ret_code = 0 + raise visa.VisaIOError(visa.constants.VI_ERROR_TMO) - return len(cmd), ret_code + return len(cmd) def ask(self, cmd): if self.closed: From e1093dcdba51f9f6cee5598d3b0e6755ac34c1d3 Mon Sep 17 00:00:00 2001 From: Mikhail Astafev Date: Tue, 20 Oct 2020 12:17:06 +0200 Subject: [PATCH 27/27] Bring back and deprecate VisaInstrument.check_error --- qcodes/instrument/visa.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/qcodes/instrument/visa.py b/qcodes/instrument/visa.py index 066a9504d7a..aa3ecd8af66 100644 --- a/qcodes/instrument/visa.py +++ b/qcodes/instrument/visa.py @@ -10,6 +10,7 @@ from .base import Instrument, InstrumentBase import qcodes.utils.validators as vals +from qcodes.utils.deprecate import deprecate from qcodes.logger.instrument_logger import get_instrument_logger from qcodes.utils.delaykeyboardinterrupt import DelayedKeyboardInterrupt @@ -185,6 +186,25 @@ def close(self) -> None: self.visa_handle.close() super().close() + @deprecate(reason="pyvisa already checks the error code itself") + def check_error(self, ret_code: int) -> None: + """ + Default error checking, raises an error if return code ``!=0``. + Does not differentiate between warnings or specific error messages. + Override this function in your driver if you want to add specific + error messages. + + Args: + ret_code: A Visa error code. See eg: + https://github.com/hgrecco/pyvisa/blob/master/pyvisa/errors.py + + Raises: + visa.VisaIOError: if ``ret_code`` indicates a communication + problem. + """ + if ret_code != 0: + raise visa.VisaIOError(ret_code) + def write_raw(self, cmd: str) -> None: """ Low-level interface to ``visa_handle.write``.