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.

41 lines
941 B

  1. import time
  2. from pyad2 import AD2
  3. from pyad2.devices import SerialDevice
  4. # Configuration values
  5. SERIAL_DEVICE = '/dev/ttyUSB0'
  6. BAUDRATE = 115200
  7. def main():
  8. """
  9. Example application that opens a serial device and prints messages to the terminal.
  10. """
  11. try:
  12. # Retrieve the specified serial device.
  13. device = AD2(SerialDevice(interface=SERIAL_DEVICE))
  14. # Set up an event handler and open the device
  15. device.on_message += handle_message
  16. device.open(baudrate=BAUDRATE) # Override the default SerialDevice baudrate.
  17. # Wait for events.
  18. while True:
  19. time.sleep(1)
  20. except Exception, ex:
  21. print 'Exception:', ex
  22. finally:
  23. device.close()
  24. def handle_message(sender, *args, **kwargs):
  25. """
  26. Handles message events from the AD2.
  27. """
  28. msg = kwargs['message']
  29. print sender, msg.raw
  30. if __name__ == '__main__':
  31. main()