Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions pymodbus/server/requesthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,18 @@ def handle_later(self):

async def handle_request(self):
"""Handle request."""
broadcast = False
if not self.last_pdu:
return
try:
if self.server.broadcast_enable and not self.last_pdu.dev_id:
broadcast = True
# if broadcasting then execute on all device contexts,
# note response will be ignored
for dev_id in self.server.context.device_id():
response = await self.last_pdu.update_datastore(self.server.context[dev_id])
else:
context = self.server.context[self.last_pdu.dev_id]
response = await self.last_pdu.update_datastore(context)
await self.last_pdu.update_datastore(self.server.context[dev_id])
return
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broadcast mode returns here without responses


context = self.server.context[self.last_pdu.dev_id]
response = await self.last_pdu.update_datastore(context)

except NoSuchIdException:
Log.error("requested device id does not exist: {}", self.last_pdu.dev_id)
Expand All @@ -112,11 +111,9 @@ async def handle_request(self):
traceback.format_exc(),
)
response = ExceptionResponse(self.last_pdu.function_code, ExceptionResponse.DEVICE_FAILURE)
# no response when broadcasting
if not broadcast:
response.transaction_id = self.last_pdu.transaction_id
response.dev_id = self.last_pdu.dev_id
self.server_send(response, self.last_addr)
response.transaction_id = self.last_pdu.transaction_id
response.dev_id = self.last_pdu.dev_id
self.server_send(response, self.last_addr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm seems to me this change will send a response if we are in broadcast mode, that is not allowed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is an early return in broadcast mode and this code will never execute.


def server_send(self, pdu, addr):
"""Send message."""
Expand Down