Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions pymodbus/client/async/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ class AsyncioModbusSerialClient(object):
transport = None
framer = None

def __init__(self, port, protocol_class=None, framer=None, loop=None):
def __init__(self, port, protocol_class=None, framer=None, loop=None,
baudrate=9600, bytesize=8, parity='N', stopbits=1):
"""
Initializes Asyncio Modbus Serial Client
:param port: Port to connect
Expand All @@ -674,6 +675,10 @@ def __init__(self, port, protocol_class=None, framer=None, loop=None):
#: Event loop to use.
self.loop = loop or asyncio.get_event_loop()
self.port = port
self.baudrate = baudrate
self.bytesize = bytesize
self.parity = parity
self.stopbits = stopbits
self.framer = framer
self._connected = False

Expand All @@ -687,18 +692,6 @@ def stop(self):
if self.protocol.transport:
self.protocol.transport.close()

def _create_protocol(self):
"""
Factory function to create initialized protocol instance.
"""
from serial_asyncio import create_serial_connection

def factory():
return self.protocol_class(framer=self.framer)

cor = create_serial_connection(self.loop, factory, self.port)
return cor

@asyncio.coroutine
def connect(self):
"""
Expand All @@ -707,11 +700,18 @@ def connect(self):
"""
_logger.debug('Connecting.')
try:
yield from self.loop.create_connection(self._create_protocol)
_logger.info('Connected to %s:%s.' % (self.host, self.port))
from serial_asyncio import create_serial_connection
Copy link
Contributor

@dhoomakethu dhoomakethu Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I updated the pull request.


def factory():
return self.protocol_class(framer=self.framer)

yield from create_serial_connection(
self.loop, factory, self.port, baudrate=self.baudrate,
bytesize=self.bytesize, stopbits=self.stopbits
)
_logger.info('Connected to %s', self.port)
except Exception as ex:
_logger.warning('Failed to connect: %s' % ex)
# asyncio.async(self._reconnect(), loop=self.loop)
_logger.warning('Failed to connect: %s', ex)

def protocol_made_connection(self, protocol):
"""
Expand Down