/usr/lib/python2.7/dist-packages/pyvisa/errors.py is in python-pyvisa 1.8-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | # -*- coding: utf-8 -*-
"""
pyvisa.errors
~~~~~~~~~~~~~
Defines exceptions hierarchy and textual explanations of VISA completion and error codes.
This file is part of PyVISA.
:copyright: 2014 by PyVISA Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
from __future__ import division, print_function, absolute_import
from . import util, constants
from .constants import *
completion_and_error_messages = {
VI_SUCCESS : ("VI_SUCCESS",
"Operation completed successfully."),
VI_SUCCESS_EVENT_EN : ("VI_SUCCESS_EVENT_EN",
"Specified event is already enabled for at "
"least one of the specified mechanisms."),
VI_SUCCESS_EVENT_DIS : ("VI_SUCCESS_EVENT_DIS",
"Specified event is already disabled for "
"at least one of the specified mechanisms."),
VI_SUCCESS_QUEUE_EMPTY : ("VI_SUCCESS_QUEUE_EMPTY",
"Operation completed successfully, but "
"queue was already empty."),
VI_SUCCESS_TERM_CHAR : ("VI_SUCCESS_TERM_CHAR",
"The specified termination character was "
"read."),
VI_SUCCESS_MAX_CNT : ("VI_SUCCESS_MAX_CNT",
"The number of bytes transferred is equal "
"to the requested input count. More data "
"may be available."),
VI_SUCCESS_DEV_NPRESENT : ("VI_SUCCESS_DEV_NPRESENT",
"Session opened successfully, but the "
"device at the specified address is not "
"responding."),
VI_SUCCESS_TRIG_MAPPED : ("VI_SUCCESS_TRIG_MAPPED",
"The path from trigSrc to trigDest is "
"already mapped."),
VI_SUCCESS_QUEUE_NEMPTY : ("VI_SUCCESS_QUEUE_NEMPTY",
"Wait terminated successfully on receipt "
"of an event notification. There is at "
"least one more event object of the "
"requested type(s) available for this "
"session."),
VI_SUCCESS_NCHAIN : ("VI_SUCCESS_NCHAIN",
"Event handled successfully. Do not invoke "
"any other handlers on this session for "
"this event."),
VI_SUCCESS_NESTED_SHARED : ("VI_SUCCESS_NESTED_SHARED",
"Operation completed successfully, and "
"this session has nested shared locks."),
VI_SUCCESS_NESTED_EXCLUSIVE: ("VI_SUCCESS_NESTED_EXCLUSIVE",
"Operation completed successfully, and "
"this session has nested exclusive locks."),
VI_SUCCESS_SYNC : ("VI_SUCCESS_SYNC",
"Operation completed successfully, but the "
"operation was actually synchronous rather "
"than asynchronous."),
VI_WARN_QUEUE_OVERFLOW : ("VI_WARN_QUEUE_OVERFLOW",
"VISA received more event information of "
"the specified type than the configured "
"queue size could hold."),
VI_WARN_CONFIG_NLOADED : ("VI_WARN_CONFIG_NLOADED",
"The specified configuration either does "
"not exist or could not be loaded. "
"VISA-specified defaults will be used."),
VI_WARN_NULL_OBJECT : ("VI_WARN_NULL_OBJECT",
"The specified object reference is "
"uninitialized."),
VI_WARN_NSUP_ATTR_STATE : ("VI_WARN_NSUP_ATTR_STATE",
"Although the specified state of the "
"attribute is valid, it is not supported "
"by this implementation."),
VI_WARN_UNKNOWN_STATUS : ("VI_WARN_UNKNOWN_STATUS",
"The status code passed to the operation "
"could not be interpreted."),
VI_WARN_NSUP_BUF : ("VI_WARN_NSUP_BUF",
"The specified I/O buffer type is not "
"supported."),
VI_WARN_EXT_FUNC_NIMPL : ("VI_WARN_EXT_FUNC_NIMPL",
"The operation succeeded, but a lower "
"level driver did not implement the "
"extended functionality."),
VI_ERROR_SYSTEM_ERROR : ("VI_ERROR_SYSTEM_ERROR",
"Unknown system error (miscellaneous "
"error)."),
VI_ERROR_INV_OBJECT : ("VI_ERROR_INV_OBJECT",
"The given session or object reference is "
"invalid."),
VI_ERROR_RSRC_LOCKED : ("VI_ERROR_RSRC_LOCKED",
"Specified type of lock cannot be "
"obtained, or specified operation cannot "
"be performed, because the resource is "
"locked."),
VI_ERROR_INV_EXPR : ("VI_ERROR_INV_EXPR",
"Invalid expression specified for search."),
VI_ERROR_RSRC_NFOUND : ("VI_ERROR_RSRC_NFOUND",
"Insufficient location information or the "
"requested device or resource is not "
"present in the system."),
VI_ERROR_INV_RSRC_NAME : ("VI_ERROR_INV_RSRC_NAME",
"Invalid resource reference specified. "
"Parsing error."),
VI_ERROR_INV_ACC_MODE : ("VI_ERROR_INV_ACC_MODE",
"Invalid access mode."),
VI_ERROR_TMO : ("VI_ERROR_TMO",
"Timeout expired before operation "
"completed."),
VI_ERROR_CLOSING_FAILED : ("VI_ERROR_CLOSING_FAILED",
"The VISA driver failed to properly close "
"the session or object reference. This "
"might be due to an error freeing internal "
"or OS resources, a failed network "
"connection, or a lower-level driver or OS "
"error."),
VI_ERROR_INV_DEGREE : ("VI_ERROR_INV_DEGREE",
"Specified degree is invalid."),
VI_ERROR_INV_JOB_ID : ("VI_ERROR_INV_JOB_ID",
"Specified job identifier is invalid."),
VI_ERROR_NSUP_ATTR : ("VI_ERROR_NSUP_ATTR",
"The specified attribute is not defined or "
"supported by the referenced object."),
VI_ERROR_NSUP_ATTR_STATE : ("VI_ERROR_NSUP_ATTR_STATE",
"The specified state of the attribute is "
"not valid, or is not supported as defined "
"by the object."),
VI_ERROR_ATTR_READONLY : ("VI_ERROR_ATTR_READONLY",
"The specified attribute is read-only."),
VI_ERROR_INV_LOCK_TYPE : ("VI_ERROR_INV_LOCK_TYPE",
"The specified type of lock is not "
"supported by this resource."),
VI_ERROR_INV_ACCESS_KEY : ("VI_ERROR_INV_ACCESS_KEY",
"The access key to the resource associated "
"with the specified session is invalid."),
VI_ERROR_INV_EVENT : ("VI_ERROR_INV_EVENT",
"Specified event type is not supported by "
"the resource."),
VI_ERROR_INV_MECH : ("VI_ERROR_INV_MECH",
"Invalid mechanism specified."),
VI_ERROR_HNDLR_NINSTALLED : ("VI_ERROR_HNDLR_NINSTALLED",
"A handler was not installed."),
VI_ERROR_INV_HNDLR_REF : ("VI_ERROR_INV_HNDLR_REF",
"The given handler reference is either "
"invalid or was not installed."),
VI_ERROR_INV_CONTEXT : ("VI_ERROR_INV_CONTEXT",
"Specified event context is invalid."),
VI_ERROR_QUEUE_OVERFLOW : ("VI_ERROR_QUEUE_OVERFLOW",
"The event queue for the specified type "
"has overflowed (usually due to previous "
"events not having been closed)."),
VI_ERROR_NENABLED : ("VI_ERROR_NENABLED",
"You must be enabled for events of the "
"specified type in order to receive them."),
VI_ERROR_ABORT : ("VI_ERROR_ABORT",
"User abort occurred during transfer."),
VI_ERROR_RAW_WR_PROT_VIOL : ("VI_ERROR_RAW_WR_PROT_VIOL",
"Violation of raw write protocol occurred "
"during transfer."),
VI_ERROR_RAW_RD_PROT_VIOL : ("VI_ERROR_RAW_RD_PROT_VIOL",
"Violation of raw read protocol occurred "
"during transfer."),
VI_ERROR_OUTP_PROT_VIOL : ("VI_ERROR_OUTP_PROT_VIOL",
"Device reported an output protocol error "
"during transfer."),
VI_ERROR_INP_PROT_VIOL : ("VI_ERROR_INP_PROT_VIOL",
"Device reported an input protocol error "
"during transfer."),
VI_ERROR_BERR : ("VI_ERROR_BERR",
"Bus error occurred during transfer."),
VI_ERROR_IN_PROGRESS : ("VI_ERROR_IN_PROGRESS",
"Unable to queue the asynchronous "
"operation because there is already an "
"operation in progress."),
VI_ERROR_INV_SETUP : ("VI_ERROR_INV_SETUP",
"Unable to start operation because setup "
"is invalid (usually due to attributes "
"being set to an inconsistent state)."),
VI_ERROR_QUEUE_ERROR : ("VI_ERROR_QUEUE_ERROR",
"Unable to queue the asynchronous "
"operation (usually due to the I/O "
"completion event not being enabled or "
"insufficient space in the session's "
"queue)."),
VI_ERROR_ALLOC : ("VI_ERROR_ALLOC",
"Insufficient system resources to perform "
"necessary memory allocation."),
VI_ERROR_INV_MASK : ("VI_ERROR_INV_MASK",
"Invalid buffer mask specified."),
VI_ERROR_IO : ("VI_ERROR_IO",
"Could not perform operation because of "
"I/O error."),
VI_ERROR_INV_FMT : ("VI_ERROR_INV_FMT",
"A format specifier in the format string "
"is invalid."),
VI_ERROR_NSUP_FMT : ("VI_ERROR_NSUP_FMT",
"A format specifier in the format string "
"is not supported."),
VI_ERROR_LINE_IN_USE : ("VI_ERROR_LINE_IN_USE",
"The specified trigger line is currently "
"in use."),
VI_ERROR_NSUP_MODE : ("VI_ERROR_NSUP_MODE",
"The specified mode is not supported by "
"this VISA implementation."),
VI_ERROR_SRQ_NOCCURRED : ("VI_ERROR_SRQ_NOCCURRED",
"Service request has not been received for "
"the session."),
VI_ERROR_INV_SPACE : ("VI_ERROR_INV_SPACE",
"Invalid address space specified."),
VI_ERROR_INV_OFFSET : ("VI_ERROR_INV_OFFSET",
"Invalid offset specified."),
VI_ERROR_INV_WIDTH : ("VI_ERROR_INV_WIDTH",
"Invalid access width specified."),
VI_ERROR_NSUP_OFFSET : ("VI_ERROR_NSUP_OFFSET",
"Specified offset is not accessible from "
"this hardware."),
VI_ERROR_NSUP_VAR_WIDTH : ("VI_ERROR_NSUP_VAR_WIDTH",
"Cannot support source and destination "
"widths that are different."),
VI_ERROR_WINDOW_NMAPPED : ("VI_ERROR_WINDOW_NMAPPED",
"The specified session is not currently "
"mapped."),
VI_ERROR_RESP_PENDING : ("VI_ERROR_RESP_PENDING",
"A previous response is still pending, "
"causing a multiple query error."),
VI_ERROR_NLISTENERS : ("VI_ERROR_NLISTENERS",
"No listeners condition is detected (both "
"NRFD and NDAC are deasserted)."),
VI_ERROR_NCIC : ("VI_ERROR_NCIC",
"The interface associated with this "
"session is not currently the controller "
"in charge."),
VI_ERROR_NSYS_CNTLR : ("VI_ERROR_NSYS_CNTLR",
"The interface associated with this "
"session is not the system controller."),
VI_ERROR_NSUP_OPER : ("VI_ERROR_NSUP_OPER",
"The given session or object reference "
"does not support this operation."),
VI_ERROR_INTR_PENDING : ("VI_ERROR_INTR_PENDING",
"An interrupt is still pending from a "
"previous call."),
VI_ERROR_ASRL_PARITY : ("VI_ERROR_ASRL_PARITY",
"A parity error occurred during transfer."),
VI_ERROR_ASRL_FRAMING : ("VI_ERROR_ASRL_FRAMING",
"A framing error occurred during transfer."),
VI_ERROR_ASRL_OVERRUN : ("VI_ERROR_ASRL_OVERRUN",
"An overrun error occurred during "
"transfer. A character was not read from "
"the hardware before the next character "
"arrived."),
VI_ERROR_TRIG_NMAPPED : ("VI_ERROR_TRIG_NMAPPED",
"The path from trigSrc to trigDest is not "
"currently mapped."),
VI_ERROR_NSUP_ALIGN_OFFSET : ("VI_ERROR_NSUP_ALIGN_OFFSET",
"The specified offset is not properly "
"aligned for the access width of the "
"operation."),
VI_ERROR_USER_BUF : ("VI_ERROR_USER_BUF",
"A specified user buffer is not valid or "
"cannot be accessed for the required size."),
VI_ERROR_RSRC_BUSY : ("VI_ERROR_RSRC_BUSY",
"The resource is valid, but VISA cannot "
"currently access it."),
VI_ERROR_NSUP_WIDTH : ("VI_ERROR_NSUP_WIDTH",
"Specified width is not supported by this "
"hardware."),
VI_ERROR_INV_PARAMETER : ("VI_ERROR_INV_PARAMETER",
"The value of some parameter (which "
"parameter is not known) is invalid."),
VI_ERROR_INV_PROT : ("VI_ERROR_INV_PROT",
"The protocol specified is invalid."),
VI_ERROR_INV_SIZE : ("VI_ERROR_INV_SIZE",
"Invalid size of window specified."),
VI_ERROR_WINDOW_MAPPED : ("VI_ERROR_WINDOW_MAPPED",
"The specified session currently contains "
"a mapped window."),
VI_ERROR_NIMPL_OPER : ("VI_ERROR_NIMPL_OPER",
"The given operation is not implemented."),
VI_ERROR_INV_LENGTH : ("VI_ERROR_INV_LENGTH",
"Invalid length specified."),
VI_ERROR_INV_MODE : ("VI_ERROR_INV_MODE",
"Invalid mode specified."),
VI_ERROR_SESN_NLOCKED : ("VI_ERROR_SESN_NLOCKED",
"The current session did not have a lock "
"on the resource."),
VI_ERROR_MEM_NSHARED : ("VI_ERROR_MEM_NSHARED",
"The device does not export any memory."),
VI_ERROR_LIBRARY_NFOUND : ("VI_ERROR_LIBRARY_NFOUND",
"A code library required by VISA could not "
"be located or loaded."),
VI_ERROR_NSUP_INTR : ("VI_ERROR_NSUP_INTR",
"The interface cannot generate an "
"interrupt on the requested level or with "
"the requested statusID value."),
VI_ERROR_INV_LINE : ("VI_ERROR_INV_LINE",
"The value specified by the line parameter "
"is invalid."),
VI_ERROR_FILE_ACCESS : ("VI_ERROR_FILE_ACCESS",
"An error occurred while trying to open "
"the specified file. Possible reasons "
"include an invalid path or lack of access "
"rights."),
VI_ERROR_FILE_IO : ("VI_ERROR_FILE_IO",
"An error occurred while performing I/O on "
"the specified file."),
VI_ERROR_NSUP_LINE : ("VI_ERROR_NSUP_LINE",
"One of the specified lines (trigSrc or "
"trigDest) is not supported by this VISA "
"implementation, or the combination of "
"lines is not a valid mapping."),
VI_ERROR_NSUP_MECH : ("VI_ERROR_NSUP_MECH",
"The specified mechanism is not supported "
"for the given event type."),
VI_ERROR_INTF_NUM_NCONFIG : ("VI_ERROR_INTF_NUM_NCONFIG",
"The interface type is valid but the "
"specified interface number is not "
"configured."),
VI_ERROR_CONN_LOST : ("VI_ERROR_CONN_LOST",
"The connection for the given session has "
"been lost."),
VI_ERROR_MACHINE_NAVAIL : ("VI_ERROR_MACHINE_NAVAIL",
"The remote machine does not exist or is "
"not accepting any connections. If the "
"NI-VISA server is installed and running "
"on the remote machine, it may have an "
"incompatible version or may be listening "
"on a different port."),
VI_ERROR_NPERMISSION : ("VI_ERROR_NPERMISSION",
"Access to the resource or remote machine "
"is denied. This is due to lack of "
"sufficient privileges for the current "
"user or machine")
}
default_warnings = frozenset([VI_SUCCESS_MAX_CNT, VI_SUCCESS_DEV_NPRESENT,
VI_SUCCESS_SYNC, VI_WARN_QUEUE_OVERFLOW,
VI_WARN_CONFIG_NLOADED, VI_WARN_NULL_OBJECT,
VI_WARN_NSUP_ATTR_STATE, VI_WARN_UNKNOWN_STATUS,
VI_WARN_NSUP_BUF, VI_WARN_EXT_FUNC_NIMPL])
class Error(Exception):
"""Abstract basic exception class for this module."""
def __init__(self, description):
super(Error, self).__init__(description)
class VisaIOError(Error):
"""Exception class for VISA I/O errors.
Please note that all values for "error_code" are negative according to the
specification (VPP-4.3.2, observation 3.3.2) and the NI implementation.
"""
def __init__(self, error_code):
abbreviation, description = completion_and_error_messages.get(error_code,
('?', 'Unknown code.'))
super(VisaIOError, self).__init__('%s (%d): %s' % (abbreviation, error_code, description))
self.error_code = error_code
self.abbreviation = abbreviation
self.description = description
class VisaIOWarning(Warning):
"""Exception class for VISA I/O warnings.
According to the specification VPP-4.3.2 and the NI implementation.
"""
def __init__(self, error_code):
abbreviation, description = completion_and_error_messages.get(error_code,
('?', 'Unknown code.'))
super(VisaIOWarning, self).__init__('%s (%d): %s' % (abbreviation, error_code, description))
self.error_code = error_code
self.abbreviation = abbreviation
self.description = description
class VisaTypeError(Error):
"""Exception class for wrong types in VISA function argument lists.
Raised if unsupported types are given to scanf, sscanf, printf, sprintf,
and queryf. Because the current implementation doesn't analyse the format
strings, it can only deal with integers, floats, and strings.
Additionally, this exception is raised by install_handler if un unsupported
type is used for the user handle.
"""
class UnknownHandler(Error):
"""Exception class for invalid handler data given to uninstall_handler().
uninstall_handler() checks whether the handler and user_data parameters
point to a known handler previously installed with install_handler(). If
it can't find it, this exception is raised.
"""
def __init__(self, event_type, handler, user_handle):
super(UnknownHandler, self).__init__('%s, %s, %s' % (event_type, handler, user_handle))
class OSNotSupported(Error):
def __init__(self, os):
super(OSNotSupported, self).__init__(os + " is not yet supported by PyVISA")
class InvalidBinaryFormat(Error):
def __init__(self, description=""):
if description:
description = ": " + description
super(InvalidBinaryFormat, self).__init__("Unrecognized binary data format" + description)
class InvalidSession(Error):
"""Exception raised when an invalid session is requested.
"""
def __init__(self):
super(InvalidSession, self).__init__('Invalid session handle. The resource might be closed.')
class LibraryError(OSError, Error):
@classmethod
def from_exception(cls, exc, filename):
try:
msg = str(exc)
if ': image not found' in msg:
msg = ' File not found or not readable.'
elif ': no suitable image found' in msg:
if 'no matching architecture' in msg:
return LibraryError.from_wrong_arch(filename)
else:
msg = 'Could not determine filetype.'
elif 'wrong ELF class' in msg:
return LibraryError.from_wrong_arch(filename)
except UnicodeDecodeError:
return cls('Error while accessing %s:' % filename)
return cls('Error while accessing %s: %s' % (filename, msg))
@classmethod
def from_wrong_arch(cls, filename):
s = ''
details = util.get_system_details(backends=False)
visalib = util.LibraryPath(filename, 'user' if filename == util.read_user_library_path() else 'auto')
s += 'No matching architecture.\n'
s += ' Current Python interpreter is %s bits\n' % details['bits']
s += ' The library in: %s\n' % visalib.path
s += ' found by: %s\n' % visalib.found_by
s += ' bitness: %s\n' % visalib.bitness
return cls('Error while accessing %s: %s' % (filename, s))
def _args_to_str(args, kwargs):
return 'args=%s, kwargs=%s' % (args, kwargs)
def return_handler(module_logger, first_is_session=True):
"""Decorator for VISA library classes.
"""
def _outer(visa_library_method):
def _inner(self, session, *args, **kwargs):
ret_value = visa_library_method(*args, **kwargs)
module_logger.debug('%s%s -> %r',
visa_library_method.__name__,
_args_to_str(args, kwargs),
ret_value)
try:
ret_value = constants.StatusCode(ret_value)
except ValueError:
pass
if first_is_session:
self._last_status = ret_value
self._last_status_in_session[session] = ret_value
if ret_value < 0:
raise VisaIOError(ret_value)
if ret_value in self.issue_warning_on:
if session and ret_value not in self._ignore_warning_in_session[session]:
module_logger.warn(VisaIOWarning(ret_value), stacklevel=2)
return ret_value
return _inner
return _outer
|