Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to allow pyvisa 1.11 dependency #2304

Merged
merged 35 commits into from Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c2fa418
pin pyvisa to 1.11.1
trevormorgan Oct 19, 2020
7d692ce
imnport pyvisa as visa change
trevormorgan Oct 19, 2020
0e0e8c4
update to write_raw method that checks return
trevormorgan Oct 19, 2020
9bada8d
chane import visa to pyvisa visa
trevormorgan Oct 19, 2020
c203006
GPIB address change due to changes in pyvisa_sim
trevormorgan Oct 19, 2020
9898ecc
pin pyvisa to 1.11.1
trevormorgan Oct 19, 2020
96d3052
imnport pyvisa as visa change
trevormorgan Oct 19, 2020
ef7a0cc
update to write_raw method that checks return
trevormorgan Oct 19, 2020
e0ea1ef
chane import visa to pyvisa visa
trevormorgan Oct 19, 2020
4de8b59
GPIB address change due to changes in pyvisa_sim
trevormorgan Oct 19, 2020
c16e9ab
allow pyvisa in setup.py
jenshnielsen Oct 19, 2020
1cf6998
dont use removed ask from pyvisa
jenshnielsen Oct 19, 2020
5a10974
don't rely on return from clean
jenshnielsen Oct 19, 2020
ba86c0a
use enum for constants
jenshnielsen Oct 19, 2020
dc1fdcc
simplify type signature
jenshnielsen Oct 19, 2020
8d7637f
fix typechecking by asserting that this is really a serial instrument
jenshnielsen Oct 19, 2020
cf9b607
we only support messsagebasedresource
jenshnielsen Oct 19, 2020
dbede88
raise on a non MessageBasedResource
jenshnielsen Oct 19, 2020
4f15645
dont try to set timeout to None
jenshnielsen Oct 19, 2020
a04dcd2
let the mock handle inherite from the real handle
jenshnielsen Oct 19, 2020
662bb44
add methods so this can run as a subclass
jenshnielsen Oct 19, 2020
291c33f
remove visa tests requireing fork
jenshnielsen Oct 19, 2020
5103188
use official pyvisasim
jenshnielsen Oct 19, 2020
31b9ab5
also add pyvisa 1.11.1 to docs test reqs
jenshnielsen Oct 19, 2020
a0eb44d
Merge pull request #2307 from jenshnielsen/visa_typing
trevormorgan Oct 19, 2020
37b1682
Merge branch 'pyvisa_1.11_fixes' of https://github.com/QCoDeS/Qcodes …
trevormorgan Oct 19, 2020
3580f8c
remove error check from write_raw
trevormorgan Oct 19, 2020
44cf927
modified test due to changes at local write_raw
trevormorgan Oct 19, 2020
f983b1c
Merge branch 'master' into pyvisa_1.11_fixes
trevormorgan Oct 19, 2020
cdac36f
Merge branch 'master' into pyvisa_1.11_fixes
trevormorgan Oct 19, 2020
061baf3
Merge branch 'pyvisa_1.11_fixes' of https://github.com/QCoDeS/Qcodes …
trevormorgan Oct 19, 2020
e1093dc
Bring back and deprecate VisaInstrument.check_error
astafan8 Oct 20, 2020
672bd64
Merge branch 'master' into pyvisa_1.11_fixes
astafan8 Oct 20, 2020
1a1e264
Merge master into pyvisa_1.11_fixes
github-actions[bot] Oct 20, 2020
dd260ca
Merge master into pyvisa_1.11_fixes
github-actions[bot] Oct 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs_requirements.txt
Expand Up @@ -51,8 +51,8 @@ pyparsing==2.4.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==1.11.1
PyVISA-sim==0.4.0
pywin32==228; sys_platform == 'win32'
pywinpty==0.5.7; sys_platform == 'win32'
PyYAML==5.3.1
Expand Down
32 changes: 18 additions & 14 deletions qcodes/instrument/visa.py
Expand Up @@ -3,13 +3,14 @@
import warnings
import logging

import visa
import pyvisa as visa
import pyvisa.constants as vi_const
import pyvisa.resources

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

Expand Down Expand Up @@ -52,7 +53,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',
Expand Down Expand Up @@ -119,7 +120,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:
Expand All @@ -136,12 +141,10 @@ 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:
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"""
Expand All @@ -158,10 +161,12 @@ 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:
# 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
Expand All @@ -181,10 +186,10 @@ 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:
astafan8 marked this conversation as resolved.
Show resolved Hide resolved
"""
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.
Expand All @@ -209,8 +214,7 @@ 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)
self.visa_handle.write(cmd)

def ask_raw(self, cmd: str) -> str:
"""
Expand Down
2 changes: 1 addition & 1 deletion 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

Expand Down
2 changes: 1 addition & 1 deletion 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

Expand Down
2 changes: 1 addition & 1 deletion qcodes/instrument_drivers/QDevil/QDevil_QDAC.py
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions qcodes/instrument_drivers/stahl/stahl.py
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion qcodes/instrument_drivers/tektronix/Keithley_2600.py
Expand Up @@ -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']
Expand Down
19 changes: 13 additions & 6 deletions 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

Expand All @@ -19,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:

Expand Down Expand Up @@ -51,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)
astafan8 marked this conversation as resolved.
Show resolved Hide resolved

return len(cmd), ret_code
return len(cmd)

def ask(self, cmd):
if self.closed:
Expand All @@ -69,6 +68,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 = [
Expand Down
28 changes: 0 additions & 28 deletions qcodes/tests/test_wrong_address.py

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions test_requirements.txt
Expand Up @@ -30,8 +30,8 @@ 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-sim-QCoDeS @ git+https://github.com/QCoDeS/pyvisa-sim.git@c23b02520e1966cd89c62e93b6db6790cb60f693
PyVISA==1.11.1
PyVISA-sim==0.4.0
PyYAML==5.3.1
requests==2.24.0
six==1.15.0
Expand Down