Skip to content

Commit

Permalink
Datastore will not return ExceptionResponse. (#2175)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Apr 23, 2024
1 parent bf3b21e commit 559e516
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
6 changes: 1 addition & 5 deletions pymodbus/pdu/bit_read_message.py
Expand Up @@ -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


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down
2 changes: 0 additions & 2 deletions pymodbus/pdu/bit_write_message.py
Expand Up @@ -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):
Expand Down
13 changes: 4 additions & 9 deletions pymodbus/pdu/register_read_message.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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)


Expand Down Expand Up @@ -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)
Expand All @@ -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)


Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions pymodbus/pdu/register_write_message.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 559e516

Please sign in to comment.