コード例 #1
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def set_port_configuration(self, port, selection_mask, direction, value):
        """
        Configures the value and direction of a specified port. Possible directions
        are 'i' and 'o' for input and output.

        If the direction is configured as output, the value is either high or low
        (set as *true* or *false*).

        If the direction is configured as input, the value is either pull-up or
        default (set as *true* or *false*).

        For example:

        * ('a', 255, 'i', true) or ('a', 0b11111111, 'i', true) will set all pins of port A as input pull-up.
        * ('a', 128, 'i', false) or ('a', 0b10000000, 'i', false) will set pin 7 of port A as input default (floating if nothing is connected).
        * ('b', 3, 'o', false) or ('b', 0b00000011, 'o', false) will set pins 0 and 1 of port B as output low.
        * ('b', 4, 'o', true) or ('b', 0b00000100, 'o', true) will set pin 2 of port B as output high.

        Running monoflop timers for the selected pins will be aborted if this
        function is called.

        The default configuration is input with pull-up.
        """
        port = create_char(port)
        selection_mask = int(selection_mask)
        direction = create_char(direction)
        value = bool(value)

        self.ipcon.send_request(self, BrickletIO16.FUNCTION_SET_PORT_CONFIGURATION, (port, selection_mask, direction, value), 'c B c !', '')
コード例 #2
0
ファイル: bricklet_io16.py プロジェクト: daniz185/brickv
    def set_selected_values(self, port, selection_mask, value_mask):
        """
        Sets the output value (high or low) for a port ("a" or "b" with a bitmask,
        according to the selection mask. The bitmask is 8 bit long and a 1 in the
        bitmask means high and a 0 in the bitmask means low.

        For example: The parameters ('a', 192, 128) or ('a', 0b11000000, 0b10000000)
        will turn pin 7 high and pin 6 low on port A, pins 0-6 will remain untouched.

        Running monoflop timers for the selected pins will be aborted if this
        function is called.

        .. note::
         This function does nothing for pins that are configured as input.
         Pull-up resistors can be switched on with :func:`Set Port Configuration`.
        """
        self.check_validity()

        port = create_char(port)
        selection_mask = int(selection_mask)
        value_mask = int(value_mask)

        self.ipcon.send_request(self,
                                BrickletIO16.FUNCTION_SET_SELECTED_VALUES,
                                (port, selection_mask, value_mask), 'c B B', 0,
                                '')
コード例 #3
0
ファイル: bricklet_io16.py プロジェクト: daniz185/brickv
    def set_port_monoflop(self, port, selection_mask, value_mask, time):
        """
        Configures a monoflop of the pins specified by the second parameter as 8 bit
        long bitmask. The specified pins must be configured for output. Non-output
        pins will be ignored.

        The third parameter is a bitmask with the desired value of the specified
        output pins. A 1 in the bitmask means high and a 0 in the bitmask means low.

        The forth parameter indicates the time that the pins should hold
        the value.

        If this function is called with the parameters ('a', 9, 1, 1500) or
        ('a', 0b00001001, 0b00000001, 1500): Pin 0 will get high and pin 3 will get
        low on port 'a'. In 1.5s pin 0 will get low and pin 3 will get high again.

        A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
        have a RS485 bus and an IO-16 Bricklet connected to one of the slave
        stacks. You can now call this function every second, with a time parameter
        of two seconds and pin 0 set to high. Pin 0 will be high all the time. If now
        the RS485 connection is lost, then pin 0 will get low in at most two seconds.
        """
        self.check_validity()

        port = create_char(port)
        selection_mask = int(selection_mask)
        value_mask = int(value_mask)
        time = int(time)

        self.ipcon.send_request(self, BrickletIO16.FUNCTION_SET_PORT_MONOFLOP,
                                (port, selection_mask, value_mask, time),
                                'c B B I', 0, '')
コード例 #4
0
    def set_voltage_callback_threshold(self, channel, option, min, max):
        """
        Sets the thresholds for the :cb:`Voltage Reached` callback for the given
        channel.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the voltage is *outside* the min and max values"
         "'i'",    "Callback is triggered when the voltage is *inside* the min and max values"
         "'<'",    "Callback is triggered when the voltage is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the voltage is greater than the min value (max is ignored)"
        """
        channel = int(channel)
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self, BrickletIndustrialDualAnalogIn.
            FUNCTION_SET_VOLTAGE_CALLBACK_THRESHOLD,
            (channel, option, min, max), 'B c i i', '')
コード例 #5
0
    def set_configuration(self, channel, direction, value):
        """
        Configures the value and direction of a specific channel. Possible directions
        are 'i' and 'o' for input and output.

        If the direction is configured as output, the value is either high or low
        (set as *true* or *false*).

        If the direction is configured as input, the value is either pull-up or
        default (set as *true* or *false*).

        For example:

        * (0, 'i', true) will set channel-0 as input pull-up.
        * (1, 'i', false) will set channel-1 as input default (floating if nothing is connected).
        * (2, 'o', true) will set channel-2 as output high.
        * (3, 'o', false) will set channel-3 as output low.

        A running monoflop timer for the specific channel will be aborted if this
        function is called.

        The default configuration is input with pull-up.
        """
        channel = int(channel)
        direction = create_char(direction)
        value = bool(value)

        self.ipcon.send_request(self, BrickletIO16V2.FUNCTION_SET_CONFIGURATION, (channel, direction, value), 'B c !', '')
コード例 #6
0
    def set_current_callback_threshold(self, sensor, option, min, max):
        """
        Sets the thresholds for the :cb:`Current Reached` callback for the given
        sensor.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the current is *outside* the min and max values"
         "'i'",    "Callback is triggered when the current is *inside* the min and max values"
         "'<'",    "Callback is triggered when the current is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the current is greater than the min value (max is ignored)"
        """
        self.check_validity()

        sensor = int(sensor)
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self, BrickletIndustrialDual020mA.
            FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD,
            (sensor, option, min, max), 'B c i i', 0, '')
コード例 #7
0
    def set_configuration(self, channel, direction, value):
        """
        Configures the value and direction of a specific channel. Possible directions
        are 'i' and 'o' for input and output.

        If the direction is configured as output, the value is either high or low
        (set as *true* or *false*).

        If the direction is configured as input, the value is either pull-up or
        default (set as *true* or *false*).

        For example:

        * (0, 'i', true) will set channel-0 as input pull-up.
        * (1, 'i', false) will set channel-1 as input default (floating if nothing is connected).
        * (2, 'o', true) will set channel-2 as output high.
        * (3, 'o', false) will set channel-3 as output low.

        The default configuration is input with pull-up.
        """
        channel = int(channel)
        direction = create_char(direction)
        value = bool(value)

        self.ipcon.send_request(self, BrickletIO4V2.FUNCTION_SET_CONFIGURATION,
                                (channel, direction, value), 'B c !', '')
コード例 #8
0
    def set_analog_value_callback_threshold(self, option, min, max):
        """
        Sets the thresholds for the :cb:`Analog Value Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the analog value is *outside* the min and max values"
         "'i'",    "Callback is triggered when the analog value is *inside* the min and max values"
         "'<'",    "Callback is triggered when the analog value is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the analog value is greater than the min value (max is ignored)"
        """
        self.check_validity()

        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self, BrickletVoltage.FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD,
            (option, min, max), 'c H H', 0, '')
コード例 #9
0
    def set_acceleration_callback_threshold(self, option, min_x, max_x, min_y, max_y, min_z, max_z):
        """
        Sets the thresholds for the :cb:`Acceleration Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the acceleration is *outside* the min and max values"
         "'i'",    "Callback is triggered when the acceleration is *inside* the min and max values"
         "'<'",    "Callback is triggered when the acceleration is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the acceleration is greater than the min value (max is ignored)"

        The default value is ('x', 0, 0, 0, 0, 0, 0).
        """
        option = create_char(option)
        min_x = int(min_x)
        max_x = int(max_x)
        min_y = int(min_y)
        max_y = int(max_y)
        min_z = int(min_z)
        max_z = int(max_z)

        self.ipcon.send_request(self, BrickletAccelerometer.FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD, (option, min_x, max_x, min_y, max_y, min_z, max_z), 'c h h h h h h', '')
コード例 #10
0
ファイル: bricklet_color.py プロジェクト: Tinkerforge/brickv
    def set_color_callback_threshold(self, option, min_r, max_r, min_g, max_g, min_b, max_b, min_c, max_c):
        """
        Sets the thresholds for the :cb:`Color Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the temperature is *outside* the min and max values"
         "'i'",    "Callback is triggered when the temperature is *inside* the min and max values"
         "'<'",    "Callback is triggered when the temperature is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the temperature is greater than the min value (max is ignored)"

        The default value is ('x', 0, 0, 0, 0, 0, 0, 0, 0).
        """
        option = create_char(option)
        min_r = int(min_r)
        max_r = int(max_r)
        min_g = int(min_g)
        max_g = int(max_g)
        min_b = int(min_b)
        max_b = int(max_b)
        min_c = int(min_c)
        max_c = int(max_c)

        self.ipcon.send_request(self, BrickletColor.FUNCTION_SET_COLOR_CALLBACK_THRESHOLD, (option, min_r, max_r, min_g, max_g, min_b, max_b, min_c, max_c), 'c H H H H H H H H', '')
コード例 #11
0
ファイル: brick_dc.py プロジェクト: Tinkerforge/brickv
    def set_spitfp_baudrate(self, bricklet_port, baudrate):
        """
        Sets the baudrate for a specific Bricklet port ('a' - 'd'). The
        baudrate can be in the range 400000 to 2000000.

        If you want to increase the throughput of Bricklets you can increase
        the baudrate. If you get a high error count because of high
        interference (see :func:`Get SPITFP Error Count`) you can decrease the
        baudrate.

        If the dynamic baudrate feature is enabled, the baudrate set by this
        function corresponds to the maximum baudrate (see :func:`Set SPITFP Baudrate Config`).

        Regulatory testing is done with the default baudrate. If CE compatibility
        or similar is necessary in you applications we recommend to not change
        the baudrate.

        The default baudrate for all ports is 1400000.

        .. versionadded:: 2.3.3$nbsp;(Firmware)
        """
        bricklet_port = create_char(bricklet_port)
        baudrate = int(baudrate)

        self.ipcon.send_request(self, BrickDC.FUNCTION_SET_SPITFP_BAUDRATE, (bricklet_port, baudrate), 'c I', '')
コード例 #12
0
    def set_velocity_callback_threshold(self, option, min, max):
        """
        Sets the thresholds for the :cb:`Velocity Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the velocity is *outside* the min and max values"
         "'i'",    "Callback is triggered when the velocity is *inside* the min and max values"
         "'<'",    "Callback is triggered when the velocity is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the velocity is greater than the min value (max is ignored)"

        The default value is ('x', 0, 0).
        """
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self,
            BrickletLaserRangeFinder.FUNCTION_SET_VELOCITY_CALLBACK_THRESHOLD,
            (option, min, max), 'c h h', '')
コード例 #13
0
    def set_current_callback_threshold(self, sensor, option, min, max):
        """
        Sets the thresholds for the :cb:`Current Reached` callback for the given
        sensor.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the current is *outside* the min and max values"
         "'i'",    "Callback is triggered when the current is *inside* the min and max values"
         "'<'",    "Callback is triggered when the current is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the current is greater than the min value (max is ignored)"

        The default value is ('x', 0, 0).
        """
        sensor = int(sensor)
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(self, BrickletIndustrialDual020mA.FUNCTION_SET_CURRENT_CALLBACK_THRESHOLD, (sensor, option, min, max), 'B c i i', '')
コード例 #14
0
ファイル: brick_stepper.py プロジェクト: jose1711/brickv
    def set_spitfp_baudrate(self, bricklet_port, baudrate):
        """
        Sets the baudrate for a specific Bricklet port ('a' - 'd'). The
        baudrate can be in the range 400000 to 2000000.

        If you want to increase the throughput of Bricklets you can increase
        the baudrate. If you get a high error count because of high
        interference (see :func:`Get SPITFP Error Count`) you can decrease the
        baudrate.

        If the dynamic baudrate feature is enabled, the baudrate set by this
        function corresponds to the maximum baudrate (see :func:`Set SPITFP Baudrate Config`).

        Regulatory testing is done with the default baudrate. If CE compatibility
        or similar is necessary in you applications we recommend to not change
        the baudrate.

        The default baudrate for all ports is 1400000.

        .. versionadded:: 2.3.3$nbsp;(Firmware)
        """
        bricklet_port = create_char(bricklet_port)
        baudrate = int(baudrate)

        self.ipcon.send_request(self,
                                BrickStepper.FUNCTION_SET_SPITFP_BAUDRATE,
                                (bricklet_port, baudrate), 'c I', '')
コード例 #15
0
    def set_analog_value_callback_threshold(self, option, min_x, max_x, min_y, max_y):
        """
        Sets the thresholds for the :cb:`Analog Value Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the analog values are *outside* the min and max values"
         "'i'",    "Callback is triggered when the analog values are *inside* the min and max values"
         "'<'",    "Callback is triggered when the analog values are smaller than the min values (max is ignored)"
         "'>'",    "Callback is triggered when the analog values are greater than the min values (max is ignored)"

        The default value is ('x', 0, 0, 0, 0).
        """
        option = create_char(option)
        min_x = int(min_x)
        max_x = int(max_x)
        min_y = int(min_y)
        max_y = int(max_y)

        self.ipcon.send_request(self, BrickletJoystick.FUNCTION_SET_ANALOG_VALUE_CALLBACK_THRESHOLD, (option, min_x, max_x, min_y, max_y), 'c H H H H', '')
コード例 #16
0
    def set_temperature_callback_threshold(self, option, min, max):
        """
        Sets the thresholds for the :cb:`Temperature Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the temperature is *outside* the min and max values"
         "'i'",    "Callback is triggered when the temperature is *inside* the min and max values"
         "'<'",    "Callback is triggered when the temperature is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the temperature is greater than the min value (max is ignored)"

        The default value is ('x', 0, 0).
        """
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self,
            BrickletThermocouple.FUNCTION_SET_TEMPERATURE_CALLBACK_THRESHOLD,
            (option, min, max), 'c i i', '')
コード例 #17
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def set_port_monoflop(self, port, selection_mask, value_mask, time):
        """
        Configures a monoflop of the pins specified by the second parameter as 8 bit
        long bitmask. The specified pins must be configured for output. Non-output
        pins will be ignored.

        The third parameter is a bitmask with the desired value of the specified
        output pins. A 1 in the bitmask means high and a 0 in the bitmask means low.

        The forth parameter indicates the time (in ms) that the pins should hold
        the value.

        If this function is called with the parameters ('a', 9, 1, 1500) or
        ('a', 0b00001001, 0b00000001, 1500): Pin 0 will get high and pin 3 will get
        low on port 'a'. In 1.5s pin 0 will get low and pin 3 will get high again.

        A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
        have a RS485 bus and an IO-16 Bricklet connected to one of the slave
        stacks. You can now call this function every second, with a time parameter
        of two seconds and pin 0 set to high. Pin 0 will be high all the time. If now
        the RS485 connection is lost, then pin 0 will get low in at most two seconds.
        """
        port = create_char(port)
        selection_mask = int(selection_mask)
        value_mask = int(value_mask)
        time = int(time)

        self.ipcon.send_request(self, BrickletIO16.FUNCTION_SET_PORT_MONOFLOP, (port, selection_mask, value_mask, time), 'c B B I', '')
コード例 #18
0
    def set_acceleration_callback_threshold(self, option, min_x, max_x, min_y, max_y, min_z, max_z):
        """
        Sets the thresholds for the :cb:`Acceleration Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the acceleration is *outside* the min and max values"
         "'i'",    "Callback is triggered when the acceleration is *inside* the min and max values"
         "'<'",    "Callback is triggered when the acceleration is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the acceleration is greater than the min value (max is ignored)"
        """
        self.check_validity()

        option = create_char(option)
        min_x = int(min_x)
        max_x = int(max_x)
        min_y = int(min_y)
        max_y = int(max_y)
        min_z = int(min_z)
        max_z = int(max_z)

        self.ipcon.send_request(self, BrickletAccelerometer.FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD, (option, min_x, max_x, min_y, max_y, min_z, max_z), 'c h h h h h h', 0, '')
コード例 #19
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def get_port_interrupt(self, port):
        """
        Returns the interrupt bitmask for the specified port as set by
        :func:`Set Port Interrupt`.
        """
        port = create_char(port)

        return self.ipcon.send_request(self, BrickletIO16.FUNCTION_GET_PORT_INTERRUPT, (port,), 'c', 'B')
コード例 #20
0
    def get_port_interrupt(self, port):
        """
        Returns the interrupt bitmask for the specified port as set by
        :func:`Set Port Interrupt`.
        """
        port = create_char(port)

        return self.ipcon.send_request(self, BrickletIO16.FUNCTION_GET_PORT_INTERRUPT, (port,), 'c', 'B')
コード例 #21
0
ファイル: brick_dc.py プロジェクト: Tinkerforge/brickv
    def get_spitfp_baudrate(self, bricklet_port):
        """
        Returns the baudrate for a given Bricklet port, see :func:`Set SPITFP Baudrate`.

        .. versionadded:: 2.3.3$nbsp;(Firmware)
        """
        bricklet_port = create_char(bricklet_port)

        return self.ipcon.send_request(self, BrickDC.FUNCTION_GET_SPITFP_BAUDRATE, (bricklet_port,), 'c', 'I')
コード例 #22
0
    def get_port(self, port):
        """
        Returns a bitmask of the values that are currently measured on the
        specified port. This function works if the pin is configured to input
        as well as if it is configured to output.
        """
        port = create_char(port)

        return self.ipcon.send_request(self, BrickletIO16.FUNCTION_GET_PORT, (port,), 'c', 'B')
コード例 #23
0
ファイル: brick_dc.py プロジェクト: bmwiedemann/brickv
    def get_spitfp_baudrate(self, bricklet_port):
        """
        Returns the baudrate for a given Bricklet port, see :func:`Set SPITFP Baudrate`.

        .. versionadded:: 2.3.3$nbsp;(Firmware)
        """
        bricklet_port = create_char(bricklet_port)

        return self.ipcon.send_request(self, BrickDC.FUNCTION_GET_SPITFP_BAUDRATE, (bricklet_port,), 'c', 'I')
コード例 #24
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def get_port(self, port):
        """
        Returns a bitmask of the values that are currently measured on the
        specified port. This function works if the pin is configured to input
        as well as if it is configured to output.
        """
        port = create_char(port)

        return self.ipcon.send_request(self, BrickletIO16.FUNCTION_GET_PORT, (port,), 'c', 'B')
コード例 #25
0
ファイル: brick_dc.py プロジェクト: Tinkerforge/brickv
    def get_protocol1_bricklet_name(self, port):
        """
        Returns the firmware and protocol version and the name of the Bricklet for a
        given port.

        This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet
        plugins.
        """
        port = create_char(port)

        return GetProtocol1BrickletName(*self.ipcon.send_request(self, BrickDC.FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, (port,), 'c', 'B 3B 40s'))
コード例 #26
0
ファイル: brick_dc.py プロジェクト: bmwiedemann/brickv
    def get_protocol1_bricklet_name(self, port):
        """
        Returns the firmware and protocol version and the name of the Bricklet for a
        given port.

        This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet
        plugins.
        """
        port = create_char(port)

        return GetProtocol1BrickletName(*self.ipcon.send_request(self, BrickDC.FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, (port,), 'c', 'B 3B 40s'))
コード例 #27
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def get_port_monoflop(self, port, pin):
        """
        Returns (for the given pin) the current value and the time as set by
        :func:`Set Port Monoflop` as well as the remaining time until the value flips.

        If the timer is not running currently, the remaining time will be returned
        as 0.
        """
        port = create_char(port)
        pin = int(pin)

        return GetPortMonoflop(*self.ipcon.send_request(self, BrickletIO16.FUNCTION_GET_PORT_MONOFLOP, (port, pin), 'c B', 'B I I'))
コード例 #28
0
    def get_port_monoflop(self, port, pin):
        """
        Returns (for the given pin) the current value and the time as set by
        :func:`Set Port Monoflop` as well as the remaining time until the value flips.

        If the timer is not running currently, the remaining time will be returned
        as 0.
        """
        port = create_char(port)
        pin = int(pin)

        return GetPortMonoflop(*self.ipcon.send_request(self, BrickletIO16.FUNCTION_GET_PORT_MONOFLOP, (port, pin), 'c B', 'B I I'))
コード例 #29
0
ファイル: brick_imu_v2.py プロジェクト: fk0815/brickv
    def read_bricklet_plugin(self, port, offset):
        """
        Reads 32 bytes of firmware from the bricklet attached at the given port.
        The bytes are read starting at the position offset * 32.

        This function is used by Brick Viewer during flashing. It should not be
        necessary to call it in a normal user program.
        """
        self.check_validity()

        port = create_char(port)
        offset = int(offset)

        return self.ipcon.send_request(self, BrickIMUV2.FUNCTION_READ_BRICKLET_PLUGIN, (port, offset), 'c B', 40, '32B')
コード例 #30
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def set_port_interrupt(self, port, interrupt_mask):
        """
        Sets the pins on which an interrupt is activated with a bitmask.
        Interrupts are triggered on changes of the voltage level of the pin,
        i.e. changes from high to low and low to high.

        For example: ('a', 129) or ('a', 0b10000001) will enable the interrupt for
        pins 0 and 7 of port a.

        The interrupt is delivered with the :cb:`Interrupt` callback.
        """
        port = create_char(port)
        interrupt_mask = int(interrupt_mask)

        self.ipcon.send_request(self, BrickletIO16.FUNCTION_SET_PORT_INTERRUPT, (port, interrupt_mask), 'c B', '')
コード例 #31
0
    def switch_socket_c(self, system_code, device_code, switch_to):
        """
        To switch a type C socket you have to give the system code, device code and the
        state (on or off) you want to switch to.

        A detailed description on how you can figure out the system and device code
        can be found :ref:`here <remote_switch_bricklet_type_c_system_and_device_code>`.
        """
        system_code = create_char(system_code)
        device_code = int(device_code)
        switch_to = int(switch_to)

        self.ipcon.send_request(
            self, BrickletRemoteSwitchV2.FUNCTION_SWITCH_SOCKET_C,
            (system_code, device_code, switch_to), 'c B B', '')
コード例 #32
0
ファイル: brick_imu_v2.py プロジェクト: fk0815/brickv
    def write_bricklet_plugin(self, port, offset, chunk):
        """
        Writes 32 bytes of firmware to the bricklet attached at the given port.
        The bytes are written to the position offset * 32.

        This function is used by Brick Viewer during flashing. It should not be
        necessary to call it in a normal user program.
        """
        self.check_validity()

        port = create_char(port)
        offset = int(offset)
        chunk = list(map(int, chunk))

        self.ipcon.send_request(self, BrickIMUV2.FUNCTION_WRITE_BRICKLET_PLUGIN, (port, offset, chunk), 'c B 32B', 0, '')
コード例 #33
0
    def set_port_interrupt(self, port, interrupt_mask):
        """
        Sets the pins on which an interrupt is activated with a bitmask.
        Interrupts are triggered on changes of the voltage level of the pin,
        i.e. changes from high to low and low to high.

        For example: ('a', 129) or ('a', 0b10000001) will enable the interrupt for
        pins 0 and 7 of port a.

        The interrupt is delivered with the :cb:`Interrupt` callback.
        """
        port = create_char(port)
        interrupt_mask = int(interrupt_mask)

        self.ipcon.send_request(self, BrickletIO16.FUNCTION_SET_PORT_INTERRUPT, (port, interrupt_mask), 'c B', '')
コード例 #34
0
    def get_port_configuration(self, port):
        """
        Returns a direction bitmask and a value bitmask for the specified port. A 1 in
        the direction bitmask means input and a 0 in the bitmask means output.

        For example: A return value of (15, 51) or (0b00001111, 0b00110011) for
        direction and value means that:

        * pins 0 and 1 are configured as input pull-up,
        * pins 2 and 3 are configured as input default,
        * pins 4 and 5 are configured as output high
        * and pins 6 and 7 are configured as output low.
        """
        port = create_char(port)

        return GetPortConfiguration(*self.ipcon.send_request(self, BrickletIO16.FUNCTION_GET_PORT_CONFIGURATION, (port,), 'c', 'B B'))
コード例 #35
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def get_port_configuration(self, port):
        """
        Returns a direction bitmask and a value bitmask for the specified port. A 1 in
        the direction bitmask means input and a 0 in the bitmask means output.

        For example: A return value of (15, 51) or (0b00001111, 0b00110011) for
        direction and value means that:

        * pins 0 and 1 are configured as input pull-up,
        * pins 2 and 3 are configured as input default,
        * pins 4 and 5 are configured as output high
        * and pins 6 and 7 are configured as output low.
        """
        port = create_char(port)

        return GetPortConfiguration(*self.ipcon.send_request(self, BrickletIO16.FUNCTION_GET_PORT_CONFIGURATION, (port,), 'c', 'B B'))
コード例 #36
0
    def set_port(self, port, value_mask):
        """
        Sets the output value (high or low) for a port ("a" or "b") with a bitmask
        (8bit). A 1 in the bitmask means high and a 0 in the bitmask means low.

        For example: The value 15 or 0b00001111 will turn the pins 0-3 high and the
        pins 4-7 low for the specified port.

        .. note::
         This function does nothing for pins that are configured as input.
         Pull-up resistors can be switched on with :func:`Set Port Configuration`.
        """
        port = create_char(port)
        value_mask = int(value_mask)

        self.ipcon.send_request(self, BrickletIO16.FUNCTION_SET_PORT, (port, value_mask), 'c B', '')
コード例 #37
0
    def set_current_callback_configuration(self, channel, period,
                                           value_has_to_change, option, min,
                                           max):
        """
        The period in ms is the period with which the :cb:`Current` callback is triggered
        periodically. A value of 0 turns the callback off.

        If the `value has to change`-parameter is set to true, the callback is only
        triggered after the value has changed. If the value didn't change
        within the period, the callback is triggered immediately on change.

        If it is set to false, the callback is continuously triggered with the period,
        independent of the value.

        It is furthermore possible to constrain the callback with thresholds.

        The `option`-parameter together with min/max sets a threshold for the :cb:`Current` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Threshold is turned off"
         "'o'",    "Threshold is triggered when the value is *outside* the min and max values"
         "'i'",    "Threshold is triggered when the value is *inside* or equal to the min and max values"
         "'<'",    "Threshold is triggered when the value is smaller than the min value (max is ignored)"
         "'>'",    "Threshold is triggered when the value is greater than the min value (max is ignored)"

        If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.

        The default value is (0, false, 'x', 0, 0).
        """
        channel = int(channel)
        period = int(period)
        value_has_to_change = bool(value_has_to_change)
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self, BrickletIndustrialDual020mAV2.
            FUNCTION_SET_CURRENT_CALLBACK_CONFIGURATION,
            (channel, period, value_has_to_change, option, min, max),
            'B I ! c i i', '')
コード例 #38
0
ファイル: brick_hat_zero.py プロジェクト: fk0815/brickv
    def set_usb_voltage_callback_configuration(self, period,
                                               value_has_to_change, option,
                                               min, max):
        """
        The period is the period with which the :cb:`USB Voltage` callback is triggered
        periodically. A value of 0 turns the callback off.

        If the `value has to change`-parameter is set to true, the callback is only
        triggered after the value has changed. If the value didn't change
        within the period, the callback is triggered immediately on change.

        If it is set to false, the callback is continuously triggered with the period,
        independent of the value.

        It is furthermore possible to constrain the callback with thresholds.

        The `option`-parameter together with min/max sets a threshold for the :cb:`USB Voltage` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Threshold is turned off"
         "'o'",    "Threshold is triggered when the value is *outside* the min and max values"
         "'i'",    "Threshold is triggered when the value is *inside* or equal to the min and max values"
         "'<'",    "Threshold is triggered when the value is smaller than the min value (max is ignored)"
         "'>'",    "Threshold is triggered when the value is greater than the min value (max is ignored)"

        If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.

        .. versionadded:: 2.0.1$nbsp;(Firmware)
        """
        self.check_validity()

        period = int(period)
        value_has_to_change = bool(value_has_to_change)
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self, BrickHATZero.FUNCTION_SET_USB_VOLTAGE_CALLBACK_CONFIGURATION,
            (period, value_has_to_change, option, min, max), 'I ! c H H', 0,
            '')
コード例 #39
0
    def switch_socket_c(self, system_code, device_code, switch_to):
        """
        To switch a type C socket you have to give the system code, device code and the
        state (on or off) you want to switch to.

        The system code has a range of 'A' to 'P' (4bit) and the device code has a
        range of 1 to 16 (4bit).

        A detailed description on how you can figure out the system and device code
        can be found :ref:`here <remote_switch_bricklet_type_c_system_and_device_code>`.

        .. versionadded:: 2.0.1$nbsp;(Plugin)
        """
        system_code = create_char(system_code)
        device_code = int(device_code)
        switch_to = int(switch_to)

        self.ipcon.send_request(self, BrickletRemoteSwitch.FUNCTION_SWITCH_SOCKET_C, (system_code, device_code, switch_to), 'c B B', '')
コード例 #40
0
ファイル: brick_dc.py プロジェクト: Tinkerforge/brickv
    def get_spitfp_error_count(self, bricklet_port):
        """
        Returns the error count for the communication between Brick and Bricklet.

        The errors are divided into

        * ACK checksum errors,
        * message checksum errors,
        * framing errors and
        * overflow errors.

        The errors counts are for errors that occur on the Brick side. All
        Bricklets have a similar function that returns the errors on the Bricklet side.

        .. versionadded:: 2.3.3$nbsp;(Firmware)
        """
        bricklet_port = create_char(bricklet_port)

        return GetSPITFPErrorCount(*self.ipcon.send_request(self, BrickDC.FUNCTION_GET_SPITFP_ERROR_COUNT, (bricklet_port,), 'c', 'I I I I'))
コード例 #41
0
ファイル: brick_dc.py プロジェクト: bmwiedemann/brickv
    def get_spitfp_error_count(self, bricklet_port):
        """
        Returns the error count for the communication between Brick and Bricklet.

        The errors are divided into

        * ACK checksum errors,
        * message checksum errors,
        * framing errors and
        * overflow errors.

        The errors counts are for errors that occur on the Brick side. All
        Bricklets have a similar function that returns the errors on the Bricklet side.

        .. versionadded:: 2.3.3$nbsp;(Firmware)
        """
        bricklet_port = create_char(bricklet_port)

        return GetSPITFPErrorCount(*self.ipcon.send_request(self, BrickDC.FUNCTION_GET_SPITFP_ERROR_COUNT, (bricklet_port,), 'c', 'I I I I'))
コード例 #42
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def set_port(self, port, value_mask):
        """
        Sets the output value (high or low) for a port ("a" or "b") with a bitmask
        (8bit). A 1 in the bitmask means high and a 0 in the bitmask means low.

        For example: The value 15 or 0b00001111 will turn the pins 0-3 high and the
        pins 4-7 low for the specified port.

        All running monoflop timers of the given port will be aborted if this function
        is called.

        .. note::
         This function does nothing for pins that are configured as input.
         Pull-up resistors can be switched on with :func:`Set Port Configuration`.
        """
        port = create_char(port)
        value_mask = int(value_mask)

        self.ipcon.send_request(self, BrickletIO16.FUNCTION_SET_PORT, (port, value_mask), 'c B', '')
コード例 #43
0
    def set_magnetic_flux_density_callback_configuration(
            self, period, value_has_to_change, option, min, max):
        """
        The period is the period with which the :cb:`Magnetic Flux Density` callback is triggered
        periodically. A value of 0 turns the callback off.

        If the `value has to change`-parameter is set to true, the callback is only
        triggered after the value has changed. If the value didn't change
        within the period, the callback is triggered immediately on change.

        If it is set to false, the callback is continuously triggered with the period,
        independent of the value.

        It is furthermore possible to constrain the callback with thresholds.

        The `option`-parameter together with min/max sets a threshold for the :cb:`Magnetic Flux Density` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Threshold is turned off"
         "'o'",    "Threshold is triggered when the value is *outside* the min and max values"
         "'i'",    "Threshold is triggered when the value is *inside* or equal to the min and max values"
         "'<'",    "Threshold is triggered when the value is smaller than the min value (max is ignored)"
         "'>'",    "Threshold is triggered when the value is greater than the min value (max is ignored)"

        If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
        """
        period = int(period)
        value_has_to_change = bool(value_has_to_change)
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self, BrickletHallEffectV2.
            FUNCTION_SET_MAGNETIC_FLUX_DENSITY_CALLBACK_CONFIGURATION,
            (period, value_has_to_change, option, min, max), 'I ! c h h', '')
コード例 #44
0
    def switch_socket_c(self, system_code, device_code, switch_to):
        """
        To switch a type C socket you have to give the system code, device code and the
        state (on or off) you want to switch to.

        The system code has a range of 'A' to 'P' (4bit) and the device code has a
        range of 1 to 16 (4bit).

        A detailed description on how you can figure out the system and device code
        can be found :ref:`here <remote_switch_bricklet_type_c_system_and_device_code>`.

        .. versionadded:: 2.0.1$nbsp;(Plugin)
        """
        system_code = create_char(system_code)
        device_code = int(device_code)
        switch_to = int(switch_to)

        self.ipcon.send_request(self,
                                BrickletRemoteSwitch.FUNCTION_SWITCH_SOCKET_C,
                                (system_code, device_code, switch_to), 'c B B',
                                '')
コード例 #45
0
ファイル: bricklet_io16.py プロジェクト: Tinkerforge/brickv
    def set_selected_values(self, port, selection_mask, value_mask):
        """
        Sets the output value (high or low) for a port ("a" or "b" with a bitmask,
        according to the selection mask. The bitmask is 8 bit long and a 1 in the
        bitmask means high and a 0 in the bitmask means low.

        For example: The parameters ('a', 192, 128) or ('a', 0b11000000, 0b10000000)
        will turn pin 7 high and pin 6 low on port A, pins 0-6 will remain untouched.

        Running monoflop timers for the selected pins will be aborted if this
        function is called.

        .. note::
         This function does nothing for pins that are configured as input.
         Pull-up resistors can be switched on with :func:`Set Port Configuration`.
        """
        port = create_char(port)
        selection_mask = int(selection_mask)
        value_mask = int(value_mask)

        self.ipcon.send_request(self, BrickletIO16.FUNCTION_SET_SELECTED_VALUES, (port, selection_mask, value_mask), 'c B B', '')
コード例 #46
0
    def set_position_callback_threshold(self, option, min, max):
        """
        Sets the thresholds for the :cb:`Position Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the position is *outside* the min and max values"
         "'i'",    "Callback is triggered when the position is *inside* the min and max values"
         "'<'",    "Callback is triggered when the position is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the position is greater than the min value (max is ignored)"
        """
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(self, BrickletRotaryPoti.FUNCTION_SET_POSITION_CALLBACK_THRESHOLD, (option, min, max), 'c h h', '')
コード例 #47
0
    def set_current_callback_configuration(self, channel, period, value_has_to_change, option, min, max):
        """
        The period in ms is the period with which the :cb:`Current` callback is triggered
        periodically. A value of 0 turns the callback off.

        If the `value has to change`-parameter is set to true, the callback is only
        triggered after the value has changed. If the value didn't change
        within the period, the callback is triggered immediately on change.

        If it is set to false, the callback is continuously triggered with the period,
        independent of the value.

        It is furthermore possible to constrain the callback with thresholds.

        The `option`-parameter together with min/max sets a threshold for the :cb:`Current` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Threshold is turned off"
         "'o'",    "Threshold is triggered when the value is *outside* the min and max values"
         "'i'",    "Threshold is triggered when the value is *inside* or equal to the min and max values"
         "'<'",    "Threshold is triggered when the value is smaller than the min value (max is ignored)"
         "'>'",    "Threshold is triggered when the value is greater than the min value (max is ignored)"

        If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.

        The default value is (0, false, 'x', 0, 0).
        """
        channel = int(channel)
        period = int(period)
        value_has_to_change = bool(value_has_to_change)
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(self, BrickletIndustrialDual020mAV2.FUNCTION_SET_CURRENT_CALLBACK_CONFIGURATION, (channel, period, value_has_to_change, option, min, max), 'B I ! c i i', '')
コード例 #48
0
    def set_position_callback_threshold(self, option, min, max):
        """
        Sets the thresholds for the :cb:`Position Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the position is *outside* the min and max values"
         "'i'",    "Callback is triggered when the position is *inside* the min and max values"
         "'<'",    "Callback is triggered when the position is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the position is greater than the min value (max is ignored)"

        The default value is ('x', 0, 0).
        """
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(self, BrickletRotaryPoti.FUNCTION_SET_POSITION_CALLBACK_THRESHOLD, (option, min, max), 'c h h', '')
コード例 #49
0
    def set_air_pressure_callback_threshold(self, option, min, max):
        """
        Sets the thresholds for the :cb:`Air Pressure Reached` callback.

        The following options are possible:

        .. csv-table::
         :header: "Option", "Description"
         :widths: 10, 100

         "'x'",    "Callback is turned off"
         "'o'",    "Callback is triggered when the air pressure is *outside* the min and max values"
         "'i'",    "Callback is triggered when the air pressure is *inside* the min and max values"
         "'<'",    "Callback is triggered when the air pressure is smaller than the min value (max is ignored)"
         "'>'",    "Callback is triggered when the air pressure is greater than the min value (max is ignored)"
        """
        option = create_char(option)
        min = int(min)
        max = int(max)

        self.ipcon.send_request(
            self,
            BrickletBarometer.FUNCTION_SET_AIR_PRESSURE_CALLBACK_THRESHOLD,
            (option, min, max), 'c i i', '')
コード例 #50
0
import sys
from ip_connection import create_char, create_char_list, create_string, pack_payload, unpack_payload


def b(value):
    if sys.hexversion < 0x03000000:
        return value
    else:
        return bytes(map(ord, value))


#
# char
#

assert (create_char('a') == 'a')  # str

if sys.hexversion < 0x03000000:
    assert (create_char(u'a') == 'a')  # unicode
else:
    assert (create_char(b'a') == 'a')  # bytes

assert (create_char(bytearray([97])) == 'a')  # bytearray
assert (create_char(97) == 'a')  # int

for c in range(256):
    k = (c + 1) % 256

    assert (create_char(chr(c)) == chr(c))  # str
    assert (create_char(chr(c)) != chr(k))  # str
コード例 #51
0
# -*- coding: utf-8 -*-

import sys
from ip_connection import create_char, create_char_list, create_string, pack_payload, unpack_payload

def b(value):
    if sys.hexversion < 0x03000000:
        return value
    else:
        return bytes(map(ord, value))

#
# char
#

assert(create_char('a') == 'a') # str

if sys.hexversion < 0x03000000:
    assert(create_char(u'a') == 'a') # unicode
else:
    assert(create_char(b'a') == 'a') # bytes

assert(create_char(bytearray([97])) == 'a') # bytearray
assert(create_char(97) == 'a') # int

for c in range(256):
    k = (c + 1) % 256

    assert(create_char(chr(c)) == chr(c)) # str
    assert(create_char(chr(c)) != chr(k)) # str