HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Voltage/Current Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_voltage_current import BrickletVoltageCurrent # Callback function for power reached callback (parameter has unit mW) def cb_power_reached(power): print("Power: " + str(power/1000.0) + " W") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection vc = BrickletVoltageCurrent(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) vc.set_debounce_period(10000) # Register power reached callback to function cb_power_reached vc.register_callback(vc.CALLBACK_POWER_REACHED, cb_power_reached) # Configure threshold for power "greater than 10 W" (unit is mW) vc.set_power_callback_threshold(">", 10*1000, 0) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
# -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Voltage/Current Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_voltage_current import BrickletVoltageCurrent # Callback function for current callback def cb_current(current): print("Current: " + str(current/1000.0) + " A") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection vc = BrickletVoltageCurrent(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Register current callback to function cb_current vc.register_callback(vc.CALLBACK_CURRENT, cb_current) # Set period for current callback to 1s (1000ms) # Note: The current callback is only called every second # if the current has changed since the last call! vc.set_current_callback_period(1000) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Voltage/Current Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_voltage_current import BrickletVoltageCurrent # Callback function for current callback (parameter has unit mA) def cb_current(current): print("Current: " + str(current / 1000.0) + " A") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection vc = BrickletVoltageCurrent(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Register current callback to function cb_current vc.register_callback(vc.CALLBACK_CURRENT, cb_current) # Set period for current callback to 1s (1000ms) # Note: The current callback is only called every second # if the current has changed since the last call! vc.set_current_callback_period(1000) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()