From 559e516a96e263f4b87623a99143bd7cc3ab529b Mon Sep 17 00:00:00 2001 From: jan iversen Date: Tue, 23 Apr 2024 10:47:53 +0200 Subject: [PATCH] Datastore will not return ExceptionResponse. (#2175) --- pymodbus/pdu/bit_read_message.py | 6 +----- pymodbus/pdu/bit_write_message.py | 2 -- pymodbus/pdu/register_read_message.py | 13 ++++--------- pymodbus/pdu/register_write_message.py | 4 +--- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/pymodbus/pdu/bit_read_message.py b/pymodbus/pdu/bit_read_message.py index 9deb7009b..6796eeffc 100644 --- a/pymodbus/pdu/bit_read_message.py +++ b/pymodbus/pdu/bit_read_message.py @@ -11,8 +11,8 @@ # pylint: disable=missing-type-doc import struct -from pymodbus.pdu import ExceptionResponse, ModbusRequest, ModbusResponse from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse from pymodbus.utilities import pack_bitstring, unpack_bitstring @@ -172,8 +172,6 @@ async def execute(self, context): values = await context.async_getValues( self.function_code, self.address, self.count ) - if isinstance(values, ExceptionResponse): - return values return ReadCoilsResponse(values) @@ -242,8 +240,6 @@ async def execute(self, context): values = await context.async_getValues( self.function_code, self.address, self.count ) - if isinstance(values, ExceptionResponse): - return values return ReadDiscreteInputsResponse(values) diff --git a/pymodbus/pdu/bit_write_message.py b/pymodbus/pdu/bit_write_message.py index d9a9fb323..6c4fafa27 100644 --- a/pymodbus/pdu/bit_write_message.py +++ b/pymodbus/pdu/bit_write_message.py @@ -92,8 +92,6 @@ async def execute(self, context): await context.async_setValues(self.function_code, self.address, [self.value]) values = await context.async_getValues(self.function_code, self.address, 1) - # if isinstance(values, ExceptionResponse): - # return values return WriteSingleCoilResponse(self.address, values[0]) def get_response_pdu_size(self): diff --git a/pymodbus/pdu/register_read_message.py b/pymodbus/pdu/register_read_message.py index a6f1e3f75..9088f501e 100644 --- a/pymodbus/pdu/register_read_message.py +++ b/pymodbus/pdu/register_read_message.py @@ -13,8 +13,8 @@ # pylint: disable=missing-type-doc import struct -from pymodbus.pdu import ExceptionResponse, ModbusRequest, ModbusResponse from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse class ReadRegistersRequestBase(ModbusRequest): @@ -143,7 +143,7 @@ async def execute(self, context): """Run a read holding request against a datastore. :param context: The datastore to request from - :returns: An initialized :py:class:`~pymodbus.register_read_message.ReadHoldingRegistersResponse`, or an :py:class:`~pymodbus.pdu.ExceptionResponse` if an error occurred + :returns: An initialized :py:class:`~pymodbus.register_read_message.ReadHoldingRegistersResponse` """ if not (1 <= self.count <= 0x7D): return self.doException(merror.IllegalValue) @@ -152,9 +152,6 @@ async def execute(self, context): values = await context.async_getValues( self.function_code, self.address, self.count ) - if isinstance(values, ExceptionResponse): - return values - return ReadHoldingRegistersResponse(values) @@ -206,7 +203,7 @@ async def execute(self, context): """Run a read input request against a datastore. :param context: The datastore to request from - :returns: An initialized :py:class:`~pymodbus.register_read_message.ReadInputRegistersResponse`, or an :py:class:`~pymodbus.pdu.ExceptionResponse` if an error occurred + :returns: An initialized :py:class:`~pymodbus.register_read_message.ReadInputRegistersResponse` """ if not (1 <= self.count <= 0x7D): return self.doException(merror.IllegalValue) @@ -215,8 +212,6 @@ async def execute(self, context): values = await context.async_getValues( self.function_code, self.address, self.count ) - if isinstance(values, ExceptionResponse): - return values return ReadInputRegistersResponse(values) @@ -318,7 +313,7 @@ async def execute(self, context): """Run a write single register request against a datastore. :param context: The datastore to request from - :returns: An initialized :py:class:`~pymodbus.register_read_message.ReadWriteMultipleRegistersResponse`, or an :py:class:`~pymodbus.pdu.ExceptionResponse` if an error occurred + :returns: An initialized :py:class:`~pymodbus.register_read_message.ReadWriteMultipleRegistersResponse` """ if not (1 <= self.read_count <= 0x07D): return self.doException(merror.IllegalValue) diff --git a/pymodbus/pdu/register_write_message.py b/pymodbus/pdu/register_write_message.py index eca9035a2..753c2ce62 100644 --- a/pymodbus/pdu/register_write_message.py +++ b/pymodbus/pdu/register_write_message.py @@ -12,8 +12,8 @@ # pylint: disable=missing-type-doc import struct -from pymodbus.pdu import ExceptionResponse, ModbusRequest, ModbusResponse from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse class WriteSingleRegisterRequest(ModbusRequest): @@ -334,8 +334,6 @@ async def execute(self, context): if not context.validate(self.function_code, self.address, 1): return self.doException(merror.IllegalAddress) values = (await context.async_getValues(self.function_code, self.address, 1))[0] - if isinstance(values, ExceptionResponse): - return values values = (values & self.and_mask) | (self.or_mask & ~self.and_mask) await context.async_setValues( self.function_code, self.address, [values]