Esempio n. 1
0
 def __set_stop_bits(self, bits):
     deci_bits = 10 * bits
     if 9 < deci_bits < 11: deci_bits = 10
     elif 14 < deci_bits < 16: deci_bits = 15
     elif 19 < deci_bits < 21: deci_bits = 20
     else: raise ValueError, "invalid number of stop bits"
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_STOP_BITS, deci_bits)
Esempio n. 2
0
 def __set_stop_bits(self, bits):
     deci_bits = 10 * bits
     if 9 < deci_bits < 11: deci_bits = 10
     elif 14 < deci_bits < 16: deci_bits = 15
     elif 19 < deci_bits < 21: deci_bits = 20
     else: raise ValueError, "invalid number of stop bits"
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_STOP_BITS, deci_bits)
Esempio n. 3
0
    def __init__(self, resource_name=None, **keyw):
        """ResourceTemplate class constructor.  It opens a session to the
        resource.

        Parameters:
        resource_name -- (optional) the VISA name for the resource,
            e.g. "GPIB::10".  If "None", it's assumed that the resource manager
            is to be constructed.
        keyw -- keyword argument for the class constructor of the device instance
            to be generated.  Allowed arguments: lock, timeout.  See Instrument
            class for a detailed description.

        """
        _warn_for_invalid_keyword_arguments(keyw, ("lock", "timeout"))
        if self.__class__ is ResourceTemplate:
            raise TypeError("trying to instantiate an abstract class")
        if resource_name is not None:  # is none for the resource manager
            warnings.filterwarnings("ignore", "VI_SUCCESS_DEV_NPRESENT")
            self.vi = vpp43.open(resource_manager.session, resource_name,
                                 keyw.get("lock", VI_NO_LOCK))
            if vpp43.get_status() == VI_SUCCESS_DEV_NPRESENT:
                # okay, the device was not ready when we opened the session.
                # Now it gets five seconds more to become ready.  Every 0.1
                # seconds we probe it with viClear.
                passed_time = 0  # in seconds
                while passed_time < 5.0:
                    time.sleep(0.1)
                    passed_time += 0.1
                    try:
                        vpp43.clear(self.vi)
                    except VisaIOError as error:
                        if error.error_code == VI_ERROR_NLISTENERS:
                            continue
                        else:
                            raise
                    break
                else:
                    # Very last chance, this time without exception handling
                    time.sleep(0.1)
                    passed_time += 0.1
                    vpp43.clear(self.vi)
            _removefilter("ignore", "VI_SUCCESS_DEV_NPRESENT")
            timeout = keyw.get("timeout", 5)
            if timeout is None:
                vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE,
                                    VI_TMO_INFINITE)
            else:
                self.timeout = timeout
Esempio n. 4
0
    def __init__(self, resource_name=None, **keyw):
        """ResourceTemplate class constructor.  It opens a session to the
        resource.

        Parameters:
        resource_name -- (optional) the VISA name for the resource,
            e.g. "GPIB::10".  If "None", it's assumed that the resource manager
            is to be constructed.
        keyw -- keyword argument for the class constructor of the device instance
            to be generated.  Allowed arguments: lock, timeout.  See Instrument
            class for a detailed description.

        """
        _warn_for_invalid_keyword_arguments(keyw, ("lock", "timeout"))
        if self.__class__ is ResourceTemplate:
            raise TypeError, "trying to instantiate an abstract class"
        if resource_name is not None:  # is none for the resource manager
            warnings.filterwarnings("ignore", "VI_SUCCESS_DEV_NPRESENT")
            self.vi = vpp43.open(resource_manager.session, resource_name,
                                 keyw.get("lock", VI_NO_LOCK))
            if vpp43.get_status() == VI_SUCCESS_DEV_NPRESENT:
                # okay, the device was not ready when we opened the session.
                # Now it gets five seconds more to become ready.  Every 0.1
                # seconds we probe it with viClear.
                passed_time = 0  # in seconds
                while passed_time < 5.0:
                    time.sleep(0.1)
                    passed_time += 0.1
                    try:
                        vpp43.clear(self.vi)
                    except VisaIOError, error:
                        if error.error_code == VI_ERROR_NLISTENERS:
                            continue
                        else: raise
                    break
                else:
                    # Very last chance, this time without exception handling
                    time.sleep(0.1)
                    passed_time += 0.1
                    vpp43.clear(self.vi)
            _removefilter("ignore", "VI_SUCCESS_DEV_NPRESENT")
            timeout = keyw.get("timeout", 5)
            if timeout is None:
                vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE,
                                    VI_TMO_INFINITE)
            else:
                self.timeout = timeout
Esempio n. 5
0
    def __init__(self, resource_name=None, **keyw):

        _warn_for_invalid_keyword_arguments(keyw, ("lock", "timeout"))

        if self.__class__ is ResourceTemplate:
            raise TypeError("trying to instantiate an abstract class")

        if resource_name is None:  # is none for the resource manager
            return

        warnings.filterwarnings("ignore", "VI_SUCCESS_DEV_NPRESENT")
        self.vi = vpp43.open(resource_manager.session, resource_name,
                             keyw.get("lock", VI_NO_LOCK))

        if vpp43.get_status() == VI_SUCCESS_DEV_NPRESENT:
            # okay, the device was not ready when we opened the session.
            # Now it gets five seconds more to become ready.  Every 0.1
            # seconds we probe it with viClear.
            passed_time = 0  # in seconds
            while passed_time < 5.0:
                time.sleep(0.1)
                passed_time += 0.1
                try:
                    vpp43.clear(self.vi)
                except VisaIOError as error:
                    if error.error_code != VI_ERROR_NLISTENERS:
                        raise
                break
            else:
                # Very last chance, this time without exception handling
                time.sleep(0.1)
                passed_time += 0.1
                vpp43.clear(self.vi)

        _removefilter("ignore", "VI_SUCCESS_DEV_NPRESENT")
        timeout = keyw.get("timeout", 5)
        if timeout is None:
            vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE, VI_TMO_INFINITE)
        else:
            self.timeout = timeout
Esempio n. 6
0
 def __set_term_chars(self, term_chars):
     """Set a new termination character sequence.  See below the property
     "term_char"."""
     # First, reset termination characters, in case something bad happens.
     self.__term_chars = ""
     vpp43.set_attribute(self.vi, VI_ATTR_TERMCHAR_EN, VI_FALSE)
     if term_chars == "" or term_chars == None:
         self.__term_chars = term_chars
         return
     # Only the last character in term_chars is the real low-level
     # termination character, the rest is just used for verification after
     # each read operation.
     last_char = term_chars[-1]
     # Consequently, it's illogical to have the real termination character
     # twice in the sequence (otherwise reading would stop prematurely).
     if term_chars[:-1].find(last_char) != -1:
         raise ValueError, "ambiguous ending in termination characters"
     vpp43.set_attribute(self.vi, VI_ATTR_TERMCHAR, ord(last_char))
     vpp43.set_attribute(self.vi, VI_ATTR_TERMCHAR_EN, VI_TRUE)
     self.__term_chars = term_chars
Esempio n. 7
0
 def __set_term_chars(self, term_chars):
     """Set a new termination character sequence.  See below the property
     "term_char"."""
     # First, reset termination characters, in case something bad happens.
     self.__term_chars = ""
     vpp43.set_attribute(self.vi, VI_ATTR_TERMCHAR_EN, VI_FALSE)
     if term_chars == "" or term_chars == None:
         self.__term_chars = term_chars
         return
     # Only the last character in term_chars is the real low-level
     # termination character, the rest is just used for verification after
     # each read operation.
     last_char = term_chars[-1]
     # Consequently, it's illogical to have the real termination character
     # twice in the sequence (otherwise reading would stop prematurely).
     if term_chars[:-1].find(last_char) != -1:
         raise ValueError, "ambiguous ending in termination characters"
     vpp43.set_attribute(self.vi, VI_ATTR_TERMCHAR, ord(last_char))
     vpp43.set_attribute(self.vi, VI_ATTR_TERMCHAR_EN, VI_TRUE)
     self.__term_chars = term_chars
Esempio n. 8
0
 def __del_timeout(self):
     timeout = self.__get_timeout()  # just to test whether it's defined
     vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE, VI_TMO_INFINITE)
Esempio n. 9
0
 def __set_data_bits(self, bits):
     if not 5 <= bits <= 8:
         raise ValueError, "number of data bits must be from 5 to 8"
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_DATA_BITS, bits)
Esempio n. 10
0
 def __set_baud_rate(self, rate):
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_BAUD, rate)
Esempio n. 11
0
 def __set_send_end(self, send):
     if send:
         vpp43.set_attribute(self.vi, VI_ATTR_SEND_END_EN, VI_TRUE)
     else:
         vpp43.set_attribute(self.vi, VI_ATTR_SEND_END_EN, VI_FALSE)
Esempio n. 12
0
 def trigger(self):
     """Sends a software trigger to the device."""
     vpp43.set_attribute(self.vi, VI_ATTR_TRIG_ID, VI_TRIG_SW)
     vpp43.assert_trigger(self.vi, VI_TRIG_PROT_DEFAULT)
Esempio n. 13
0
 def __set_baud_rate(self, rate):
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_BAUD, rate)
Esempio n. 14
0
 def __set_timeout(self, timeout):
     if not(0 <= timeout <= 4294967):
         raise ValueError, "timeout value is invalid"
     vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE, int(timeout * 1000))
Esempio n. 15
0
 def trigger(self):
     """Sends a software trigger to the device."""
     vpp43.set_attribute(self.vi, VI_ATTR_TRIG_ID, VI_TRIG_SW)
     vpp43.assert_trigger(self.vi, VI_TRIG_PROT_DEFAULT)
Esempio n. 16
0
 def __set_timeout(self, timeout):
     if not(0 <= timeout <= 4294967):
         raise ValueError, "timeout value is invalid"
     vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE, int(timeout * 1000))
Esempio n. 17
0
 def __set_end_input(self, termination):
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_END_IN, termination)
Esempio n. 18
0
 def __set_parity(self, parity):
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_PARITY, parity)
Esempio n. 19
0
 def __set_data_bits(self, bits):
     if not 5 <= bits <= 8:
         raise ValueError, "number of data bits must be from 5 to 8"
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_DATA_BITS, bits)
Esempio n. 20
0
 def __set_parity(self, parity):
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_PARITY, parity)
Esempio n. 21
0
 def __del_timeout(self):
     timeout = self.__get_timeout()  # just to test whether it's defined
     vpp43.set_attribute(self.vi, VI_ATTR_TMO_VALUE, VI_TMO_INFINITE)
Esempio n. 22
0
 def __set_end_input(self, termination):
     vpp43.set_attribute(self.vi, VI_ATTR_ASRL_END_IN, termination)
Esempio n. 23
0
 def __set_send_end(self, send):
     if send:
         vpp43.set_attribute(self.vi, VI_ATTR_SEND_END_EN, VI_TRUE)
     else:
         vpp43.set_attribute(self.vi, VI_ATTR_SEND_END_EN, VI_FALSE)