コード例 #1
0
    def cb_enumerate(self, uid, connected_uid, position, hardware_version,
                     firmware_version, device_identifier, enumeration_type):

        if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
           enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:

            # Enumeration for V/C
            if device_identifier == BrickletVoltageCurrent.DEVICE_IDENTIFIER:
                self.vc = BrickletVoltageCurrent(uid, self.ipcon)
                self.cb_reached_vc()
コード例 #2
0
class PowerConsumption:
    def __init__(self, ipcon: IPConnection, UID):
        self.voltageCurrent = BrickletVoltageCurrent(UID, ipcon)
        self.voltageCurrent.set_configuration(7, 7, 7)

    def getVoltage(self):
        return self.voltageCurrent.get_voltage()

    def getCurrent(self):
        return self.voltageCurrent.get_current()

    def getPower(self):
        return self.voltageCurrent.get_voltage(
        ) * self.voltageCurrent.get_current()
コード例 #3
0
ファイル: tf_sensors.py プロジェクト: cutec-chris/halc
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
コード例 #4
0
ファイル: controller.py プロジェクト: lspgl/daVinci
 def connect(self):
     self.ipcon.connect(self.HOST, self.PORT)
     self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE,
                                  self.callback)
     self.connected = False
     self.ipcon.enumerate()
     time.sleep(.1)
     if self.connected:
         self.io = BrickletIO16(self.IO16_ID, self.ipcon)
         self.vc = BrickletVoltageCurrent(self.VC_ID, self.ipcon)
         self.rs1 = BrickletRS485(self.RS485_1_ID, self.ipcon)
         self.rs2 = BrickletRS485(self.RS485_2_ID, self.ipcon)
         self.rs485 = [self.rs1, self.rs2]
         self.callbackFn = [self.cb_read_1, self.cb_read_2]
         for i, rs in enumerate(self.rs485):
             rs.set_rs485_configuration(1250000, rs.PARITY_NONE,
                                        rs.STOPBITS_1, rs.WORDLENGTH_8,
                                        rs.DUPLEX_HALF)
             rs.register_callback(rs.CALLBACK_READ, self.callbackFn[i])
             rs.enable_read_callback()
         return True
     else:
         self.ipcon.disconnect()
         return False
コード例 #5
0
# -*- 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()
コード例 #6
0
#!/usr/bin/env python
# -*- 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

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 current voltage
    voltage = vc.get_voltage()
    print("Voltage: " + str(voltage/1000.0) + " V")

    # Get current current
    current = vc.get_current()
    print("Current: " + str(current/1000.0) + " A")

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
コード例 #7
0
# -*- 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 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()
コード例 #8
0
#!/usr/bin/env python
# -*- 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

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 current voltage (unit is mV)
    voltage = vc.get_voltage()
    print("Voltage: " + str(voltage / 1000.0) + " V")

    # Get current current (unit is mA)
    current = vc.get_current()
    print("Current: " + str(current / 1000.0) + " A")

    raw_input("Press key to exit\n")  # Use input() in Python 3
    ipcon.disconnect()
コード例 #9
0
 def __init__(self, ipcon: IPConnection, UID):
     self.voltageCurrent = BrickletVoltageCurrent(UID, ipcon)
     self.voltageCurrent.set_configuration(7, 7, 7)
コード例 #10
0
ファイル: SensorConnector.py プロジェクト: Aragnos/tf_test
 def create_instance(self, uid, ipcon):
     return BrickletVoltageCurrent(uid, ipcon)
コード例 #11
0
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()