File tree Expand file tree Collapse file tree 1 file changed +15
-12
lines changed
pymodbus/client/serial_asyncio Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -422,20 +422,23 @@ def _call_connection_lost(self, exc):
422422 assert self ._closing
423423 assert not self ._has_writer
424424 assert not self ._has_reader
425- try :
426- self ._serial .flush ()
427- except (serial .SerialException if os .name == "nt" else termios .error ):
428- # ignore serial errors which may happen if the serial device was
429- # hot-unplugged.
430- pass
431- try :
432- self ._protocol .connection_lost (exc )
433- finally :
434- self ._write_buffer .clear ()
425+ if self ._serial :
426+ try :
427+ self ._serial .flush ()
428+ except (serial .SerialException if os .name == "nt" else termios .error ):
429+ # ignore serial errors which may happen if the serial device was
430+ # hot-unplugged.
431+ pass
435432 self ._serial .close ()
436433 self ._serial = None
437- self ._protocol = None
438- self ._loop = None
434+ if self ._protocol :
435+ try :
436+ self ._protocol .connection_lost (exc )
437+ except :
438+ pass
439+ self ._write_buffer .clear ()
440+ self ._write_buffer .clear ()
441+ self ._loop = None
439442
440443
441444async def create_serial_connection (loop , protocol_factory , * args , ** kwargs ):
You can’t perform that action at this time.
0 commit comments