Page 1 of 1

Python Send Command

PostPosted: Wed Jan 20, 2016 2:38 pm
by dot850
Hello,

I am trying to figure out a way to arm the alarm from the python code provided. From looking at the documentation, I find what I think should be device.send() but I get an error back that the object have no attribute 'send.'

Can anybody help? Can I simulate key presses like this to arm the alarm from python?

Thanks,

DOT850

P.S. It is really difficult to search the forums on here because it seems that everything I search for is "common" and is removed. If I get too many hits from searching for common terms that should be my problem, not the forum. Just a thought. :-)

Re: Python Send Command

PostPosted: Wed Jan 20, 2016 5:11 pm
by kevin
Here is a working example of a send while connected to a SocketDevice:

Code: Select all
import time
from alarmdecoder import AlarmDecoder
from alarmdecoder.devices import SocketDevice

# Configuration values
HOSTNAME = 'alarmdecoder-demo.local'
PORT = 10000

def main():
    """
    Example application that opens a device that has been exposed to the network
    with ser2sock or similar serial-to-IP software.
    """
    try:
        # Retrieve an AD2 device that has been exposed with ser2sock on localhost:10000.
        device = AlarmDecoder(SocketDevice(interface=(HOSTNAME, PORT)))

        # Set up an event handler and open the device
        device.on_message += handle_message
        with device.open():
            device.send('12343')
            time.sleep(5)
            device.send('12341')
            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()


Have adjusted search to remove "Common Words" filtering all together.

Re: Python Send Command

PostPosted: Thu Jan 21, 2016 4:45 am
by dot850
Thanks Kevin. You guys are awesome. Are there more examples like this posted somewhere I am missing. I have the examples that came with the python package, did I miss this example somehow?

The next thing I would like to be able to do is see the button presses on the keypad if that is possible?

Thanks so much for all the help.

Re: Python Send Command

PostPosted: Thu Jan 21, 2016 10:36 am
by kevin
Sorry, I modified an existing example for that, you did not miss it.

It is not possible to see what keys are being pressed.