7 Provides the Dispatch class, which allows one to filter incoming data 8 packets from an XBee device and call an appropriate method when 27 register: string, function: string, data -> None, function: data -> boolean -> None 29 Register will save the given name, callback, and filter function 30 for use when a packet arrives. When one arrives, the filter 31 function will be called to determine whether to call its associated 32 callback function. If the filter method returns true, the callback 33 method will be called with its associated name string and the packet 34 which triggered the call. 36 if name
in self.
names:
37 raise ValueError(
"A callback has already been registered with the name '%s'" % name)
47 def run(self, oneshot=False):
51 run will read and dispatch any packet which arrives from the 55 raise ValueError(
"Either a serial port or an XBee must be provided to __init__ to execute run()")
58 self.
dispatch(self.xbee.wait_read_frame())
65 dispatch: XBee data dict -> None 67 When called, dispatch checks the given packet against each 68 registered callback method and calls each callback whose filter 69 function returns true. 72 if handler[
'filter'](packet):
75 handler[
'callback'](handler[
'name'], packet)
def register(self, name, callback, filter)
def __init__(self, ser=None, xbee=None)
def dispatch(self, packet)
def run(self, oneshot=False)