Esempio n. 1
0
def findDeviceType(id, devicetype):
    global ipcon
    tmp = hal.Devices.find(id)
    if tmp != None:
        return tmp.Device
    else:
        if devicetype == 13: return BrickMaster(id, ipcon)
        elif devicetype == 14: return BrickServo(id, ipcon)
        elif devicetype == 227: return BrickletVoltageCurrent(id, ipcon)
        elif devicetype == 2105: return BrickletVoltageCurrentV2(id, ipcon)
        elif devicetype == 100: return BrickletIO16(id, ipcon)
        elif devicetype == 243: return BrickletColor(id, ipcon)
        elif devicetype == 2128: return BrickletColorV2(id, ipcon)
        elif devicetype == 26: return BrickletDualRelay(id, ipcon)
        elif devicetype == 284: return BrickletIndustrialDualRelay(id, ipcon)
        elif devicetype == 225: return BrickletIndustrialQuadRelay(id, ipcon)
        elif devicetype == 2102:
            return BrickletIndustrialQuadRelayV2(id, ipcon)
        else:
            print("Warning: DeviceType " + str(devicetype) + " not found")
            return None
Esempio n. 2
0
from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_color import BrickletColor


# Callback function for color reached callback
def cb_color_reached(r, g, b, c):
    print("Color[R]: " + str(r))
    print("Color[G]: " + str(g))
    print("Color[B]: " + str(b))
    print("Color[C]: " + str(c))
    print("")


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    c = BrickletColor(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Get threshold callbacks with a debounce time of 10 seconds (10000ms)
    c.set_debounce_period(10000)

    # Register color reached callback to function cb_color_reached
    c.register_callback(c.CALLBACK_COLOR_REACHED, cb_color_reached)

    # Configure threshold for color "greater than 100, 200, 300, 400"
    c.set_color_callback_threshold(">", 100, 0, 200, 0, 300, 0, 400, 0)

    raw_input("Press key to exit\n")  # Use input() in Python 3
    ipcon.disconnect()
Esempio n. 3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Color Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_color import BrickletColor

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    c = BrickletColor(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get current color
    r, g, b, c_ = c.get_color()

    print("Color[R]: " + str(r))
    print("Color[G]: " + str(g))
    print("Color[B]: " + str(b))
    print("Color[C]: " + str(c_))

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
Esempio n. 4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your Color Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_color import BrickletColor

if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    c = BrickletColor(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Get current color
    r, g, b, c_ = c.get_color()

    print("Color[R]: " + str(r))
    print("Color[G]: " + str(g))
    print("Color[B]: " + str(b))
    print("Color[C]: " + str(c_))

    raw_input("Press key to exit\n")  # Use input() in Python 3
    ipcon.disconnect()
UID = "XYZ" # Change XYZ to the UID of your Color Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_color import BrickletColor

# Callback function for color reached callback
def cb_color_reached(r, g, b, c):
    print("Color [R]: " + str(r))
    print("Color [G]: " + str(g))
    print("Color [B]: " + str(b))
    print("Color [C]: " + str(c))
    print("")

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    c = BrickletColor(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get threshold callbacks with a debounce time of 10 seconds (10000ms)
    c.set_debounce_period(10000)

    # Register color reached callback to function cb_color_reached
    c.register_callback(c.CALLBACK_COLOR_REACHED, cb_color_reached)

    # Configure threshold for color "greater than 100, 200, 300, 400"
    c.set_color_callback_threshold(">", 100, 0, 200, 0, 300, 0, 400, 0)

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
Esempio n. 6
0
UID = "XYZ" # Change XYZ to the UID of your Color Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_color import BrickletColor

# Callback function for color callback
def cb_color(r, g, b, c):
    print("Color[R]: " + str(r))
    print("Color[G]: " + str(g))
    print("Color[B]: " + str(b))
    print("Color[C]: " + str(c))
    print("")

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    c = BrickletColor(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Register color callback to function cb_color
    c.register_callback(c.CALLBACK_COLOR, cb_color)

    # Set period for color callback to 1s (1000ms)
    # Note: The color callback is only called every second
    #       if the color has changed since the last call!
    c.set_color_callback_period(1000)

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
Esempio n. 7
0
 def create_instance(self, uid, ipcon):
     return BrickletColor(uid, ipcon)