Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Class for attributes with boolean values.
"""
@classmethod
def redoc(cls):
super(BooleanAttribute, cls).redoc()
cls.__doc__ += '\n:type: bool'
def post_get(self, value):
return value == constants.VI_TRUE
def pre_set(self, value):
return constants.VI_TRUE if value else constants.VI_FALSE
class CharAttribute(Attribute):
"""Class for attributes with char values.
"""
@classmethod
def redoc(cls):
super(CharAttribute, cls).redoc()
cls.__doc__ += '\n:range: 0 <= x <= 255\n:type: int'
def post_get(self, value):
return chr(value)
def pre_set(self, value):
return ord(value)
# noinspection PyPep8Naming
py_name = 'model_code'
visa_name = 'VI_ATTR_MODEL_CODE'
visa_type = 'ViUInt16'
default = NotAvailable
read, write, local = True, False, False
min_value, max_value, values = 0x0, 0xFFFF, []
# noinspection PyPep8Naming
class AttrVI_ATTR_MODEL_NAME(Attribute):
"""This string attribute is the model name of the device.
"""
resources = [(constants.InterfaceType.pxi, 'INSTR'),
(constants.InterfaceType.pxi, 'BACKPLANE'),
(constants.InterfaceType.usb, 'INSTR'),
(constants.InterfaceType.usb, 'RAW'),
(constants.InterfaceType.vxi, 'INSTR')]
py_name = 'model_name'
visa_name = 'VI_ATTR_MODEL_NAME'
visa_type = 'ViString'
default = NotAvailable
py_name = ''
visa_name = 'VI_ATTR_TCPIP_DEVICE_NAME'
visa_type = 'ViString'
default = NotAvailable
read, write, local = True, False, False
# [u'N/A']
# noinspection PyPep8Naming
class AttrVI_ATTR_TCPIP_HOSTNAME(Attribute):
"""This specifies the host name of the device. If no host name is
available, this attribute returns an empty string.
"""
resources = [(constants.InterfaceType.tcpip, 'INSTR'),
(constants.InterfaceType.tcpip, 'SOCKET')]
py_name = ''
visa_name = 'VI_ATTR_TCPIP_HOSTNAME'
visa_type = 'ViString'
default = NotAvailable
read, write, local = True, False, False
# See docstring
py_name = ''
visa_name = 'VI_ATTR_RM_SESSION'
visa_type = 'ViUInt32'
default = NotAvailable
read, write, local = True, False, True
min_value, max_value, values = 0, 4294967295, []
# noinspection PyPep8Naming
class AttrVI_ATTR_RSRC_CLASS(Attribute):
"""VI_ATTR_RSRC_CLASS specifies the resource class (for example, "INSTR")
as defined by the canonical resource name.
"""
resources = AllSessionTypes
py_name = 'resource_class'
visa_name = 'VI_ATTR_RSRC_CLASS'
visa_type = 'ViString'
default = NotAvailable
read, write, local = True, False, False
# [u'N/A']
py_name = ''
visa_name = 'VI_ATTR_TCPIP_ADDR'
visa_type = 'ViString'
default = NotAvailable
read, write, local = True, False, False
# [u'N/A']
# noinspection PyPep8Naming
class AttrVI_ATTR_TCPIP_DEVICE_NAME(Attribute):
"""This specifies the LAN device name used by the VXI-11 or LXI protocol
during connection.
"""
resources = [(constants.InterfaceType.tcpip, 'INSTR')]
py_name = ''
visa_name = 'VI_ATTR_TCPIP_DEVICE_NAME'
visa_type = 'ViString'
default = NotAvailable
read, write, local = True, False, False
# [u'N/A']
@classmethod
def redoc(cls):
super(ValuesAttribute, cls).redoc()
cls.__doc__ += '\n:values: %s' % cls.values
def pre_set(self, value):
if value not in self.values:
raise ValueError('%r is an invalid value for attribute %s, '
'should be in %s' % (value,
self.visa_name,
self.values))
return value
class BooleanAttribute(Attribute):
"""Class for attributes with boolean values.
"""
@classmethod
def redoc(cls):
super(BooleanAttribute, cls).redoc()
cls.__doc__ += '\n:type: bool'
def post_get(self, value):
return value == constants.VI_TRUE
def pre_set(self, value):
return constants.VI_TRUE if value else constants.VI_FALSE
class CharAttribute(Attribute):
"""
resources = [(constants.InterfaceType.vxi, 'INSTR')]
py_name = ''
visa_name = 'VI_ATTR_IMMEDIATE_SERV'
visa_type = 'ViBoolean'
default = NotAvailable
read, write, local = True, False, False
# noinspection PyPep8Naming
class AttrVI_ATTR_INTF_INST_NAME(Attribute):
"""VI_ATTR_INTF_INST_NAME specifies human-readable text that describes
the given interface.
"""
resources = AllSessionTypes
py_name = ''
visa_name = 'VI_ATTR_INTF_INST_NAME'
visa_type = 'ViString'
default = NotAvailable
read, write, local = True, False, False
# [u'N/A']
cls.__doc__ += '\n:type: :class:%s.%s' % (cls.enum_type.__module__,
cls.enum_type.__name__)
def post_get(self, value):
return self.enum_type(value)
def pre_set(self, value):
if value not in self.enum_type:
raise ValueError('%r is an invalid value for attribute %s, '
'should be a %r' % (value,
self.visa_name,
self.enum_type))
return value
class IntAttribute(Attribute):
"""Class for attributes with integers values.
"""
@classmethod
def redoc(cls):
super(IntAttribute, cls).redoc()
cls.__doc__ += '\n:type: int'
def post_get(self, value):
return int(value)
class RangeAttribute(IntAttribute):
"""Class for integer attributes with values within a range.
"""
(constants.InterfaceType.usb, 'RAW'),
(constants.InterfaceType.vxi, 'INSTR')]
py_name = ''
visa_name = 'VI_ATTR_SUPPRESS_END_EN'
visa_type = 'ViBoolean'
default = False
read, write, local = True, True, True
# noinspection PyPep8Naming
class AttrVI_ATTR_TCPIP_ADDR(Attribute):
"""This is the TCPIP address of the device to which the session is
connected. This string is formatted in dot notation.
"""
resources = [(constants.InterfaceType.tcpip, 'INSTR'),
(constants.InterfaceType.tcpip, 'SOCKET')]
py_name = ''
visa_name = 'VI_ATTR_TCPIP_ADDR'
visa_type = 'ViString'
default = NotAvailable
read, write, local = True, False, False
@classmethod
def in_resource(cls, session_type):
"""Returns True if the attribute is part of a given session type.
The session_type is a tuple with the interface type and resource_class
:type session_type: (constants.InterfaceType, str)
:rtype: bool
"""
if cls.resources is AllSessionTypes:
return True
return session_type in cls.resources
class EnumAttribute(Attribute):
"""Class for attributes with values that map to a PyVISA Enum.
"""
#: Enum type with valid values.
enum_type = None
@classmethod
def redoc(cls):
super(EnumAttribute, cls).redoc()
cls.__doc__ += '\n:type: :class:%s.%s' % (cls.enum_type.__module__,
cls.enum_type.__name__)
def post_get(self, value):
return self.enum_type(value)
def pre_set(self, value):