[zeromq-dev] zmq_poll on a gpio file descriptor on a beaglebone
Eric Hill
eric.hill at gmail.com
Fri Mar 1 00:56:39 CET 2013
Do you have access to the python threading library on that board? If so, I
would poll the gpio pin in one thread, the zmq socket in a second thread,
and have both threads signal a mutex that your main thread is waiting on.
On Feb 28, 2013 5:37 PM, "Craig Swank" <craigswank at gmail.com> wrote:
> 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
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130228/163da672/attachment.htm>
More information about the zeromq-dev
mailing list