How to use the pyvisa.constants.InterfaceType function in PyVISA

To help you get started, we’ve selected a few PyVISA examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyvisa / pyvisa-sim / pyvisa-sim / usb.py View on Github external
return out, constants.StatusCode.success_max_count_read
        else:
            return out, constants.StatusCode.error_timeout

    def write(self, data):
        send_end = self.get_attribute(constants.VI_ATTR_SEND_END_EN)

        for i in range(len(data)):
            self.device.write(data[i:i+1])

        if send_end:
            # EOM 4882
            pass


@sessions.Session.register(constants.InterfaceType.usb, 'RAW')
class USBRawSession(sessions.Session):

    def __init__(self, resource_manager_session, resource_name, parsed):
        super(USBRawSession, self).__init__(resource_manager_session, resource_name, parsed)

    def after_parsing(self):
        self.attrs[constants.VI_ATTR_INTF_NUM] = int(self.parsed.board)
        self.attrs[constants.VI_ATTR_MANF_ID] = self.parsed.manufacturer_id
        self.attrs[constants.VI_ATTR_MODEL_CODE] = self.parsed.model_code
        self.attrs[constants.VI_ATTR_USB_SERIAL_NUM] = self.parsed.serial_number
        self.attrs[constants.VI_ATTR_USB_INTFC_NUM] = int(self.parsed.board)

    def read(self, count):
        end_char, _ = self.get_attribute(constants.VI_ATTR_TERMCHAR)
        enabled, _ = self.get_attribute(constants.VI_ATTR_TERMCHAR_EN)
        timeout, _ = self.get_attribute(constants.VI_ATTR_TMO_VALUE)
github pyvisa / pyvisa-py / pyvisa-py / tcpip.py View on Github external
""" Sets timeout calculated value from python way to VI_ way

        """
        if value == constants.VI_TMO_INFINITE:
            self.timeout = None
            self._io_timeout = 2**32-1
        elif value == constants.VI_TMO_IMMEDIATE:
            self.timeout = 0
            self._io_timeout = 0
        else:
            self.timeout = value / 1000.0
            self._io_timeout = int(self.timeout*1000)
        return StatusCode.success


@Session.register(constants.InterfaceType.tcpip, 'SOCKET')
class TCPIPSocketSession(Session):
    """A TCPIP Session that uses the network standard library to do the low
    level communication.

    """
    # Details about implementation:
    # On Windows, select is not interrupted by KeyboardInterrupt, to avoid
    # blocking for very long time, we use a decreasing timeout in select.
    # A minimum select timeout which prevents using too short select interval
    # is also calculated and select timeout is not lower that that minimum
    # timeout. The absolute minimum is 1 ms as a consequence.
    # This is valid for connect and read operations

    @staticmethod
    def list_resources():
        # TODO: is there a way to get this?
github pyvisa / pyvisa-sim / pyvisa-sim / gpib.py View on Github external
from __future__ import division, unicode_literals, print_function, absolute_import
from six.moves import range

try:
    import six.moves.queue as queue
except ImportError:
    import queue

import time

from pyvisa import constants

from . import sessions


@sessions.Session.register(constants.InterfaceType.gpib, 'INSTR')
class GPIBInstrumentSession(sessions.Session):

    def after_parsing(self):
        self.attrs[constants.VI_ATTR_INTF_NUM] = int(self.parsed.board)
        self.attrs[constants.VI_ATTR_GPIB_PRIMARY_ADDR] = int(self.parsed.primary_address)
        self.attrs[constants.VI_ATTR_GPIB_SECONDARY_ADDR] = int(self.parsed.secondary_address)

    def read(self, count):
        end_char, _ = self.get_attribute(constants.VI_ATTR_TERMCHAR)
        enabled, _ = self.get_attribute(constants.VI_ATTR_TERMCHAR_EN)
        timeout, _ = self.get_attribute(constants.VI_ATTR_TMO_VALUE)
        timeout /= 1000

        start = time.time()

        out = b''
github pyvisa / pyvisa / pyvisa / rname.py View on Github external
def interface_type_const(self):
        try:
            return getattr(constants.InterfaceType, self.interface_type.lower())
        except:
            return constants.InterfaceType.unknown
github pyvisa / pyvisa / pyvisa / resources / firewire.py View on Github external
High level wrapper for VXI resources.

    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, unicode_literals, print_function, absolute_import

from .. import constants

from .registerbased import RegisterBasedResource


@RegisterBasedResource.register(constants.InterfaceType.firewire, 'INSTR')
class FirewireInstrument(RegisterBasedResource):
    """Communicates with to devices of type VXI::VXI logical address[::INSTR]
github pyvisa / pyvisa-py / pyvisa_py / sessions.py View on Github external
Use it to do final clean ups.

        """

    #: Session handle of the parent Resource Manager
    resource_manager_session: VISARMSession

    #: Name of the resource this session is communicating with
    resource_name: str

    #: Parsed representation of the resource name.
    parsed: rname.ResourceName

    #: Session type as (Interface Type, Resource Class)
    session_type: Tuple[constants.InterfaceType, str]

    #: Timeout in seconds to use when opening the resource.
    open_timeout: Optional[float]

    #: Value of the timeout in seconds used for general operation
    timeout: Optional[float]

    #: Used as a place holder for the object doing the lowlevel communication.
    interface: Any

    #: Used for attributes not handled by the underlying interface.
    #: Values are get or set automatically by get_attribute and set_attribute
    attrs: Dict[constants.ResourceAttribute, Any]

    #: Maps (Interface Type, Resource Class) to Python class encapsulating that
    #: resource.
github pyvisa / pyvisa-sim / pyvisa-sim / serial.py View on Github external
from six.moves import range

try:
    import six.moves.queue as queue
except ImportError:
    import queue

import time

from pyvisa import constants

from . import common
from . import sessions


@sessions.Session.register(constants.InterfaceType.asrl, 'INSTR')
class SerialInstrumentSession(sessions.Session):

    def after_parsing(self):
        self.attrs[constants.VI_ATTR_INTF_NUM] = int(self.parsed.board)

    def read(self, count):

        # TODO: Implement VI_ATTR_SUPPRESS_END_EN
        end_in, _ = self.get_attribute(constants.VI_ATTR_ASRL_END_IN)

        end_char, _ = self.get_attribute(constants.VI_ATTR_TERMCHAR)
        end_char = common.int_to_byte(end_char)

        enabled, _ = self.get_attribute(constants.VI_ATTR_TERMCHAR_EN)
        timeout, _ = self.get_attribute(constants.VI_ATTR_TMO_VALUE)
        timeout /= 1000