StartAsyncSerialServer doesn't work pymodbus version 3.2??? #1433
-
Before I create a bug ticket, I thought I better ask the community about this one 'cause maybe I'm just doing something reeeeeal dumb? DetailsRunning python natively on Windows; no WSL/docker/etc.... From my poetry lock file, here are the exact details of the version of pymodbus I'm using:
Sanity Codeimport asyncio
import logging
from pymodbus.framer.rtu_framer import ModbusRtuFramer
from pymodbus.server import StartAsyncSerialServer
logging.basicConfig(
format="[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S %z",
level=logging.INFO,
)
log = logging.getLogger(__name__)
async def modbus_slave():
return await StartAsyncSerialServer(
framer=ModbusRtuFramer,
port="COM10",
baudrate=19200,
)
def sanity():
log.info(f"✅ Here I am!")
asyncio.run(modbus_slave())
log.info(f"❌ I'm going insane!") Per the example documentation I would expect to only see my first log statement and for the server to be up and running indefinitely until I send a keyboard interrupt. However, that's not the case and I see the following output when running the above code, which exits immediately after making the logs:
Working Monkey PatchIf I make the following monkey patch everything works as expected: async def StartAsyncSerialServer( # pylint: disable=invalid-name,dangerous-default-value
context=None,
identity=None,
custom_functions=[],
**kwargs,
): # pragma: no cover
"""Start and run a serial modbus server.
:param context: The ModbusServerContext datastore
:param identity: An optional identify structure
:param custom_functions: An optional list of custom function classes
supported by server instance.
:param kwargs: The rest
"""
server = ModbusSerialServer(
context, kwargs.pop("framer", ModbusAsciiFramer), identity=identity, **kwargs
)
await server.start() # <----------------------Adding this makes it work 🤔
await _serverList.run(server, custom_functions) My questions
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Seems you identified a problem, feel free to make a pull request. I am not sure when/why the start call decided to drop out. |
Beta Was this translation helpful? Give feedback.
-
Issue created: #1434 |
Beta Was this translation helpful? Give feedback.
Seems you identified a problem, feel free to make a pull request.
I am not sure when/why the start call decided to drop out.