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
965 B

  1. import time
  2. from alarmdecoder import AlarmDecoder
  3. from alarmdecoder.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 = AlarmDecoder(SerialDevice(interface=SERIAL_DEVICE))
  14. # Set up an event handler and open the device
  15. device.on_message += handle_message
  16. # Override the default SerialDevice baudrate since we're using a USB device
  17. # over serial in this example.
  18. with device.open(baudrate=BAUDRATE):
  19. while True:
  20. time.sleep(1)
  21. except Exception, ex:
  22. print 'Exception:', ex
  23. def handle_message(sender, message):
  24. """
  25. Handles message events from the AlarmDecoder.
  26. """
  27. print sender, message.raw
  28. if __name__ == '__main__':
  29. main()