From 98fc4777f44c71a5a1a7ee6608f2a8a5c63847c4 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Wed, 3 Apr 2024 09:51:29 +0200 Subject: [PATCH] Clean datastore setValues. (#2145) --- pymodbus/bit_write_message.py | 11 ++++++----- pymodbus/datastore/remote.py | 5 ++--- pymodbus/datastore/simulator.py | 4 +++- test/test_remote_datastore.py | 7 ++++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pymodbus/bit_write_message.py b/pymodbus/bit_write_message.py index 7e634f204..0af65992d 100644 --- a/pymodbus/bit_write_message.py +++ b/pymodbus/bit_write_message.py @@ -90,12 +90,13 @@ def execute(self, context): if not context.validate(self.function_code, self.address, 1): return self.doException(merror.IllegalAddress) - result = context.setValues(self.function_code, self.address, [self.value]) - if isinstance(result, ExceptionResponse): - return result + context.setValues(self.function_code, self.address, [self.value]) + # result = context.setValues(self.function_code, self.address, [self.value]) + # if isinstance(result, ExceptionResponse): + # return result values = context.getValues(self.function_code, self.address, 1) - if isinstance(values, ExceptionResponse): - return values + # if isinstance(values, ExceptionResponse): + # return values return WriteSingleCoilResponse(self.address, values[0]) def get_response_pdu_size(self): diff --git a/pymodbus/datastore/remote.py b/pymodbus/datastore/remote.py index 2ae76409b..919da6c50 100644 --- a/pymodbus/datastore/remote.py +++ b/pymodbus/datastore/remote.py @@ -57,9 +57,8 @@ def setValues(self, fc_as_hex, address, values): self.result = func_fc(address, values) else: self.result = func_fc(address, values[0]) - if self.result.isError(): - return self.result - return None + # if self.result.isError(): + # return self.result def __str__(self): """Return a string representation of the context. diff --git a/pymodbus/datastore/simulator.py b/pymodbus/datastore/simulator.py index ee11b5198..05235a155 100644 --- a/pymodbus/datastore/simulator.py +++ b/pymodbus/datastore/simulator.py @@ -7,6 +7,8 @@ from datetime import datetime from typing import Any, Callable +from pymodbus.datastore.context import ModbusBaseSlaveContext + WORD_SIZE = 16 @@ -370,7 +372,7 @@ def setup(self, config, custom_actions) -> None: raise RuntimeError(f"INVALID key in setup: {self.config}") -class ModbusSimulatorContext: +class ModbusSimulatorContext(ModbusBaseSlaveContext): """Modbus simulator. :param config: A dict with structure as shown below. diff --git a/test/test_remote_datastore.py b/test/test_remote_datastore.py index d9ab9d247..1f59c62b8 100644 --- a/test/test_remote_datastore.py +++ b/test/test_remote_datastore.py @@ -29,9 +29,10 @@ def test_remote_slave_set_values(self): context = RemoteSlaveContext(client) context.setValues(0x0F, 0, [1]) - result = context.setValues(0x10, 1, [1]) - assert result.exception_code == 0x02 - assert result.function_code == 0x90 + # result = context.setValues(0x10, 1, [1]) + context.setValues(0x10, 1, [1]) + # assert result.exception_code == 0x02 + # assert result.function_code == 0x90 def test_remote_slave_get_values(self): """Test getting values from a remote slave context."""