niolabs / python-xbee

Python tools for working with XBee radios
MIT License
101 stars 45 forks source link

Callback not called #28

Closed wackazong closed 7 years ago

wackazong commented 7 years ago

Python newbie question: I try to wrap the xBee connection into a class. But the callback gets never called if it is a class method. If it is not in a class it works fine. What can I do?

class Receiver: def enter(self): self.serial_port = serial.Serial('/dev/ttyUSB0', 115200)
self.xbee = ZigBee(self.serial_port, escaped=True, callback=self.handlePackets) Logger.info('Receiver: enter') return self def exit(self ,type, value, traceback): Logger.info('Receiver: exit') self.serial_port.close() def handlePackets(data): Logger.info('Receiver: packet incoming')

hansmosh commented 7 years ago

It's hard to say what is wrong since your comment doesn't have any indentation, but try adding self to def handlePackets(self, data):.

Questions like this are better asked on a site like stackoverflow.com. GitHub Issues are generally meant for reporting issues with the code in this repository, not with individual issues with using it.