Пример #1
0
    def getIoGroup(self, channels, values):
        """Get the values of a group of analog input channels.
            
        This method calls the GetIoGroup function of the module and
            returns the values of a group of analog input channels.
        
        Args:
            channels: Tuple with 4 boolean values (one for each channel).
                A channel is only read if the corresponding channel is
                true.
            values: Value objects
                A tuple with 4 value objects. The value objects must be
                either ValueVOS4, ValueVOS2, ValueCUS4 or ValueANU2.
                The function fills the objects with read data.
            
        Returns:
            IO_RETURN_OK in case of success, otherwise detailed IoReturn
            error code.
        
        Raises:
            TypeError: Passed argument types are wrong
            ValueError: Channel value is out of range
        """
        if not isinstance(channels, tuple):
            raise TypeError('Expected channels as a tuple with 4 channels \
                (bools), got %s' % type(channels))

        if (len(channels) < 4):
            raise TypeError('Expected 4 channels, got %d' % len(channels))

        for x in range(4):
            if not isinstance(channels[x], int):
                raise TypeError('Expected channel as bool, got %s' %
                                type(channels[x]))

        if not isinstance(values, tuple):
            raise TypeError(
                'Expected values as a tuple with 4 values, got %s' %
                type(values))

        if (len(values) < 4):
            raise TypeError('Expected 4 values, got %d' % len(values))

        for x in range(4):
            if not isinstance(values[x],
                              (ValueANU2, ValueVOS2, ValueVOS4, ValueCUS4)):
                raise TypeError('Expected value as ValueANU2 or ValueVOS2, \
                    ValueVOS4 or ValueCUS4 got %s' % type(values[x]))

        cmd = Cmd(self.com)
        return cmd.getIoGroup(channels, values)