[zeromq-dev] zmq_poll on a gpio file descriptor on a beaglebone

Craig Swank craigswank at gmail.com
Thu Feb 28 21:47:22 CET 2013


I'm trying use zmq_poll to poll both a zmq_socket and a file descriptor for
a gpio input pin on a beaglebone using pyzmq.  Does anyone know if this is
possible?  I wrote a python script that tries to poll on the gpio pin only
(in order to keep the example as simple as possible).  After opening an
issue at pyzmq and some back and forth with the person who responded to my
issue, it seems that what I'm asking for is not supported.

My question, is what I'm asking for supported, and if not should I issue a
feature request with zmq?

Here is the example script.  I have two functions - wait and zmq_wait.
wait blocks until I press a button connected to the gpio pin on the
beaglebone.  zmq_wait never blocks::

    import os, select, time
    import zmq

    class MyObj(object):
        """
        Pyzmq docs claim that any object
        that provides a 'fileno' function
        can be passed to the register function
        of the zmq.Poller
        """
        def __init__(self, fd):
            self.fd = fd

        def fileno(self):
            return self.fd


    def wait(fd):
        os.read(fd, 2)
        poller = select.poll()
        poller.register(fd, select.POLLPRI)
        events = poller.poll(-1)
        os.lseek(fd, 0, 0)
        val = os.read(fd, 2)
        print 'poller returned', val


    def zmq_wait(fd):
        os.read(fd, 2)
        poller = zmq.Poller()
        poller.register(fd, zmq.POLLIN)
        events = poller.poll(-1)
        os.lseek(fd, 0, 0)
        val = os.read(fd, 2)
        print 'zmq poller returned', val

    path = '/sys/class/gpio/gpio89/value'
    #the gpio pin has already been configured as input, and to trigger an
event
    #on a rising edge by doing "echo 'rising' > /sys/class/gpio/gpio89/edge"
    fd = os.open(path, os.O_RDONLY | os.O_NONBLOCK)

    #this function blocks until I push the button
    zmq_wait(fd) #returns immediately

    wait(fd) #blocks until I push the button connected to the gpio pin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130228/2cae38c1/attachment.htm>


More information about the zeromq-dev mailing list