Page 1 of 2
Help with printing terminal messages
Posted:
Fri Dec 04, 2015 9:39 am
by billbrazeal
I am not a python programmer (yet). But I have cobbled together some code to send commands from a program to the keypad, and it works. But, I want to be able to see the messages back from the command on the terminal. However, I don't see anything from this code (see attachment). What am I missing to be able to see the resulting messages?
- Screen Shot 2015-12-04 at 11.35.09 AM.png (74.71 KiB) Viewed 11505 times
Thanks
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 10:37 am
by kevin
To see the messages FROM the panel you would want to override the on_message event, as such:
- Code: Select all
# Set up an event handler and open the device
device.on_message += handle_message
And you definitely don't want to keep assigning your event handlers in your loop as you are with the on_sending_received message - that will result in some weirdness.
Then define your message handler function as such:
- Code: Select all
def handle_message(sender, message):
"""
Handles message events from the AlarmDecoder.
"""
print sender, message.raw
It will print the "raw" message.
You can find the API Documentation here:
http://alarmdecoder.readthedocs.org/en/ ... rmdecoder/
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 12:22 pm
by billbrazeal
OK, Thanks. I made the changes suggested and the code runs without error but I still don't see any messages on the terminal. It seems that the handle_message routine does not get called for some reason. Any thoughts?
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 1:15 pm
by kevin
You want to see what you're sending the decoder, or you want to see messages from the decoder?
https://github.com/nutechsoftware/alarm ... _device.py This code example shows how to connect to a USB Device, as well as print out messages from the decoder to the terminal.
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 1:19 pm
by billbrazeal
what is coming back from the decoder. I basically want to see if the system is armed or not. But I am not seeing anything on the terminal from the message routine. I put a generic print in the message handler routine and it is not even getting called apparently.
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 1:20 pm
by kevin
Check out our examples -
https://github.com/nutechsoftware/alarm ... _device.pyDo note that since it is a serial port - if you have other items using the serial port, you will not be able to use it with your script. If you are setup to use ser2sock, I suggest using the SocketDevice class.
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 1:34 pm
by billbrazeal
OK, that may be the problem. So I am trying the example for the SocketDevice but I am using a AD2PI device not an AD2USB. When I try the example it errors on No AD2USB devices present. What should I use instead of the device = AlarmDecoder(USBDevices.find()) command?
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 1:46 pm
by billbrazeal
Never mind, I found the answers in the socket_example.py. Got it to work, exactly what I needed. Thank you for your help!
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 1:58 pm
by billbrazeal
Well, I spoke a little too soon. The first time I ran the program it printed out the raw message. Then on subsequent executions of the script, nothing. See image below of the terminal window. Why would it behave this way?
- Screen Shot 2015-12-04 at 3.55.43 PM.png (24.54 KiB) Viewed 11492 times
Re: Help with printing terminal messages
Posted:
Fri Dec 04, 2015 2:04 pm
by kevin
You have to make sure to call decoder.close() on exit otherwise the serial port will not get released - will have to update the examples to show this.