报警解码器(AD2)系列报警设备的Python接口,包括AD2USB、AD2Serial和AD2PI。
alarmdecoder的Python项目详细描述
摘要
这个python库旨在为 AlarmDecoder生产线。(AD2USB、AD2串行和AD2PI)。 这还包括通过ser2sock公开的设备,这些设备 支持通过ssl/tls进行加密。
安装
AlarmDecoder可以通过pip:
安装pip install alarmdecoder
或来源:
python setup.py install
- 注意:安装需要python-setuptools。
文档
api文档可以在readthedocs找到。
示例
下面是一个基本的例子。请参阅examples目录 更多信息。
import time from alarmdecoder import AlarmDecoder from alarmdecoder.devices import SerialDevice def main(): """ Example application that prints messages from the panel to the terminal. """ try: # Retrieve the first USB device device = AlarmDecoder(SerialDevice(interface='/dev/ttyUSB0')) # Set up an event handler and open the device device.on_message += handle_message with device.open(baudrate=115200): while True: time.sleep(1) except Exception as ex: print ('Exception:', ex) def handle_message(sender, message): """ Handles message events from the AlarmDecoder. """ print sender, message.raw if __name__ == '__main__': main()