A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
913 B

  1. import time
  2. from pyad2 import AD2
  3. from pyad2.devices import SocketDevice
  4. def main():
  5. """
  6. Example application that opens a device that has been exposed to the network
  7. with ser2sock or similar serial->ip software.
  8. """
  9. try:
  10. # Retrieve an AD2 device that has been exposed with ser2sock on localhost:10000.
  11. device = AD2(SocketDevice(interface=('localhost', 10000)))
  12. # Set up an event handler and open the device
  13. device.on_message += handle_message
  14. device.open()
  15. device.get_config()
  16. # Wait for events.
  17. while True:
  18. time.sleep(1)
  19. except Exception, ex:
  20. print 'Exception:', ex
  21. finally:
  22. device.close()
  23. def handle_message(sender, *args, **kwargs):
  24. """
  25. Handles message events from the AD2.
  26. """
  27. msg = kwargs['message']
  28. print sender, msg.raw
  29. if __name__ == '__main__':
  30. main()