-1

I'm trying to get LIRC functioning within my code. I've created some test code but I'm receiving this error:

Traceback (most recent call last):
  File "ir_remote.py", line 5, in <module>
    config = lirc.nextcode()
  File "lirc.pyx", line 183, in lirc.nextcode (lirc/lirc.c:2983)
  File "lirc.pyx", line 217, in lirc._is_init_or_error (lirc/lirc.c:3472)
lirc.InitError: lirc has not been initialised.

The code I created:

#!/usr/bin/python
import lirc, time
import RPi.GPIO as GPIO

config = lirc.nextcode()

sockid = lirc.init(blocking = False)

if config == 'KEY_DOWN':
    print 'Red OFF'
if config == 'KEY_UP':
    print 'Light Red'
if config == 'KEY_LEFT':
    print 'Red'
if config == 'KEY_RIGHT':
    print 'Green OFF'
if config == 'KEY_OK':
    print 'Light Green'
if config == 'KEY_1':
    print 'Green'
if config == 'KEY_2':
    print 'Blue OFF'
if config == 'KEY_3':
    print 'Light Blue'
if config == 'KEY_4':
    print 'BLUE'
demongolem
  • 9,474
  • 36
  • 90
  • 105

1 Answers1

1

You need to swap these two lines around:

config = lirc.nextcode()
sockid = lirc.init(blocking = False)

Because you need to initialize lirc before starting to use it.
Should look like this:

sockid = lirc.init(blocking = False)
config = lirc.nextcode()

At least according to all their documentation, just noticed @larsks said the same thing and I gotta say it too. I've never worked with this library before, but checking the documentation and the error message, it's a reasonable assumption.

Torxed
  • 22,866
  • 14
  • 82
  • 131