Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions pymodbus/pdu/decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def lookupPduClass(self, data: bytes) -> type[ModbusPDU] | None:
return self.sub_lookup[func_code].get(sub_func_code, None)
return self.lookup.get(func_code, None)

def list_function_codes(self):
"""Return list of function codes."""
return list(self.lookup)

@classmethod
def add_pdu(cls, req: type[ModbusPDU], resp: type[ModbusPDU]):
"""Register request/response."""
Expand Down
13 changes: 5 additions & 8 deletions pymodbus/server/simulator/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CallTypeResponse:
clear_after: int = 1


class ModbusSimulatorServer: # pylint: disable=too-many-instance-attributes
class ModbusSimulatorServer:
"""**ModbusSimulatorServer**.

:param modbus_server: Server name in json file (default: "server")
Expand Down Expand Up @@ -201,7 +201,6 @@ def __init__(
self.refresh_rate = 0
self.register_filter: list[int] = []
self.call_list: list[CallTracer] = []
self.request_lookup = DecodePDU(True).lookup
self.call_monitor = CallTypeMonitor()
self.call_response = CallTypeResponse()
app_key = getattr(web, 'AppKey', str) # fall back to str for aiohttp < 3.9.0
Expand Down Expand Up @@ -376,7 +375,7 @@ def build_html_calls(self, params: dict, html: str) -> str:
else ""
)
function_codes = ""
for function in self.request_lookup.values():
for function in DecodePDU(True).list_function_codes():
selected = (
"selected"
if function.function_code == self.call_monitor.function
Expand All @@ -392,9 +391,7 @@ def build_html_calls(self, params: dict, html: str) -> str:
del self.call_list[0]
call_rows = ""
for entry in reversed(self.call_list):
# req_obj = self.request_lookup[entry[1]]
call_rows += f"<tr><td>{entry.call} - {entry.fc}</td><td>{entry.address}</td><td>{entry.count}</td><td>{entry.data.decode()}</td></tr>"
# line += req_obj.funcion_code_name
new_html = (
html.replace("<!--SIMULATION_ACTIVE-->", simulation_action)
.replace("FUNCTION_RANGE_START", range_start_html)
Expand Down Expand Up @@ -543,11 +540,11 @@ def build_json_calls(self, params: dict) -> dict:
)

function_codes = []
for function in self.request_lookup.values():
for function in DecodePDU(True).list_function_codes():
function_codes.append({
"value": function.function_code,
"value": function,
"text": "function code name",
"selected": function.function_code == self.call_monitor.function
"selected": function == self.call_monitor.function
})

simulation_action = "ACTIVE" if self.call_response.active != RESPONSE_INACTIVE else ""
Expand Down