Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

"No handle available"

Sun Oct 05, 2014 6:27 pm

Hello all.
randomly it happens that my i2c devices goes offline and i get a "no handle available" error.
If i reboot the pi, i2c starts up again.
I had never seen this error so i'm wondering where is this coming from.
have you ever seen this? is there a "i2c log" somewhere i can check to investigate the problem?

Thanks

User avatar
DougieLawson
Posts: 39813
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: "No handle available"

Sun Oct 05, 2014 8:48 pm

The driver logs messages to the kernel log. You can see those with a dmesg command.

Have you tried using rmmod to unload the driver and modprobe to reload it?

Code: Select all

sudo rmmod i2c_dev
sudo rmmod i2c_bcm2708
sudo modprobe i2c_dev
sudo modprobe i2c_bcm2708
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: "No handle available"

Sun Oct 05, 2014 9:28 pm

mmm
i'm now noticing that it's only with joan's pigpio.

Little background :) today i finally took my weather sensors outside, so some meters of cable, and now i'm testing.
All seems to work, but as i said before after a while (let's say an hour or so) the error comes.

BUT

Now i've tried an adc reading with smbus and it's ok!
On the other side, the same code written with PIGPIO i2c functions is broken

this is the error, maybe joan will light my way :)

Code: Select all

Traceback (most recent call last):
[my code]
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1707, in i2c_open
    self._control, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents))
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 644, in _u2i
    raise error(error_text(v))
pigpio.error: 'no handle available'
i don't think i'm going to read pigpio sources :)

Edit: i tried with baudrate 100000, 400000 and 32000 just to see if it could be something cable related.. same behaviour..

User avatar
joan
Posts: 15038
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: "No handle available"

Sun Oct 05, 2014 9:52 pm

No handle available means that all 32 handles are in use. Assuming you aren't using 32 devices it means you have opened an I2C device without closing it at the end of the script.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: "No handle available"

Mon Oct 06, 2014 5:50 am

joan wrote:No handle available means that all 32 handles are in use. Assuming you aren't using 32 devices it means you have opened an I2C device without closing it at the end of the script.
i can easily have done this :)
so it's just a matter of my stupidity, that's clear..

need to check my bmp180 script..
btw, is there a way to know how many handles i am using?

Thanks joan

User avatar
joan
Posts: 15038
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: "No handle available"

Mon Oct 06, 2014 6:10 am

pattagghiu wrote:
joan wrote:No handle available means that all 32 handles are in use. Assuming you aren't using 32 devices it means you have opened an I2C device without closing it at the end of the script.
i can easily have done this :)
so it's just a matter of my stupidity, that's clear..

need to check my bmp180 script..
btw, is there a way to know how many handles i am using?

Thanks joan
I should make it clear in the documentation that "objects" created on the daemon are not purged when the daemon connection is dropped.

In particular gpios remain in their last set state (mode, level, pull-up, servo pulse, PWM etc), handles (serial, I2C, SPI, bit bang serial) remain open, scripts remain, waves remain. They all exist until closed by the user for the life-time of the daemon.

No, there is no way of querying the number of handles in use.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: "No handle available"

Mon Oct 06, 2014 1:50 pm

Good, this means i have to check all my PIGPIO scripts to see if i'm leaving something open..
So, i.e., i should manage the closing of "things" even when catching exceptions, otherwise i'm leaving them open for nothing..
But, at least, a little fix to BMP180 script has made it rock solid.
Thanks joan, as always

jamesokbo
Posts: 2
Joined: Wed Nov 12, 2014 3:43 pm

Re: "No handle available"

Thu Nov 20, 2014 12:06 am

Ok, so I have too many I2C devices open... How do I close them? haha

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: "No handle available"

Thu Nov 20, 2014 11:12 am

jamesokbo wrote:Ok, so I have too many I2C devices open... How do I close them? haha
restart your pigpio daemon and edit your scripts to close i2c connections at exit :)

User avatar
joan
Posts: 15038
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: "No handle available"

Thu Nov 20, 2014 5:06 pm

jamesokbo wrote:Ok, so I have too many I2C devices open... How do I close them? haha
If none are meant to be open you can enter the following from the command line.

Code: Select all

for ((i=0; i<32; i++)); do pigs i2cc $i; done
It'll close any open handle (and give a warning if the handle wasn't open which you should ignore).

electro1300n
Posts: 1
Joined: Mon Feb 18, 2019 8:42 pm

Re: "No handle available"

Mon Feb 18, 2019 8:48 pm

Clean way of closing handles when the count is up to 30

Code: Select all

from pigpio import pi
x_pi = pi('192.168.0.51')
if not x_pi.connected:
    print('Unable to connect to RPi')
else:
    h = x_pi.i2c_open(1, 118)
    x_pi.i2c_close(h)
    print(h)
    if h > 30:
        x = h - 1
        while x >= 0:
            x_pi.i2c_close(x)
            x = x - 1
        print(str(h) + ' pigpio handles closed')
    x_pi.stop()
[moderator added code tags]

Return to “Interfacing (DSI, CSI, I2C, etc.)”