Ejemplo n.º 1
0
    def __init__(self, identifier, protocol, reactor=None):
        assert IRFIDReaderProtocol.implementedBy(protocol.__class__)

        self.events = EventDispatcher()
        self.events.setEventParent(rfidEvents)

        self.identifier = identifier

        self.protocol = protocol
        self.protocol.events.addObserver("tag-present", self.gotTag)
        self.protocol.events.setEventParent(self.events)

        self.protocol.start()

        self.tags = {}
        if reactor is None:
            from twisted.internet import reactor
        self.reactor = reactor
Ejemplo n.º 2
0
class RFIDReader (object):

    identifier = None
    protocol = None

    reactor = None
    timeout = 0.5

    def __init__(self, identifier, protocol, reactor=None):
        assert IRFIDReaderProtocol.implementedBy(protocol.__class__)

        self.events = EventDispatcher()
        self.events.setEventParent(rfidEvents)

        self.identifier = identifier

        self.protocol = protocol
        self.protocol.events.addObserver("tag-present", self.gotTag)
        self.protocol.events.setEventParent(self.events)

        self.protocol.start()

        self.tags = {}
        if reactor is None:
            from twisted.internet import reactor
        self.reactor = reactor


    def _tagTimeout(self, tpe, tag):
        self.events.dispatch("tag-removed", {'tag': tag, 'type': tpe, 'reader': self.identifier})
        del self.tags[tag]


    def gotTag(self, tpe, tag):
        if tag in self.tags:
            return self.tags[tag].reset(self.timeout)
        self.tags[tag] = self.reactor.callLater(self.timeout, self._tagTimeout, tpe, tag)
        self.events.dispatch("tag-added", {'tag': tag, 'type': tpe, 'reader': self.identifier})


    def __del__(self):
        print "del"