Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asyncio serial client not passing in all serial parameters, may help with sync issues #486

Closed
gbrucepayne opened this issue Jan 5, 2020 · 1 comment
Labels

Comments

@gbrucepayne
Copy link

Versions

  • Python: 3.6.9
  • OS: Linux Mint 19.3
  • Pymodbus: 2.3.0
  • Modbus Hardware (if used): SCADAPack 100 (Schneider Electric)

Pymodbus Specific

  • Client: rtu - async - asyncio

Description

I see frequent framing errors where the client is not waiting for the response to complete, dropping bytes that cause the CRC to fail. I tried to add 'timeout' parameter but it threw an unexpected keyword error. Digging through the source I see that AsyncioModbusSerialClient init does not include several of the serial parameters including timeout, write_timeout, inter_byte_timeout and flow control options. Those could all be passed through which may help with sync issues.
May overlap other sync related issues.

Code and Logs

Function missing **kwargs for additional serial configuration

 class AsyncioModbusSerialClient(object):
    """
    Client to connect to modbus device over serial.
    """
    transport = None
    framer = 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
        :param protocol_class: Protocol used to talk to modbus device.
        :param framer: Framer to use
        :param loop: Asyncio Event loop
        """
        #: Protocol used to talk to modbus device.
        self.protocol_class = protocol_class or ModbusClientProtocol
        #: Current protocol instance.
        self.protocol = 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_event = asyncio.Event()

Success example followed by Failed example (happens intermittent)

2020-01-05T22:46:41.332Z,[DEBUG],(MainThread),selector_events.__init__:54,Using selector: EpollSelector
2020-01-05T22:46:41.348Z,[DEBUG],(MainThread),__init__.connect:716,Connecting.
2020-01-05T22:46:41.353Z,[DEBUG],(MainThread),__init__._connectionMade:94,Client connected to modbus server
2020-01-05T22:46:41.354Z,[INFO],(MainThread),__init__.protocol_made_connection:733,Protocol made connection.
2020-01-05T22:46:41.356Z,[INFO],(MainThread),__init__.connect:725,Connected to /dev/ttyUSB0
2020-01-05T22:46:41.358Z,[DEBUG],(MainThread),modbusproxy.start_async_test:253,Write to a Coil and read back
2020-01-05T22:46:41.360Z,[DEBUG],(MainThread),__init__.execute:128,send: 0x1 0x5 0x0 0x0 0xff 0x0 0x8c 0x3a
2020-01-05T22:46:41.362Z,[DEBUG],(MainThread),transaction.addTransaction:383,Adding transaction 1
2020-01-05T22:46:41.399Z,[DEBUG],(MainThread),__init__._dataReceived:137,recv: 0x1 0x5 0x0 0x0 0xff 0x0 0x8c 0x3a
2020-01-05T22:46:41.402Z,[DEBUG],(MainThread),rtu_framer.getFrame:180,Getting Frame - 0x5 0x0 0x0 0xff 0x0
2020-01-05T22:46:41.403Z,[DEBUG],(MainThread),factory._helper:266,Factory Response[WriteSingleCoilResponse: 5]
2020-01-05T22:46:41.405Z,[DEBUG],(MainThread),rtu_framer.advanceFrame:115,Frame advanced, resetting header!!
2020-01-05T22:46:41.406Z,[DEBUG],(MainThread),transaction.getTransaction:394,Getting transaction 1
2020-01-05T22:46:41.408Z,[DEBUG],(MainThread),__init__.execute:128,send: 0x1 0x1 0x0 0x0 0x0 0xa 0xbc 0xd
2020-01-05T22:46:41.410Z,[DEBUG],(MainThread),transaction.addTransaction:383,Adding transaction 1
2020-01-05T22:46:41.446Z,[DEBUG],(MainThread),__init__._dataReceived:137,recv: 0x1 0x1 0x2 0xa7 0x1 0x2 0xc
2020-01-05T22:46:41.448Z,[DEBUG],(MainThread),rtu_framer.getFrame:180,Getting Frame - 0x1 0x2 0xa7 0x1
2020-01-05T22:46:41.449Z,[DEBUG],(MainThread),factory._helper:266,Factory Response[ReadCoilsResponse: 1]
2020-01-05T22:46:41.450Z,[DEBUG],(MainThread),rtu_framer.advanceFrame:115,Frame advanced, resetting header!!
2020-01-05T22:46:41.451Z,[DEBUG],(MainThread),transaction.getTransaction:394,Getting transaction 1
2020-01-05T22:46:41.452Z,[INFO],(MainThread),modbusproxy.start_async_test:258,read bits ReadBitResponse(16)

*** FAILURE LOG ***

2020-01-05T22:46:59.222Z,[DEBUG],(MainThread),selector_events.__init__:54,Using selector: EpollSelector
2020-01-05T22:46:59.234Z,[DEBUG],(MainThread),__init__.connect:716,Connecting.
2020-01-05T22:46:59.240Z,[DEBUG],(MainThread),__init__._connectionMade:94,Client connected to modbus server
2020-01-05T22:46:59.242Z,[INFO],(MainThread),__init__.protocol_made_connection:733,Protocol made connection.
2020-01-05T22:46:59.245Z,[INFO],(MainThread),__init__.connect:725,Connected to /dev/ttyUSB0
2020-01-05T22:46:59.247Z,[DEBUG],(MainThread),modbusproxy.start_async_test:253,Write to a Coil and read back
2020-01-05T22:46:59.249Z,[DEBUG],(MainThread),__init__.execute:128,send: 0x1 0x5 0x0 0x0 0xff 0x0 0x8c 0x3a
2020-01-05T22:46:59.251Z,[DEBUG],(MainThread),transaction.addTransaction:383,Adding transaction 1
2020-01-05T22:46:59.285Z,[DEBUG],(MainThread),__init__._dataReceived:137,recv: 0x1 0x5 0x0 0x0 0xff 0x0 0x8c 0x3a
2020-01-05T22:46:59.287Z,[DEBUG],(MainThread),rtu_framer.getFrame:180,Getting Frame - 0x5 0x0 0x0 0xff 0x0
2020-01-05T22:46:59.288Z,[DEBUG],(MainThread),factory._helper:266,Factory Response[WriteSingleCoilResponse: 5]
2020-01-05T22:46:59.290Z,[DEBUG],(MainThread),rtu_framer.advanceFrame:115,Frame advanced, resetting header!!
2020-01-05T22:46:59.291Z,[DEBUG],(MainThread),transaction.getTransaction:394,Getting transaction 1
2020-01-05T22:46:59.292Z,[DEBUG],(MainThread),__init__.execute:128,send: 0x1 0x1 0x0 0x0 0x0 0xa 0xbc 0xd
2020-01-05T22:46:59.294Z,[DEBUG],(MainThread),transaction.addTransaction:383,Adding transaction 1
2020-01-05T22:46:59.317Z,[DEBUG],(MainThread),__init__._dataReceived:137,recv: 0x1 0x1 0x2 0xa7
2020-01-05T22:46:59.318Z,[DEBUG],(MainThread),rtu_framer.processIncomingPacket:232,Frame check failed, ignoring!!
2020-01-05T22:46:59.319Z,[DEBUG],(MainThread),rtu_framer.resetFrame:128,Resetting frame - Current Frame in buffer - 0x1 0x1 0x2 0xa7
2020-01-05T22:46:59.333Z,[DEBUG],(MainThread),__init__._dataReceived:137,recv: 0x1 0x2 0xc
2020-01-05T22:46:59.335Z,[DEBUG],(MainThread),rtu_framer.processIncomingPacket:232,Frame check failed, ignoring!!
2020-01-05T22:46:59.336Z,[DEBUG],(MainThread),rtu_framer.resetFrame:128,Resetting frame - Current Frame in buffer - 0x1 0x2 0xc
@dhoomakethu dhoomakethu added the Bug label Jan 6, 2020
dhoomakethu added a commit that referenced this issue Jul 3, 2020
2. Fix examples
3. Fix #494 - handle_local_echo
4. Fix #500 -- asyncio serial client with already running loop
5. Fix #486 - Pass serial args for asyncio serial client
6. Fix #490 - Typo in decode_data for socker_framer
7. Fix #385 - Support timeouts to break out of responspe await when server goes offline
8. Misc updates
@dhoomakethu
Copy link
Contributor

@dhoomakethu dhoomakethu modified the milestones: 2.4.0, 3.0.0 Jul 3, 2020
dhoomakethu added a commit that referenced this issue Aug 1, 2020
* Closes  #491

* 1. update requirements
2. Fix examples
3. Fix #494 - handle_local_echo
4. Fix #500 -- asyncio serial client with already running loop
5. Fix #486 - Pass serial args for asyncio serial client
6. Fix #490 - Typo in decode_data for socker_framer
7. Fix #385 - Support timeouts to break out of responspe await when server goes offline
8. Misc updates

* #516 custom data block fix
dhoomakethu added a commit that referenced this issue Sep 11, 2020
* 1. update requirements
2. Fix examples
3. Fix #494 - handle_local_echo
4. Fix #500 -- asyncio serial client with already running loop
5. Fix #486 - Pass serial args for asyncio serial client
6. Fix #490 - Typo in decode_data for socker_framer
7. Fix #385 - Support timeouts to break out of responspe await when server goes offline
8. Misc updates

* #516 custom data block fix

* Fix broadcast error  with REPL client #515

* Fix #509 Wrong unit ID referenced in framers

* Update documentation for serial forwarder example. Fixes #525

* Fix unit tests, support python 3.8 for tests, renamed:    pymodbus/server/asyncio.py -> pymodbus/server/async_io.py and pymodbus/client/asynchronous/asyncio -> pymodbus/client/asynchronous/async_io

* Ignore python3 code syntax while reporting coverage

* Fix tests failing on python 3.6 and osx

* Fix typo in makefile

* Fix test execution errors specific to python3.6

* Osx travis issue - Fix trial 1

* Travis reverting xcode to 8.x for mac osx
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants