<br><br><div class="gmail_quote">On Sun, Feb 12, 2012 at 7:10 PM, Phil Mayers <span dir="ltr">&lt;<a href="mailto:p.mayers@imperial.ac.uk">p.mayers@imperial.ac.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 02/12/2012 04:13 AM, Donal McMullan wrote:<br>
&gt; I&#39;m trying to integrate Twisted with libusb-1<br>
&gt;<br>
&gt; The libusb-1 Python wrapper offers a USBPoller class to &quot;allow<br>
&gt; integration of USB event polling in a file-descriptor monitoring event<br>
&gt; loop.&quot; The class expects to receive a &#39;poller&#39; object, again quoting<br>
&gt; from the documentation:<br>
&gt;<br>
&gt;      poller is a polling instance implementing the following methods:<br>
&gt;      - register(fd, event_flags)<br>
</div>&gt;        event_flags have the same meaning as in poll API (POLLIN&amp;  POLLOUT)<br>
<div class="im">&gt;      - unregister(fd)<br>
&gt;      - poll(timeout)<br>
&gt;        timeout being a float in seconds, or None if there is no timeout.<br>
&gt;        It must return a list of (descriptor, event) pairs.<br>
&gt;      Note: USBPoller is itself a valid poller.<br>
&gt;<br>
&gt; I feel like it should be obvious, but I can&#39;t see what would be the<br>
&gt; correct way to integrate this with Twisted. My particular application<br>
&gt; is to enable networking over the ANT+ protocol via a small USB key.<br>
<br>
</div>I&#39;ve only quickly scanned it, but actually it doesn&#39;t look obvious to me<br>
at all.<br>
<br>
I *think* that you want to ignore USBPoller entirely; it looks like it&#39;s<br>
some sort of mini reactor thing, although it&#39;s not obvious to me how it<br>
ever DOES anything.<br>
<br>
USBContext looks to be the &quot;thing&quot; that you plug in an event loop to.<br>
<br>
However, I&#39;m not certain (perhaps others will comment) that it makes<br>
sense to integrate it into the Twisted event loop - the file descriptor<br>
&quot;ready&quot; events don&#39;t seem to trigger corresponding &quot;read&quot; events, and<br>
the USB protocol implementation isn&#39;t accessible, so the Twisted model of:<br>
<br>
  file ready event -&gt; transport does read -&gt; protocol dataReceived<br>
<br>
...doesn&#39;t really apply.<br>
<br>
It may be just as easy to write wrapper around your protocol in plain<br>
non-Twisted python, and talk to it from Twisted over a<br>
pipe/process/whatever.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div> the most simplest way is probably to use another thread to handle all possible events and use twisted&#39;s thread functions to </div><div>leverage the whole system though it is inefficient. </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>