Skip to content

Commit

Permalink
temp ??.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Nov 25, 2024
1 parent bb46154 commit 4881e2b
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions pymodbus/server/async_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4881e2b

Please sign in to comment.