Closed looninho closed 1 year ago
your code looks OK, you probably have another error hidden in the log, the problem is that AsyncModbusSerialClient could not create a transport (self._serial). And it seems you had connection but lost it.
Your log output is scrambled, you cannot call pymodbus_apply_logging_config, with the text string.
You need to a activate a proper debug log (as the issue asked you to do, when you created it). Without the proper debug log, I cannot tell you more.
Thank you @janiversen,
I test with this very simple code and it works for one time, the next call will return RuntimeError: Event loop is closed
.
import asyncio
from pymodbus.client import AsyncModbusSerialClient
from pymodbus.framer.rtu_framer import ModbusRtuFramer
from pymodbus.pdu import ExceptionResponse
async def test (client):
await client.connect()
rr = await client.read_holding_registers(0,8,slave=1)
return rr
client=AsyncModbusSerialClient(
port="COM7", # /dev/ttyUSB0
framer=ModbusRtuFramer,
baudrate=115200,
bytesize=8,
parity="O",
stopbits=1,
strict=False
)
asyncio.run(test(client), debug=True)
So I comment the line await client.close()
in run_async_client()
and it works too.
BTW, what must I do to recall asyncio.run()
without RuntimeError
?
Versions
Pymodbus Specific
Description
I'm able to make communication in serial sync client mode but not in async mode. Please help me what I was missing.
Code and Logs