[Twisted-Python] Reconnection to Serialport after connectionLost

I have written several daemons that listen to the serialport. Everything works well, however the serial port connections are actually USB connections over IP (using an USB network hub). This means the connection is lost once in a while which is detected and triggers the connectionLost method of the protocol. I tried numerous things to reconnect to the serial port but without success. When I reconnect to the serial port I doubt what to do with the reactor parameter, when I specify the current reactor, I am able to reconnect to the serial port, the connectionMade method of the protocol is triggered, but it will never trigger dataReceived although I know data is arriving. Does any body have a glue how you can reconnect to the serial port within a running reactor loop?
--
Rene

Have you tried ReconnectingClientFactory?
http://twistedmatrix.com/documents/current/api/twisted.internet.protocol.Rec...
(Also, could you pastebin some code? What you're describing ought to work.)

I will put some code on pastebin when I come home this evening. The Clientfactory class does not support serial port communication, does it?
-- Rene ________________________________ Van: twisted-python-bounces@twistedmatrix.com [twisted-python-bounces@twistedmatrix.com] namens Laurens Van Houtven [_@lvh.cc] Verzonden: maandag 1 augustus 2011 1:37 Aan: Twisted general discussion Onderwerp: Re: [Twisted-Python] Reconnection to Serialport after connectionLost
Have you tried ReconnectingClientFactory?
http://twistedmatrix.com/documents/current/api/twisted.internet.protocol.Rec...
(Also, could you pastebin some code? What you're describing ought to work.)
-- cheers lvh

Last I looked at this I had problems with the disconnection events not being propagated properly. I did, however, end up being able to write a system that would connect, disconnect and reconnect to usb serial devices that went away and came back again. So I'm sure it's possible.
Can't access that code anymore, sorry.
Stephen.

When I tried this more than a year ago (Twisted 10.x), the connectionLost event was not indeed propagated correctly. However, in version 11 the event is propagated correctly.
-- Rene ________________________________________ Van: twisted-python-bounces@twistedmatrix.com [twisted-python-bounces@twistedmatrix.com] namens Thorne, Stephen [stephen@thorne.id.au] Verzonden: maandag 1 augustus 2011 14:12 Aan: Twisted general discussion Onderwerp: Re: [Twisted-Python] Reconnection to Serialport after connectionLost
Last I looked at this I had problems with the disconnection events not being propagated properly. I did, however, end up being able to write a system that would connect, disconnect and reconnect to usb serial devices that went away and came back again. So I'm sure it's possible.
Can't access that code anymore, sorry.
Stephen.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

On Mon, Aug 1, 2011 at 13:21, Rene Klootwijk (klootwijk.org) rene@klootwijk.org wrote:
When I tried this more than a year ago (Twisted 10.x), the connectionLost event was not indeed propagated correctly. However, in version 11 the event is propagated correctly.
Ah, good to hear. Thanks
Stephen.

I have copied a code snippit to pastebin, http://pastebin.com/us4vL0bk http://pastebin.com/us4vL0bk
This is what happens:
When I break the connection, the connectionLost event is triggered and the connectionLost method of the protocol class is called. After a 5 second delay the serialport is reopened successfully because I reconnected the device. The connectionMade event is triggered and the connectionMade method of the protocol class is called. However, data arriving on the serial port no longer triggers the dataReceived event.
--
Rene
From: twisted-python-bounces@twistedmatrix.com [mailto:twisted-python-bounces@twistedmatrix.com] On Behalf Of Laurens Van Houtven Sent: maandag 1 augustus 2011 1:37 To: Twisted general discussion Subject: Re: [Twisted-Python] Reconnection to Serialport after connectionLost
Have you tried ReconnectingClientFactory?
http://twistedmatrix.com/documents/current/api/twisted.internet.protocol.Rec onnectingClientFactory.html
(Also, could you pastebin some code? What you're describing ought to work.)

I figured it out! I forget to set the speed of the serial port. Dumb , dumber, dumbest.
From: twisted-python-bounces@twistedmatrix.com [mailto:twisted-python-bounces@twistedmatrix.com] On Behalf Of Rene Klootwijk Sent: maandag 1 augustus 2011 18:21 To: 'Twisted general discussion' Subject: Re: [Twisted-Python] Reconnection to Serialport after connectionLost
I have copied a code snippit to pastebin, http://pastebin.com/us4vL0bk http://pastebin.com/us4vL0bk
This is what happens:
When I break the connection, the connectionLost event is triggered and the connectionLost method of the protocol class is called. After a 5 second delay the serialport is reopened successfully because I reconnected the device. The connectionMade event is triggered and the connectionMade method of the protocol class is called. However, data arriving on the serial port no longer triggers the dataReceived event.
--
Rene
From: twisted-python-bounces@twistedmatrix.com [mailto:twisted-python-bounces@twistedmatrix.com] On Behalf Of Laurens Van Houtven Sent: maandag 1 augustus 2011 1:37 To: Twisted general discussion Subject: Re: [Twisted-Python] Reconnection to Serialport after connectionLost
Have you tried ReconnectingClientFactory?
http://twistedmatrix.com/documents/current/api/twisted.internet.protocol.Rec onnectingClientFactory.html
(Also, could you pastebin some code? What you're describing ought to work.)
participants (6)
-
exarkun@twistedmatrix.com
-
Itamar Turner-Trauring
-
Laurens Van Houtven
-
Rene Klootwijk
-
Rene Klootwijk (klootwijk.org)
-
Thorne, Stephen