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.

42 lines
969 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. device.get_config()
  18. # Wait for events.
  19. while True:
  20. time.sleep(1)
  21. except Exception, ex:
  22. print 'Exception:', ex
  23. finally:
  24. device.close()
  25. def handle_message(sender, *args, **kwargs):
  26. """
  27. Handles message events from the AD2.
  28. """
  29. msg = kwargs['message']
  30. print sender, msg.raw
  31. if __name__ == '__main__':
  32. main()