Merge pull request #91 from rob-smallshire/transport_is_closing
Adds an override of BaseTransport.is_closing() to SerialTransport.
diff --git a/serial/aio.py b/serial/aio.py
index 7f5df2f..76d4f18 100644
--- a/serial/aio.py
+++ b/serial/aio.py
@@ -21,6 +21,7 @@
class SerialTransport(asyncio.Transport):
def __init__(self, loop, protocol, serial_instance):
+ super().__init__()
self._loop = loop
self._protocol = protocol
self.serial = serial_instance
@@ -72,7 +73,7 @@
if self._paused:
raise RuntimeError('Already paused')
self._paused = True
- self._loop.remove_reader(self._sock_fd)
+ self._loop.remove_reader(self.serial.fd)
if self._loop.get_debug():
logging.debug("%r pauses reading", self)
@@ -82,7 +83,7 @@
self._paused = False
if self._closing:
return
- self._loop.add_reader(self._sock_fd, self._read_ready)
+ self._loop.add_reader(self.serial.fd, self._read_ready)
if self._loop.get_debug():
logging.debug("%r resumes reading", self)
@@ -100,6 +101,37 @@
transport = SerialTransport(loop, protocol, ser)
return (transport, protocol)
+
+@asyncio.coroutine
+def open_serial_connection(*,
+ loop=None,
+ limit=asyncio.streams._DEFAULT_LIMIT,
+ **kwargs):
+ """A wrapper for create_serial_connection() returning a (reader,
+ writer) pair.
+
+ The reader returned is a StreamReader instance; the writer is a
+ StreamWriter instance.
+
+ The arguments are all the usual arguments to Serial(). Additional
+ optional keyword arguments are loop (to set the event loop instance
+ to use) and limit (to set the buffer limit passed to the
+ StreamReader.
+
+ This function is a coroutine.
+ """
+ if loop is None:
+ loop = asyncio.get_event_loop()
+ reader = asyncio.StreamReader(limit=limit, loop=loop)
+ protocol = asyncio.StreamReaderProtocol(reader, loop=loop)
+ transport, _ = yield from create_serial_connection(
+ loop=loop,
+ protocol_factory=lambda: protocol,
+ **kwargs)
+ writer = asyncio.StreamWriter(transport, protocol, reader, loop)
+ return reader, writer
+
+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# test
if __name__ == '__main__':
diff --git a/serial/serialposix.py b/serial/serialposix.py
index 2dca984..70fb241 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -131,6 +131,7 @@
buf = array.array('i', [0] * 8) # flags, delaytx, delayrx, padding
try:
fcntl.ioctl(self.fd, TIOCGRS485, buf)
+ buf[0] |= SER_RS485_ENABLED
if rs485_settings is not None:
if rs485_settings.loopback:
buf[0] |= SER_RS485_RX_DURING_TX