Use RFC2217 network serial ports with Twisted Python? -


is there way connect rfc2217 networked serial port twisted python?

pyserial seems support via serial.serial_for_url("rfc2217://...") function. , indicate twisted uses pyserial managing serial connections, twisted.internet.serialport.serialport seems expect port name or number suggests passing serial.serial constructor.

i can use socat create pty externally , pass dev name twisted works fine, wondering if can bypass step using pyserial support directly.

socat pty,link=/dev/myport tcp:192.168.1.222:9001 

edit: pyserial faq suggests modification instantiating serial objects:

try:     s = serial.serial_for_url(...) except attributeerror:     s = serial.serial(...) 

not sure if helps though...

i have come conclusion using pyserial's rfc2217 support twisted python non-trivial. pyserial's implementation of rfc2217, besides being experimental, uses threads manage socket connection state being problem select based applications:

the current implementation starts thread keeps reading (internal) socket. thread managed automatically rfc2217.serial port object on open()/close(). may problem user applications use select instead of threads.

it straight forward subclass t.i.serialport.serialport , overwrite _serialfactory method (which creates pyserial object used accessing serial port)

class serialport(serialport.serialport):     def _serialfactory(self, dev, *args, **kwargs):         " pyserial recommends following supporting serial urls "         try:             return serial.serial_for_url(dev)         except attributeerror:             return serial.serial(dev, *args, **kwargs) 

however, resulting object lacks file descriptor , fileno() method (used internally t.i._posixserialport) throws exception.

--- <exception caught here> ---   file "/opt/local/library/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages/twisted/internet/base.py", line 1204, in mainloop     self.doiteration(t)   file "/opt/local/library/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages/twisted/internet/selectreactor.py", line 105, in doselect     [], timeout)   file "/opt/local/library/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages/twisted/internet/_posixserialport.py", line 48, in fileno     return self._serial.fd exceptions.attributeerror: 'serial' object has no attribute 'fd' 

the current workarounds either use socat described in question, or network serial server i'm using (brainboxes es-842) can configure in "raw tcp" mode instead of "telnet/rfc2217" mode , use existing protocol on tcp connection (as long you're not depending on flow control or other serial control lines , can use predefined fixed baud rate).


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -