Skip to content
This repository was archived by the owner on Feb 2, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion ivi/interface/linuxgpib.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def parse_visa_resource_string(resource_string):
suffix = m.group('suffix'),
)

class LinuxGpibInstrument:
# linux-gpib timeout constants, in milliseconds. See self.timeout.
TIMETABLE = (0, 1e-2, 3e-2, 1e-1, 3e-1, 1e0, 3e0, 1e1, 3e1, 1e2, 3e2, 1e3, 3e3,
1e4, 3e4, 1e5, 3e5, 1e6)

class LinuxGpibInstrument(object):
"Linux GPIB wrapper instrument interface client"
def __init__(self, name = 'gpib0', pad = None, sad = 0, timeout = 13, send_eoi = 1, eos_mode = 0):

Expand Down Expand Up @@ -139,3 +143,36 @@ def unlock(self):
"Send unlock command"
raise NotImplementedError()

@property
def timeout(self):
# 0x3 is the hexadecimal reference to the IbaTMO (timeout) configuration
# option in linux-gpib.
return TIMETABLE[self.gpib.ask(3)] * 1000.

@timeout.setter
def timeout(self, value):
"""
linux-gpib only supports 18 discrete timeout values. If a timeout
value other than these is requested, it will be rounded up to the closest
available value. Values greater than the largest available timout value
will instead be rounded down. The available timeout values are:
0 Never timeout.
1 10 microseconds
2 30 microseconds
3 100 microseconds
4 300 microseconds
5 1 millisecond
6 3 milliseconds
7 10 milliseconds
8 30 milliseconds
9 100 milliseconds
10 300 milliseconds
11 1 second
12 3 seconds
13 10 seconds
14 30 seconds
15 100 seconds
16 300 seconds
17 1000 seconds
"""
self.gpib.timeout(bisect(TIMETABLE, value/1000.))
13 changes: 11 additions & 2 deletions ivi/interface/pyserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def parse_visa_resource_string(resource_string):
suffix = m.group('suffix'),
)

class SerialInstrument:
class SerialInstrument(object):
"Serial instrument interface client"
def __init__(self, port = None, baudrate=9600, bytesize=8, paritymode=0, stopbits=1, timeout=None,
xonxoff=False, rtscts=False, dsrdtr=False):
Expand Down Expand Up @@ -123,7 +123,7 @@ def update_settings(self):
else:
self.serial.stopbits = serial.STOPBITS_ONE

self.serial.timeout = self.timeout
# timeout is handled in property setter
self.serial.xonxoff = self.xonxoff
self.serial.rtscts = self.rtscts
self.serial.dsrdtr = self.dsrdtr
Expand Down Expand Up @@ -223,3 +223,12 @@ def unlock(self):
"Send unlock command"
raise NotImplementedError()

@property
def timeout(self):
return self.serial.timeout

@timeout.setter
def timeout(self, value):
self.serial.timeout = value
self.serial.writeTimeout = value

10 changes: 9 additions & 1 deletion ivi/interface/pyvisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
(e.__class__.__name__, e.args[0]))
raise ImportError

class PyVisaInstrument:
class PyVisaInstrument(object):
"PyVisa wrapper instrument interface client"
def __init__(self, resource, *args, **kwargs):
if type(resource) is str:
Expand Down Expand Up @@ -129,3 +129,11 @@ def lock(self):
def unlock(self):
"Send unlock command"
raise NotImplementedError()

@property
def timeout(self):
return self.instrument.timeout

@timeout.setter
def timeout(self, value):
self.instrument.timeout = value
32 changes: 32 additions & 0 deletions ivi/ivi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ def __init__(self, resource = None, id_query = False, reset = False, *args, **kw
self._initialized = False
self.__dict__.setdefault('_instrument_id', '')
self._cache_valid = dict()
self._timeout = 2000

super(Driver, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -1632,6 +1633,8 @@ def __init__(self, resource = None, id_query = False, reset = False, *args, **kw
+-------------------------+----------------------+---------------------+
| Prefer PyVISA | False | prefer_pyvisa |
+-------------------------+----------------------+---------------------+
| Timeout | 2000 | timeout |
+-------------------------+----------------------+---------------------+

Each IVI specific driver defines it own meaning and valid values for the
Driver Setup attribute. Many specific drivers ignore the value of the
Expand Down Expand Up @@ -1686,6 +1689,18 @@ def __init__(self, resource = None, id_query = False, reset = False, *args, **kw
again.
* May deallocate internal resources used by the IVI session.
""")
self._add_property('timeout',
self._get_timeout,
self._set_timeout,
self._del_timeout,
"""
Set the device timeout. This value specifies how long the driver should
wait for a response from the device before giving up. The value is
specified in milliseconds.

This property behaves the same way as pyvisa's timeout property.
To set an infinite timeout, set it to None or use 'del timeout'.
""")

# inherit prefer_pyvisa from global setting
self._prefer_pyvisa = _prefer_pyvisa
Expand Down Expand Up @@ -1718,6 +1733,8 @@ def _initialize(self, resource = None, id_query = False, reset = False, **keywar
self._driver_operation_driver_setup = val
elif op == 'prefer_pyvisa':
self._prefer_pyvisa = bool(val)
elif op == 'timeout':
self._timeout = float(val)
else:
raise UnknownOptionException('Invalid option')

Expand Down Expand Up @@ -1837,6 +1854,9 @@ def _initialize(self, resource = None, id_query = False, reset = False, **keywar

self.driver_operation.invalidate_all_attributes()

if self._interface:
self._interface.timeout = self._timeout

self._initialized = True


Expand Down Expand Up @@ -1891,6 +1911,18 @@ def _set_cache_valid(self, valid=True, tag=None, index=-1):
def _driver_operation_invalidate_all_attributes(self):
self._cache_valid = dict()


def _get_timeout(self):
return self._timeout

def _set_timeout(self, value):
self._timeout = value
if self._initialized and self._interface:
self._interface.timeout = value

def _del_timeout(self):
self._set_timeout = None

def _write_raw(self, data):
"Write binary data to instrument"
if self._driver_operation_simulate:
Expand Down