Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with self.ignore_warning(constants.VI_SUCCESS_DEV_NPRESENT,
constants.VI_SUCCESS_MAX_CNT):
try:
status = None
while len(ret) < count:
size = min(chunk_size, left_to_read)
logger.debug('%s - reading %d bytes (last status %r)',
self._resource_name, size, status)
chunk, status = self.visalib.read(self.session, size)
ret.extend(chunk)
left_to_read -= len(chunk)
if break_on_termchar and status == termchar_read:
break
except errors.VisaIOError as e:
logger.debug('%s - exception while reading: %s\n'
'Buffer content: %r', self._resource_name, e,
ret)
raise
return bytes(ret)
def close(self):
"""Close the resource manager session.
"""
try:
logger.debug('Closing ResourceManager (session: %s)', self.session)
# Cleanly close all resources when closing the manager.
for resource in self._created_resources:
resource.close()
self.visalib.close(self.session)
self.session = None
self.visalib.resource_manager = None
except errors.InvalidSession:
pass
and will be removed in 1.12
If neither can be found, raise a ValueError.
"""
from .ctwrapper import IVIVisaLibrary
ni_binary_found = bool(IVIVisaLibrary.get_library_paths())
if ni_binary_found:
logger.debug('The IVI implementation available')
return 'ivi'
else:
logger.debug('Did not find IVI binary')
try:
get_wrapper_class('py') # check for pyvisa-py availability
logger.debug('pyvisa-py is available.')
return 'py'
except ValueError:
logger.debug('Did not find pyvisa-py package')
raise ValueError('Could not locate a VISA implementation. Install either the IVI binary or pyvisa-py.')
def gpib_pass_control(self, primary_address, secondary_address):
"""Tell the GPIB device at the specified address to become controller in charge (CIC).
Corresponds to viGpibPassControl function of the VISA library.
:param session: Unique logical identifier to a session.
:param primary_address: Primary address of the GPIB device to which you want to pass control.
:param secondary_address: Secondary address of the targeted GPIB device.
If the targeted device does not have a secondary address,
this parameter should contain the value Constants.VI_NO_SEC_ADDR.
:return: return value of the library call.
:rtype: :class:`pyvisa.constants.StatusCode`
"""
# ibpct need to get the device id matching the primary and secondary address
logger.debug("GPIB.pass control")
try:
did = gpib.dev(self.parsed.board, primary_address, secondary_address)
except gpib.GpibError:
logger.exception(
"Failed to get id for %s, %d", primary_address, secondary_address
)
return StatusCode.error_resource_not_found
status = gpib_lib.ibpct(did)
return convert_gpib_status(status)
Use IVI if the binary is found, else try to use pyvisa-py.
'ni' VISA wrapper is NOT used since version > 1.10.0
and will be removed in 1.12
If neither can be found, raise a ValueError.
"""
from .ctwrapper import IVIVisaLibrary
ni_binary_found = bool(IVIVisaLibrary.get_library_paths())
if ni_binary_found:
logger.debug('The IVI implementation available')
return 'ivi'
else:
logger.debug('Did not find IVI binary')
try:
get_wrapper_class('py') # check for pyvisa-py availability
logger.debug('pyvisa-py is available.')
return 'py'
except ValueError:
logger.debug('Did not find pyvisa-py package')
raise ValueError('Could not locate a VISA implementation. Install either the IVI binary or pyvisa-py.')
:param size: The chunk size to use when reading the data.
:rtype: bytearray
"""
size = self.chunk_size if size is None else size
loop_status = constants.StatusCode.success_max_count_read
ret = bytearray()
with self.ignore_warning(constants.VI_SUCCESS_DEV_NPRESENT,
constants.VI_SUCCESS_MAX_CNT):
try:
status = loop_status
while status == loop_status:
logger.debug('%s - reading %d bytes (last status %r)',
self._resource_name, size, status)
chunk, status = self.visalib.read(self.session, size)
ret.extend(chunk)
except errors.VisaIOError as e:
logger.debug('%s - exception while reading: %s\nBuffer '
'content: %r', self._resource_name, e, ret)
raise
return ret
"""
from .ctwrapper import IVIVisaLibrary
ni_binary_found = bool(IVIVisaLibrary.get_library_paths())
if ni_binary_found:
logger.debug('The IVI implementation available')
return 'ivi'
else:
logger.debug('Did not find IVI binary')
try:
get_wrapper_class('py') # check for pyvisa-py availability
logger.debug('pyvisa-py is available.')
return 'py'
except ValueError:
logger.debug('Did not find pyvisa-py package')
raise ValueError('Could not locate a VISA implementation. Install either the IVI binary or pyvisa-py.')
def _get_default_wrapper():
"""Return an available default VISA wrapper as a string ('ivi' or 'py').
Use IVI if the binary is found, else try to use pyvisa-py.
'ni' VISA wrapper is NOT used since version > 1.10.0
and will be removed in 1.12
If neither can be found, raise a ValueError.
"""
from .ctwrapper import IVIVisaLibrary
ni_binary_found = bool(IVIVisaLibrary.get_library_paths())
if ni_binary_found:
logger.debug('The IVI implementation available')
return 'ivi'
else:
logger.debug('Did not find IVI binary')
try:
get_wrapper_class('py') # check for pyvisa-py availability
logger.debug('pyvisa-py is available.')
return 'py'
except ValueError:
logger.debug('Did not find pyvisa-py package')
raise ValueError('Could not locate a VISA implementation. Install either the IVI binary or pyvisa-py.')