From 77da554d5ba18e10ac9a5a78f46baa064f4f153e Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Tue, 10 Dec 2013 11:07:59 -0800 Subject: [PATCH] Added example. Cleanup. --- README.md | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8cd92dc..06066dc 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,20 @@ -alarmdecoder - Python library for the Alarm Decoder (AD2) device family -======================================================================= +Alarm Decoder +================================================================== +#### Interface for the Alarm Decoder (AD2) device family #### -This Python module aims to provide a consistent interface for all of the Alarm -Decoder product line, including the AD2USB, AD2SERIAL and AD2PI devices. This -also includes devices that have been exposed via [ser2sock](http://github.com/nutechsoftware/ser2sock) and supports -encryption via SSL/TLS. + +This Python library aims to provide a consistent interface for the entire Alarm +Decoder product line, including the AD2USB, AD2SERIAL and AD2PI devices. +This also includes devices that have been exposed via [ser2sock](http://github.com/nutechsoftware/ser2sock), which +supports encryption via SSL/TLS. Installation ------------ - alarmdecoder can be installed through pip: - pip install alarmdecoder + ```pip install alarmdecoder``` or from source: - python setup.py install + ```python setup.py install``` Requirements ------------ @@ -24,16 +25,41 @@ Requirements Documentation ------------- - API documentation can be found [here](http://github.com/nutechsoftware/alarmdecoder/tree/master/docs/_build/html). Examples -------- +A basic example is included below. Please see the [examples](http://github.com/nutechsoftware/alarmdecoder/tree/master/examples) directory for more. -Basic usage: ```python +import time +from alarmdecoder import AlarmDecoder +from alarmdecoder.devices import USBDevice -``` +def main(): + """ + Example application that prints messages from the panel to the terminal. + """ + try: + # Retrieve the first USB device + device = AlarmDecoder(USBDevice.find()) -Please see the [examples](http://github.com/nutechsoftware/alarmdecoder/tree/master/examples) directory for more. + # Set up an event handler and open the device + device.on_message += handle_message + with device.open(): + while True: + time.sleep(1) + + except Exception, ex: + print 'Exception:', ex + +def handle_message(sender, message): + """ + Handles message events from the AlarmDecoder. + """ + print sender, message.raw + +if __name__ == '__main__': + main() +```