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.

37 lines
892 B

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