Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1251

Python • Working with new lirc client 0.10.1

$
0
0
I wasted a lot of time searching for any samples as previously posted examples not working due to the current changes in lirc python module.
To save time to others who are interested - here is small script test that will work with current lirc module:

$ cat pylirc.py

Code:

#!/usr/bin/pythonimport lirc#import socketdef ProcessIRRemote():           #get IR command    #keypress format = (hexcode, repeat_num, command_key, remote_id)    try:        keypress = conn.readline()    #do not handle all exceptions or you have to kill process to stop    except TimeoutError:        keypress=""        #print ("\nTimeout")                  if (keypress != "" and keypress != None):                        data = keypress.split()        sequence = data[1]        command = data[2]                #ignore command repeats        if (sequence != "00"):           return                print(command)#define Globalclient = lirc.Client()print("lirc client version:", client.version())conn = lirc.LircdConnection()#conn=lirc.LircdConnection(#     address="/var/run/lirc/lircd",#     socket=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM),#     timeout = 5.0#   )conn.connect()print("Listening...")try:    while True:                 ProcessIRRemote()except KeyboardInterrupt:    print ("\nShutting down...")    conn.close()

Statistics: Posted by victorPi1234 — Sun Aug 04, 2024 2:10 pm



Viewing all articles
Browse latest Browse all 1251

Trending Articles