Example #1
0
class BrickletQuadRelay:
    def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue):
        self._bricklet = BrickletIndustrialQuadRelay(uid, connection)
        self.uid = uid
        self.switch_id = switch_id
        self.ip = ip
        self._logging_daemon = logging_daemon
        self._queue = queue
        self._logging_daemon.info(
            'Tinkerforge ... DualRelay-Bricklet "%s" initialisiert' % uid)

    def status(self, number):
        return ((self._bricklet.get_value() & (1 << int(number))) != 0)

    def set_switch(self, switch_to, arg_a, arg_b, arg_c, arg_d):
        _now = self._bricklet.get_value()
        _change = 1 << int(arg_b)
        self._bricklet.set_value(_now ^ _change)
        self._logging_daemon.debug(
            'Tinkerforge ... QuadRelay-Bricklet UID "%s" , geschaltet Relais %s , SOLL = %s , IST = %s'
            % (self.uid, arg_b, switch_to, self.status(arg_b)))
        tmp_json = json.dumps({
            "usage": "switch_changed_status",
            "ip": self.ip,
            "id": self.switch_id,
            "value": switch_to
        })
        for consumer in self._queue:
            consumer(tmp_json)
            self._logging_daemon.info(
                'Tinkerforge ... QuadRelay-Bricklet UID "%s" Relais %s , send %s -> SocketServer Warteschlange '
                % (self.uid, arg_b, self.status(arg_b)))
def setPins(mcuReset, pcuReset, mcuBoot, pcuBoot):
    ipcon = IPConnection()  # Create IP connection
    relay = BrickletIndustrialQuadRelay(UID_RELAY,
                                        ipcon)  # Create device object

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

    relayValue = 0

    if mcuReset:
        relayValue |= (1 << 0)

    if mcuBoot:
        relayValue |= (1 << 1)

    if pcuReset:
        relayValue |= (1 << 2)

    if pcuBoot:
        relayValue |= (1 << 3)

    relay.set_value(relayValue)

    ipcon.disconnect()
Example #3
0
class BrickletQuadRelay:
    def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue):
        self._bricklet = BrickletIndustrialQuadRelay(uid, connection)
        self.uid = uid
        self.switch_id = switch_id
        self.ip = ip
        self._logging_daemon = logging_daemon
        self._queue = queue
        self._logging_daemon.info('Tinkerforge ... DualRelay-Bricklet "%s" initialisiert' % uid)

    def status(self, number):
        return ((self._bricklet.get_value() & (1 << int(number))) != 0)

    def set_switch(self, switch_to, arg_a, arg_b, arg_c, arg_d):
        _now = self._bricklet.get_value()
        _change = 1 << int(arg_b)
        self._bricklet.set_value(_now ^ _change)
        self._logging_daemon.debug(
            'Tinkerforge ... QuadRelay-Bricklet UID "%s" , geschaltet Relais %s , SOLL = %s , IST = %s' % (
                self.uid, arg_b, switch_to, self.status(arg_b)))
        tmp_json = json.dumps({
            "usage": "switch_changed_status",
            "ip": self.ip,
            "id": self.switch_id,
            "value": switch_to
        })
        for consumer in self._queue:
            consumer(tmp_json)
            self._logging_daemon.info(
                'Tinkerforge ... QuadRelay-Bricklet UID "%s" Relais %s , send %s -> SocketServer Warteschlange ' % (
                    self.uid, arg_b, self.status(arg_b)))
Example #4
0
 def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue):
     self._bricklet = BrickletIndustrialQuadRelay(uid, connection)
     self.uid = uid
     self.switch_id = switch_id
     self.ip = ip
     self._logging_daemon = logging_daemon
     self._queue = queue
     self._logging_daemon.info(
         'Tinkerforge ... DualRelay-Bricklet "%s" initialisiert' % uid)
Example #5
0
def relay_flash(baudrate, tty, firmware, uid_iqr, uid_master):
    ipcon = IPConnection()
    iqr = BrickletIndustrialQuadRelay(uid_iqr, ipcon)
    master = BrickMaster(uid_master, ipcon)

    ipcon.connect('localhost', 4223)

    #    reset_usb()
    #    time.sleep(1)

    i = 10
    while True:
        if i == 10:
            master.get_chibi_error_log()
            iqr.set_value(MASK_DATA)
            time.sleep(0.2)
            iqr.set_value(MASK_POWER | MASK_DATA)
            i = 0

        i += 1
        try:
            time.sleep(0.01)
            xmc_flash(baudrate, tty, firmware)
            break
        except Exception as e:
            print(str(e))

    iqr.set_value(MASK_POWER)

    master.reset()

    ipcon.disconnect()
Example #6
0
 def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue):
     self._bricklet = BrickletIndustrialQuadRelay(uid, connection)
     self.uid = uid
     self.switch_id = switch_id
     self.ip = ip
     self._logging_daemon = logging_daemon
     self._queue = queue
     self._logging_daemon.info('Tinkerforge ... DualRelay-Bricklet "%s" initialisiert' % uid)
def setPins(output1,output2,output3,output4):
      ipcon = IPConnection() # Create IP connection
      relay = BrickletIndustrialQuadRelay(UID_RELAY, ipcon) # Create device object

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

      relayValue = 0

      if output1:
          relayValue |= (1 << 0)

      if output2:
          relayValue |= (1 << 1)

      if output3:
          relayValue |= (1 << 2)

      if output4:
          relayValue |= (1 << 3)

      relay.set_value(relayValue)

      ipcon.disconnect()
Example #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your Industrial Quad Relay Bricklet

import time

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_industrial_quad_relay import BrickletIndustrialQuadRelay

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

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

    # Turn relays alternating on/off 10 times with 100 ms delay
    for i in range(10):
        time.sleep(0.1)
        iqr.set_value(1 << 0)
        time.sleep(0.1)
        iqr.set_value(1 << 1)
        time.sleep(0.1)
        iqr.set_value(1 << 2)
        time.sleep(0.1)
        iqr.set_value(1 << 3)

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

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Industrial Quad Relay Bricklet

import time

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_industrial_quad_relay import BrickletIndustrialQuadRelay

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

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

    # Turn relays alternating on/off 10 times with 100 ms delay
    for i in range(10):
        time.sleep(0.1)
        iqr.set_value(1 << 0)
        time.sleep(0.1)
        iqr.set_value(1 << 1)
        time.sleep(0.1)
        iqr.set_value(1 << 2)
        time.sleep(0.1)
        iqr.set_value(1 << 3)

    raw_input("Press key to exit\n") # Use input() in Python 3