Hello. At first excuse me for my poor English. <br>I&#39;ve making a python library for handle the pcican board, using the canlib library. It works fine. <br>Now, I have to integrate to a twisted application that I made, for package encapsulation over tcp/ip. This works fine in serialport using 
abstract.filedescriptor and pyserial, but in the canlib case I have no file descriptor for this. <br><br>What can I do for encapsulate like serial protocol, but with canlib methods? <br>I have to re factorize the pycanlib library to build a file descriptor that represents, or is a way to readapt the 
abstract.filedescriptor for that?<br>The methods that I have is:<br><br>Channel.readWait() &lt;- this is persistent<br>Channel.read() &lt;-this is not persistent. If buffer is empty returns.<br>Channel.write(&lt;can package attributes&gt;)
<br clear="all"><br>More details:<br><br>This is the file descriptor I wrote... <br>----------------<br># twisted imports<br>from twisted.internet import abstract, fdesc, main<br>import canlib<br>from canlib import canOPEN_EXCLUSIVE, canWANT_EXTENDED, BAUD_1M, canDRIVER_NORMAL
<br><br>class CANConnector(abstract.FileDescriptor):<br>&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp; Conector para el dispositivo pcican usando pycanlib<br>&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br><br>&nbsp;&nbsp;&nbsp; connected = 1<br><br>&nbsp;&nbsp;&nbsp; def __init__(self, protocol, conf, reactor):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abstract.FileDescriptor.__init__(self, reactor)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._channel = canlib.Channel(0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._channel.open(canOPEN_EXCLUSIVE | canWANT_EXTENDED)<br>&nbsp;&nbsp;&nbsp; self._channel.setBusOff()<br>&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; self._channel.setBusParams(BAUD_1M, 4, 3, 1, 1)<br>&nbsp;&nbsp;&nbsp; self._channel.setBusOutputControl(canDRIVER_NORMAL)<br><br>&nbsp;&nbsp;&nbsp; self._channel.setBusOn()<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.reactor = reactor<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.protocol = protocol
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; self.protocol.makeConnection(self)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.startReading()<br><br><br>&nbsp;&nbsp;&nbsp; def writeSomeData(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self._channel.write(1000, data, 10, 0)<br><br>&nbsp;&nbsp;&nbsp; def doRead(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pack = self._channel.readWait()<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # returns the message of package<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return pack[&#39;msg&#39;]<br><br>&nbsp;&nbsp;&nbsp; def connectionLost(self, reason=None):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abstract.FileDescriptor.connectionLost
(self, reason)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._channel.close()<br>------------<br><br>in the main tac service this is how I use the connector:<br><br>---------------<br>(...)<br><br>class ServiceChannel(protocol.Protocol):<br>&nbsp;&nbsp;&nbsp; def connectionMade(self):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;Canal conectado&#39;<br><br>&nbsp;&nbsp;&nbsp; def dataReceived(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;datorecibido&quot;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s.writeOnPort(data)<br><br>&nbsp;&nbsp;&nbsp; def connectionLost(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;Canal desconectado&#39;
<br><br>class SimulatorService(service.Service):<br>&nbsp;&nbsp;&nbsp; (...)<br><br>&nbsp;&nbsp;&nbsp; def startChannel(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (...)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = ServiceChannel()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (...)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.channel = CANConnector(c, self.conf.channel
, reactor)<br><br>&nbsp;&nbsp;&nbsp; (...)<br>&nbsp;&nbsp;&nbsp; def writeOnPort(self, data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.factory.instance.transport.write(data)<br><br>--------<br>This application pipes the can comunications whith a tcp ip port.<br><br>Then ,when I run: 
<br>$ twistd -ny main.tac<br><br>2007/11/30 10:52 -0300 [-] Log opened.<br>2007/11/30 10:52 -0300 [-] twistd 2.5.0 (/usr/bin/python 2.5.1) starting up<br>2007/11/30 10:52 -0300 [-] reactor class: &lt;class &#39;twisted.internet.selectreactor.SelectReactor
&#39;&gt;<br>2007/11/30 10:52 -0300 [-] Loading main.tac...<br>2007/11/30 10:52 -0300 [-] /usr/bin/twistd: option -n not recognized<br>2007/11/30 10:52 -0300 [-] /usr/bin/twistd: Try --help for usage details.<br>2007/11/30 10:52 -0300 [-] Loaded.
<br>2007/11/30 10:52 -0300 [-] __builtin__.ServiceFactory starting on 5000<br>2007/11/30 10:52 -0300 [-] Starting factory &lt;__builtin__.ServiceFactory instance at 0x84069cc&gt;<br>2007/11/30 10:52 -0300 [__builtin__.ServiceFactory] {&#39;protocol&#39;: &#39;can&#39;, &#39;number&#39;: &#39;0&#39;, &#39;channel&#39;: &#39;1&#39;}
<br>2007/11/30 10:52 -0300 [__builtin__.ServiceFactory] Canal conectado<br>2007/11/30 10:52 -0300 [__builtin__.ServiceFactory] channel started.................<br>2007/11/30 10:52 -0300 [__builtin__.ServiceFactory] se generan los archivos de registro
<br><br>&lt;... (Connect to 5000 port ) ..&gt;<br><br>2007/11/30 10:52 -0300 [__builtin__.ServiceFactory] Conexion establecida desde IPv4Address(TCP, &#39;<a href="http://192.168.6.38">192.168.6.38</a>&#39;, 5000)<br>2007/11/30 10:52 -0300 [-] Unhandled Error
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Traceback (most recent call last):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File &quot;/usr/lib/python2.5/site-packages/twisted/scripts/_twistd_unix.py&quot;, line 214, in postApplication<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; app.runReactorWithLogging(self.config
, self.oldstdout, self.oldstderr)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File &quot;/usr/lib/python2.5/site-packages/twisted/application/app.py&quot;, line 113, in runReactorWithLogging<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.run()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File &quot;/usr/lib/python2.5/site-packages/twisted/internet/posixbase.py&quot;, line 220, in run
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.mainLoop()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File &quot;/usr/lib/python2.5/site-packages/twisted/internet/posixbase.py&quot;, line 231, in mainLoop<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.doIteration(t)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --- &lt;exception caught here&gt; ---
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File &quot;/usr/lib/python2.5/site-packages/twisted/internet/selectreactor.py&quot;, line 97, in doSelect<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [], timeout)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exceptions.ValueError: file descriptor cannot be a negative integer (-1)
<br><br>2007/11/30 10:52 -0300 [-] Malformed file descriptor found.&nbsp; Preening lists.<br>2007/11/30 10:52 -0300 [-] bad descriptor &lt;can.CANConnector object at 0x83e94ec&gt;<br><br>Thanks for your attention. <br><br>Fran
<br><br>PD: If anybody is interested in this pycanlib library I pass the source for liberation.<br><br>-- <br>&quot;El hombre se descubre cuando se mide con un obstáculo&quot; <br>(Saint Exupéry)