Help with printing terminal messages

General Discussion

Help with printing terminal messages

Postby billbrazeal » Fri Dec 04, 2015 9:39 am

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
Screen Shot 2015-12-04 at 11.35.09 AM.png (74.71 KiB) Viewed 11498 times


Thanks
billbrazeal
newt
newt
 
Posts: 10
Joined: Mon Nov 30, 2015 8:53 am

Re: Help with printing terminal messages

Postby kevin » Fri Dec 04, 2015 10:37 am

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/
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: Help with printing terminal messages

Postby billbrazeal » Fri Dec 04, 2015 12:22 pm

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?
billbrazeal
newt
newt
 
Posts: 10
Joined: Mon Nov 30, 2015 8:53 am

Re: Help with printing terminal messages

Postby kevin » Fri Dec 04, 2015 1:15 pm

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.
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: Help with printing terminal messages

Postby billbrazeal » Fri Dec 04, 2015 1:19 pm

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.
billbrazeal
newt
newt
 
Posts: 10
Joined: Mon Nov 30, 2015 8:53 am

Re: Help with printing terminal messages

Postby kevin » Fri Dec 04, 2015 1:20 pm

Check out our examples - https://github.com/nutechsoftware/alarm ... _device.py

Do 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.
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: Help with printing terminal messages

Postby billbrazeal » Fri Dec 04, 2015 1:34 pm

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?
billbrazeal
newt
newt
 
Posts: 10
Joined: Mon Nov 30, 2015 8:53 am

Re: Help with printing terminal messages

Postby billbrazeal » Fri Dec 04, 2015 1:46 pm

Never mind, I found the answers in the socket_example.py. Got it to work, exactly what I needed. Thank you for your help!
billbrazeal
newt
newt
 
Posts: 10
Joined: Mon Nov 30, 2015 8:53 am

Re: Help with printing terminal messages

Postby billbrazeal » Fri Dec 04, 2015 1:58 pm

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
Screen Shot 2015-12-04 at 3.55.43 PM.png (24.54 KiB) Viewed 11485 times
billbrazeal
newt
newt
 
Posts: 10
Joined: Mon Nov 30, 2015 8:53 am

Re: Help with printing terminal messages

Postby kevin » Fri Dec 04, 2015 2:04 pm

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.
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Next

Return to General

Who is online

Users browsing this forum: No registered users and 9 guests

cron