コード例 #1
0
class SyncHassebDALIUSBDriver(HassebDALIUSBDriver, SyncDALIDriver):
    """Synchronous ``DALIDriver`` implementation for Hasseb DALI USB device.
    """
    def __init__(self, bus=None, port_numbers=None, interface=0):
        self.backend = USBBackend(HASSEB_USB_VENDOR,
                                  HASSEB_USB_PRODUCT,
                                  bus=bus,
                                  port_numbers=port_numbers,
                                  interface=interface)

    def send(self, command, timeout=2000):
        self.backend.write(self.construct(command))
        frame = None
        backoff = 0.010

        if command.response is not None:
            for i in range(7):
                frame = self.extract(self.backend.read(timeout=timeout))
                if isinstance(frame, HassebDALIUSBNoAnswer):
                    self.backend.write(self.construct(command))
                if isinstance(frame, BackwardFrame):
                    if command.response:
                        return command.response(frame)
                    return frame
                backoff += backoff
                sleep(backoff)
            raise MissingResponse()
        return None
コード例 #2
0
class SyncTridonicDALIUSBDriver(TridonicDALIUSBDriver, SyncDALIDriver):
    """Synchronous ``DALIDriver`` implementation for Tridonic DALI USB device.
    """

    def __init__(self, bus=None, port_numbers=None, interface=0):
        self.backend = USBBackend(
            DALI_USB_VENDOR,
            DALI_USB_PRODUCT,
            bus=bus,
            port_numbers=port_numbers,
            interface=interface
        )

    def send(self, command, timeout=None):
        self.backend.write(self.construct(command))
        frame = None
        # For now read up to 2 frames. This may not be reliable if forward
        # frames are passed between request and response from DALI side.
        # though this may not happen at all due to DALI USB implementation
        # details.
        for i in range(2):
            frame = self.extract(self.backend.read(timeout=timeout))
            if isinstance(frame, BackwardFrame):
                if command.response:
                    return command.response(frame)
                return frame
        return DALI_USB_NO_RESPONSE
コード例 #3
0
class SyncTridonicDALIUSBDriver(TridonicDALIUSBDriver, SyncDALIDriver):
    """Synchronous ``DALIDriver`` implementation for Tridonic DALI USB device.
    """
    def __init__(self, bus=None, port_numbers=None, interface=0):
        self.backend = USBBackend(DALI_USB_VENDOR,
                                  DALI_USB_PRODUCT,
                                  bus=bus,
                                  port_numbers=port_numbers,
                                  interface=interface)

    def send(self, command, timeout=None):
        self.backend.write(self.construct(command))
        frame = None
        # For now read up to 2 frames. This may not be reliable if forward
        # frames are passed between request and response from DALI side.
        # though this may not happen at all due to DALI USB implementation
        # details.
        for i in range(2):
            frame = self.extract(self.backend.read(timeout=timeout))
            if isinstance(frame, BackwardFrame):
                if command.response:
                    return command.response(frame)
                return frame
        return DALI_USB_NO_RESPONSE