diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index a4f98c63d..a5f8550ae 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -108,28 +108,12 @@ def callback_disconnected(self, call_exc: Exception | None) -> None: async def inner_handle(self): """Handle handler.""" - # this is an asyncio.Queue await, it will never fail try: - data, *addr = await self.receive_queue.get() + pdu, *addr = await self.receive_queue.get() except RuntimeError: Log.error("Event loop is closed") return - - self.databuffer += data - Log.debug("Handling data: {}", self.databuffer, ":hex") - try: - used_len, pdu = self.framer.processIncomingFrame(self.databuffer) - except ModbusException: - pdu = ExceptionResponse( - 40, - exception_code=ExceptionResponse.ILLEGAL_FUNCTION - ) - self.server_send(pdu, 0) - pdu = None - used_len = len(self.databuffer) - self.databuffer = self.databuffer[used_len:] - if pdu: - self.server_execute(pdu, *addr) + self.server_execute(pdu, *addr) async def handle(self) -> None: """Coroutine which represents a single master <=> slave conversation. @@ -223,12 +207,17 @@ def server_send(self, message, addr, **kwargs): def callback_data(self, data: bytes, addr: tuple | None = ()) -> int: """Handle received data.""" try: - _used_len, _pdu = self.framer.processIncomingFrame(data) + used_len, pdu = self.framer.processIncomingFrame(data) except ModbusException: - Log.error("Framer received ModbusException.") - - self.receive_queue.put_nowait((data, addr)) - return len(data) + pdu = ExceptionResponse( + 40, + exception_code=ExceptionResponse.ILLEGAL_FUNCTION + ) + self.server_send(pdu, 0) + return len(self.databuffer) + if pdu: + self.receive_queue.put_nowait((pdu, addr)) + return used_len class ModbusBaseServer(ModbusProtocol):