def set_group(self, group):
        """
        Sets a group of Digital In 4 Bricklets that should work together. You can
        find Bricklets that can be grouped together with :func:`Get Available For Group`.

        The group consists of 4 elements. Element 1 in the group will get pins 0-3,
        element 2 pins 4-7, element 3 pins 8-11 and element 4 pins 12-15.

        Each element can either be one of the ports ('a' to 'd') or 'n' if it should
        not be used.

        For example: If you have two Digital In 4 Bricklets connected to port A and
        port B respectively, you could call with ``['a', 'b', 'n', 'n']``.

        Now the pins on the Digital In 4 on port A are assigned to 0-3 and the
        pins on the Digital In 4 on port B are assigned to 4-7. It is now possible
        to call :func:`Get Value` and read out two Bricklets at the same time.

        Changing the group configuration resets all edge counter configurations
        and values.
        """
        group = create_char_list(group)

        self.ipcon.send_request(
            self, BrickletIndustrialDigitalIn4.FUNCTION_SET_GROUP, (group, ),
            '4c', '')
Example #2
0
    def write_low_level(self, message_length, message_chunk_offset, message_chunk_data):
        """
        Writes characters to the RS232 interface. The characters can be binary data,
        ASCII or similar is not necessary.

        The return value is the number of characters that were written.

        See :func:`Set Configuration` for configuration possibilities
        regarding baud rate, parity and so on.
        """
        message_length = int(message_length)
        message_chunk_offset = int(message_chunk_offset)
        message_chunk_data = create_char_list(message_chunk_data)

        return self.ipcon.send_request(self, BrickletRS232V2.FUNCTION_WRITE_LOW_LEVEL, (message_length, message_chunk_offset, message_chunk_data), 'H H 60c', 'B')
Example #3
0
    def write_low_level(self, message_length, message_chunk_offset, message_chunk_data):
        """
        Writes characters to the RS232 interface. The characters can be binary data,
        ASCII or similar is not necessary.

        The return value is the number of characters that were written.

        See :func:`Set Configuration` for configuration possibilities
        regarding baud rate, parity and so on.
        """
        message_length = int(message_length)
        message_chunk_offset = int(message_chunk_offset)
        message_chunk_data = create_char_list(message_chunk_data)

        return self.ipcon.send_request(self, BrickletRS232V2.FUNCTION_WRITE_LOW_LEVEL, (message_length, message_chunk_offset, message_chunk_data), 'H H 60c', 'B')
Example #4
0
    def write(self, message, length):
        """
        Writes a string of up to 60 characters to the RS232 interface. The string
        can be binary data, ASCII or similar is not necessary.

        The length of the string has to be given as an additional parameter.

        The return value is the number of bytes that could be written.

        See :func:`Set Configuration` for configuration possibilities
        regarding baudrate, parity and so on.
        """
        message = create_char_list(message)
        length = int(length)

        return self.ipcon.send_request(self, BrickletRS232.FUNCTION_WRITE, (message, length), '60c B', 'B')
Example #5
0
    def write(self, message, length):
        """
        Writes a string of up to 60 characters to the RS232 interface. The string
        can be binary data, ASCII or similar is not necessary.

        The length of the string has to be given as an additional parameter.

        The return value is the number of bytes that could be written.

        See :func:`Set Configuration` for configuration possibilities
        regarding baudrate, parity and so on.
        """
        message = create_char_list(message)
        length = int(length)

        return self.ipcon.send_request(self, BrickletRS232.FUNCTION_WRITE,
                                       (message, length), '60c B', 'B')
Example #6
0
    def write(self, message):
        """
        Writes characters to the RS232 interface. The characters can be binary data,
        ASCII or similar is not necessary.

        The return value is the number of characters that were written.

        See :func:`Set Configuration` for configuration possibilities
        regarding baud rate, parity and so on.
        """
        message = create_char_list(message)

        if len(message) > 65535:
            raise Error(Error.INVALID_PARAMETER,
                        'Message can be at most 65535 items long')

        message_length = len(message)
        message_chunk_offset = 0

        if message_length == 0:
            message_chunk_data = ['\0'] * 60
            ret = self.write_low_level(message_length, message_chunk_offset,
                                       message_chunk_data)
            message_written = ret
        else:
            message_written = 0

            with self.stream_lock:
                while message_chunk_offset < message_length:
                    message_chunk_data = create_chunk_data(
                        message, message_chunk_offset, 60, '\0')
                    ret = self.write_low_level(message_length,
                                               message_chunk_offset,
                                               message_chunk_data)
                    message_written += ret

                    if ret < 60:
                        break  # either last chunk or short write

                    message_chunk_offset += 60

        return message_written
    def set_group(self, group):
        """
        Sets a group of Digital Out 4 Bricklets that should work together. You can
        find Bricklets that can be grouped together with :func:`Get Available For Group`.

        The group consists of 4 elements. Element 1 in the group will get pins 0-3,
        element 2 pins 4-7, element 3 pins 8-11 and element 4 pins 12-15.

        Each element can either be one of the ports ('a' to 'd') or 'n' if it should
        not be used.

        For example: If you have two Digital Out 4 Bricklets connected to port A and
        port B respectively, you could call with ``['a', 'b', 'n', 'n']``.

        Now the pins on the Digital Out 4 on port A are assigned to 0-3 and the
        pins on the Digital Out 4 on port B are assigned to 4-7. It is now possible
        to call :func:`Set Value` and control two Bricklets at the same time.
        """
        group = create_char_list(group)

        self.ipcon.send_request(self, BrickletIndustrialDigitalOut4.FUNCTION_SET_GROUP, (group,), '4c', '')
Example #8
0
    def write(self, message):
        """
        Writes characters to the RS232 interface. The characters can be binary data,
        ASCII or similar is not necessary.

        The return value is the number of characters that were written.

        See :func:`Set Configuration` for configuration possibilities
        regarding baud rate, parity and so on.
        """
        message = create_char_list(message)

        if len(message) > 65535:
            raise Error(Error.INVALID_PARAMETER, 'Message can be at most 65535 items long')

        message_length = len(message)
        message_chunk_offset = 0

        if message_length == 0:
            message_chunk_data = ['\0'] * 60
            ret = self.write_low_level(message_length, message_chunk_offset, message_chunk_data)
            message_written = ret
        else:
            message_written = 0

            with self.stream_lock:
                while message_chunk_offset < message_length:
                    message_chunk_data = create_chunk_data(message, message_chunk_offset, 60, '\0')
                    ret = self.write_low_level(message_length, message_chunk_offset, message_chunk_data)
                    message_written += ret

                    if ret < 60:
                        break # either last chunk or short write

                    message_chunk_offset += 60

        return message_written
    create_char([42, 17])  # int
    assert (False)
except:
    pass

try:
    create_char(256)  # int
    assert (False)
except:
    pass

#
# char list
#

assert (create_char_list('') == [])  # str
assert (create_char_list('a') == ['a'])  # str
assert (create_char_list('ab') == ['a', 'b'])  # str
assert (create_char_list([]) == [])
assert (create_char_list(['a']) == ['a'])  # str
assert (create_char_list(['a', 'b']) == ['a', 'b'])  # str

if sys.hexversion < 0x03000000:
    assert (create_char_list(u'') == [])  # unicode
    assert (create_char_list(u'a') == ['a'])  # unicode
    assert (create_char_list(u'ab') == ['a', 'b'])  # unicode
    assert (create_char_list([u'a']) == ['a'])  # unicode
    assert (create_char_list([u'a', u'b']) == ['a', 'b'])  # unicode
else:
    assert (create_char_list(b'') == [])  # bytes
    assert (create_char_list(b'a') == ['a'])  # bytes
    create_char([42, 17]) # int
    assert(False)
except:
    pass

try:
    create_char(256) # int
    assert(False)
except:
    pass

#
# char list
#

assert(create_char_list('') == []) # str
assert(create_char_list('a') == ['a']) # str
assert(create_char_list('ab') == ['a', 'b']) # str
assert(create_char_list([]) == [])
assert(create_char_list(['a']) == ['a']) # str
assert(create_char_list(['a', 'b']) == ['a', 'b']) # str

if sys.hexversion < 0x03000000:
    assert(create_char_list(u'') == []) # unicode
    assert(create_char_list(u'a') == ['a']) # unicode
    assert(create_char_list(u'ab') == ['a', 'b']) # unicode
    assert(create_char_list([u'a']) == ['a']) # unicode
    assert(create_char_list([u'a', u'b']) == ['a', 'b']) # unicode
else:
    assert(create_char_list(b'') == []) # bytes
    assert(create_char_list(b'a') == ['a']) # bytes