diff --git a/API_changes.rst b/API_changes.rst index fbe2010a8..639cf111f 100644 --- a/API_changes.rst +++ b/API_changes.rst @@ -6,6 +6,7 @@ API changes 3.8.0 ----------------- - ModbusSlaveContext, remove zero_mode parameter. - Remove skip_encode parameter. +- rename ModbusExceptions enums to legal constants. API changes 3.7.0 diff --git a/doc/source/library/simulator/calls_response.rst b/doc/source/library/simulator/calls_response.rst index f3cb303fd..51b89ae17 100644 --- a/doc/source/library/simulator/calls_response.rst +++ b/doc/source/library/simulator/calls_response.rst @@ -116,47 +116,47 @@ "function_error": [ { "value": 1, - "text": "IllegalFunction", + "text": "ILLEGAL_FUNCTION", "selected": false }, { "value": 2, - "text": "IllegalAddress", + "text": "ILLEGAL_ADDRESS", "selected": false }, { "value": 3, - "text": "IllegalValue", + "text": "ILLEGAL_VALUE", "selected": false }, { "value": 4, - "text": "SlaveFailure", + "text": "SLAVE_FAILURE", "selected": false }, { "value": 5, - "text": "Acknowledge", + "text": "ACKNOWLEDGE", "selected": false }, { "value": 6, - "text": "SlaveBusy", + "text": "SLAVE_BUSY", "selected": false }, { "value": 7, - "text": "MemoryParityError", + "text": "MEMORY_PARITY_ERROR", "selected": false }, { "value": 10, - "text": "GatewayPathUnavailable", + "text": "GATEWAY_PATH_UNAVIABLE", "selected": false }, { "value": 11, - "text": "GatewayNoResponse", + "text": "GATEWAY_NO_RESPONSE", "selected": false } ], diff --git a/examples/client_custom_msg.py b/examples/client_custom_msg.py index c57e6aefc..4ed0b39dc 100755 --- a/examples/client_custom_msg.py +++ b/examples/client_custom_msg.py @@ -85,9 +85,9 @@ def decode(self, data): def execute(self, context): """Execute.""" if not 1 <= self.count <= 0x7D0: - return self.doException(ModbusExceptions.IllegalValue) + return self.doException(ModbusExceptions.ILLEGAL_VALUE) if not context.validate(self.function_code, self.address, self.count): - return self.doException(ModbusExceptions.IllegalAddress) + return self.doException(ModbusExceptions.ILLEGAL_ADDRESS) values = context.getValues(self.function_code, self.address, self.count) return CustomModbusPDU(values) diff --git a/pymodbus/client/mixin.py b/pymodbus/client/mixin.py index 8829c10a2..1431a88ef 100644 --- a/pymodbus/client/mixin.py +++ b/pymodbus/client/mixin.py @@ -416,7 +416,7 @@ def write_coils( def write_registers( self, address: int, - values: list[bytes] | list[int], + values: list[bytes | int], slave: int = 1, no_response_expected: bool = False ) -> T: diff --git a/pymodbus/datastore/context.py b/pymodbus/datastore/context.py index 2783705eb..4282c40e3 100644 --- a/pymodbus/datastore/context.py +++ b/pymodbus/datastore/context.py @@ -32,7 +32,7 @@ def decode(self, fx): """ return self._fx_mapper[fx] - async def async_getValues(self, fc_as_hex: int, address: int, count: int = 1) -> list[int | bool | None]: + async def async_getValues(self, fc_as_hex: int, address: int, count: int = 1) -> Sequence[int | bool]: """Get `count` values from datastore. :param fc_as_hex: The function we are working with @@ -51,7 +51,7 @@ async def async_setValues(self, fc_as_hex: int, address: int, values: Sequence[i """ self.setValues(fc_as_hex, address, values) - def getValues(self, fc_as_hex: int, address: int, count: int = 1) -> list[int | bool | None]: + def getValues(self, fc_as_hex: int, address: int, count: int = 1) -> Sequence[int | bool]: """Get `count` values from datastore. :param fc_as_hex: The function we are working with diff --git a/pymodbus/device.py b/pymodbus/device.py index 136ac0c82..7187b54ee 100644 --- a/pymodbus/device.py +++ b/pymodbus/device.py @@ -343,7 +343,7 @@ class ModbusCountersHandler: 0x10 6 Return Slave NAK Count Quantity of messages addressed to the remote device for which it - returned a Negative Acknowledge (NAK) exception response, since + returned a Negative ACKNOWLEDGE (NAK) exception response, since its last restart, clear counters operation, or power-up. Exception responses are described and listed in "MODBUS Application Protocol Specification" document. @@ -375,7 +375,7 @@ class ModbusCountersHandler: "SlaveMessage", "SlaveNoResponse", "SlaveNAK", - "SlaveBusy", + "SLAVE_BUSY", "BusCharacterOverrun", ] @@ -425,7 +425,7 @@ def summary(self): SlaveMessage = dict_property(lambda s: s.__data, 3) # pylint: disable=protected-access SlaveNoResponse = dict_property(lambda s: s.__data, 4) # pylint: disable=protected-access SlaveNAK = dict_property(lambda s: s.__data, 5) # pylint: disable=protected-access - SlaveBusy = dict_property(lambda s: s.__data, 6) # pylint: disable=protected-access + SLAVE_BUSY = dict_property(lambda s: s.__data, 6) # pylint: disable=protected-access BusCharacterOverrun = dict_property(lambda s: s.__data, 7) # pylint: disable=protected-access Event = dict_property(lambda s: s.__data, 8) # pylint: disable=protected-access # fmt: on diff --git a/pymodbus/pdu/bit_message.py b/pymodbus/pdu/bit_message.py index be971e380..a208c4a17 100644 --- a/pymodbus/pdu/bit_message.py +++ b/pymodbus/pdu/bit_message.py @@ -35,9 +35,9 @@ def get_response_pdu_size(self) -> int: async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: """Run request against a datastore.""" if not (1 <= self.count <= 0x7D0): - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not context.validate(self.function_code, self.address, self.count): - return self.doException(merror.IllegalAddress) + return self.doException(merror.ILLEGAL_ADDRESS) values = cast(list[bool], await context.async_getValues( self.function_code, self.address, self.count )) @@ -98,7 +98,7 @@ class WriteSingleCoilRequest(WriteSingleCoilResponse): async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: """Run a request against a datastore.""" if not context.validate(self.function_code, self.address, 1): - return self.doException(merror.IllegalAddress) + return self.doException(merror.ILLEGAL_ADDRESS) await context.async_setValues(self.function_code, self.address, self.bits) values = cast(list[bool], await context.async_getValues(self.function_code, self.address, 1)) @@ -136,9 +136,9 @@ async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: """Run a request against a datastore.""" count = len(self.bits) if not 1 <= count <= 0x07B0: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not context.validate(self.function_code, self.address, count): - return self.doException(merror.IllegalAddress) + return self.doException(merror.ILLEGAL_ADDRESS) await context.async_setValues( self.function_code, self.address, self.bits diff --git a/pymodbus/pdu/diag_message.py b/pymodbus/pdu/diag_message.py index 7946bc247..9723a39dc 100644 --- a/pymodbus/pdu/diag_message.py +++ b/pymodbus/pdu/diag_message.py @@ -540,7 +540,7 @@ class ReturnSlaveNAKCountRequest(DiagnosticStatusSimpleRequest): """Return slave NAK count. The response data field returns the quantity of messages addressed to the - remote device for which it returned a Negative Acknowledge (NAK) exception + remote device for which it returned a Negative ACKNOWLEDGE (NAK) exception response, since its last restart, clear counters operation, or power-up. Exception responses are described and listed in section 7 . """ @@ -560,7 +560,7 @@ class ReturnSlaveNAKCountResponse(DiagnosticStatusSimpleResponse): """Return slave NAK. The response data field returns the quantity of messages addressed to the - remote device for which it returned a Negative Acknowledge (NAK) exception + remote device for which it returned a Negative ACKNOWLEDGE (NAK) exception response, since its last restart, clear counters operation, or power-up. Exception responses are described and listed in section 7. """ @@ -583,7 +583,7 @@ async def update_datastore(self, *args): :returns: The initialized response message """ - count = _MCB.Counter.SlaveBusy + count = _MCB.Counter.SLAVE_BUSY return ReturnSlaveBusyCountResponse(count) diff --git a/pymodbus/pdu/file_message.py b/pymodbus/pdu/file_message.py index d0f7b9351..29554d31e 100644 --- a/pymodbus/pdu/file_message.py +++ b/pymodbus/pdu/file_message.py @@ -239,9 +239,9 @@ def get_response_pdu_size(self) -> int: async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """Run a read exception status request against the store.""" if not 0x0000 <= self.address <= 0xFFFF: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if len(self.values) > 31: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) return ReadFifoQueueResponse(values=self.values, slave_id=self.slave_id, transaction_id=self.transaction_id) diff --git a/pymodbus/pdu/mei_message.py b/pymodbus/pdu/mei_message.py index 3b22d3057..bd2f08af5 100644 --- a/pymodbus/pdu/mei_message.py +++ b/pymodbus/pdu/mei_message.py @@ -61,9 +61,9 @@ def decode(self, data: bytes) -> None: async def update_datastore(self, _context: ModbusSlaveContext) -> ModbusPDU: """Run a read exception status request against the store.""" if not 0x00 <= self.object_id <= 0xFF: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not 0x00 <= self.read_code <= 0x04: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) information = DeviceInformationFactory.get(_MCB, self.read_code, self.object_id) return ReadDeviceInformationResponse(read_code=self.read_code, information=information, slave_id=self.slave_id, transaction_id=self.transaction_id) diff --git a/pymodbus/pdu/pdu.py b/pymodbus/pdu/pdu.py index 4ec7f62d7..e2fcfb5a6 100644 --- a/pymodbus/pdu/pdu.py +++ b/pymodbus/pdu/pdu.py @@ -4,7 +4,9 @@ import asyncio import struct from abc import abstractmethod +from collections.abc import Sequence from enum import Enum +from typing import cast from pymodbus.exceptions import NotImplementedException from pymodbus.logging import Log @@ -19,26 +21,26 @@ class ModbusPDU: rtu_byte_count_pos: int = 0 def __init__(self, - slave_id = 0, - transaction_id = 0, - address = 0, - count = 0, - bits = None, - registers = None, - status = 1, + slave_id: int = 0, + transaction_id: int = 0, + address: int = 0, + count: int = 0, + bits: list[bool] | None = None, + registers: Sequence[int | bytes] | None = None, + status: int = 1, ) -> None: """Initialize the base data for a modbus request.""" + self.slave_id: int = slave_id + self.transaction_id: int = transaction_id + self.address: int = address + self.bits: list[bool] = bits if bits else [] if not registers: registers = [] + self.registers: list[int] = cast(list[int], registers) for i, value in enumerate(registers): if isinstance(value, bytes): - registers[i] = int.from_bytes(value, byteorder="big") - self.transaction_id: int = transaction_id - self.slave_id: int = slave_id - self.address: int = address + self.registers[i] = int.from_bytes(value, byteorder="big") self.count: int = count if count else len(registers) - self.bits: list[bool] = bits if bits else [] - self.registers: list[int] = registers if registers else [] self.status: int = status self.fut: asyncio.Future @@ -82,16 +84,16 @@ def calculateRtuFrameSize(cls, data: bytes) -> int: class ModbusExceptions(int, Enum): """An enumeration of the valid modbus exceptions.""" - IllegalFunction = 0x01 # pylint: disable=invalid-name - IllegalAddress = 0x02 # pylint: disable=invalid-name - IllegalValue = 0x03 # pylint: disable=invalid-name - SlaveFailure = 0x04 # pylint: disable=invalid-name - Acknowledge = 0x05 # pylint: disable=invalid-name - SlaveBusy = 0x06 # pylint: disable=invalid-name - NegativeAcknowledge = 0x07 # pylint: disable=invalid-name - MemoryParityError = 0x08 # pylint: disable=invalid-name - GatewayPathUnavailable = 0x0A # pylint: disable=invalid-name - GatewayNoResponse = 0x0B # pylint: disable=invalid-name + ILLEGAL_FUNCTION = 0x01 + ILLEGAL_ADDRESS = 0x02 + ILLEGAL_VALUE = 0x03 + SLAVE_FAILURE = 0x04 + ACKNOWLEDGE = 0x05 + SLAVE_BUSY = 0x06 + NEGATIVE_ACKNOWLEDGE = 0x07 + MEMORY_PARITY_ERROR = 0x08 + GATEWAY_PATH_UNAVIABLE = 0x0A + GATEWAY_NO_RESPONSE = 0x0B class ExceptionResponse(ModbusPDU): diff --git a/pymodbus/pdu/register_message.py b/pymodbus/pdu/register_message.py index c8bc96ac7..5b805496a 100644 --- a/pymodbus/pdu/register_message.py +++ b/pymodbus/pdu/register_message.py @@ -1,4 +1,6 @@ """Register Reading Request/Response.""" +from __future__ import annotations + import struct from typing import cast @@ -60,12 +62,12 @@ class ReadHoldingRegistersRequest(ReadRegistersRequestBase): async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: """Run a read holding request against a datastore.""" if not (1 <= self.count <= 0x7D): - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not context.validate(self.function_code, self.address, self.count): - return self.doException(merror.IllegalAddress) - values = await context.async_getValues( + return self.doException(merror.ILLEGAL_ADDRESS) + values = cast(list[int], await context.async_getValues( self.function_code, self.address, self.count - ) + )) return ReadHoldingRegistersResponse(registers=values, slave_id=self.slave_id, transaction_id=self.transaction_id) @@ -83,9 +85,9 @@ class ReadInputRegistersRequest(ReadRegistersRequestBase): async def update_datastore(self, context) -> ModbusPDU: """Run a read input request against a datastore.""" if not (1 <= self.count <= 0x7D): - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not context.validate(self.function_code, self.address, self.count): - return self.doException(merror.IllegalAddress) + return self.doException(merror.ILLEGAL_ADDRESS) values = await context.async_getValues( self.function_code, self.address, self.count ) @@ -151,17 +153,17 @@ def decode(self, data: bytes) -> None: async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: """Run a write single register request against a datastore.""" if not (1 <= self.read_count <= 0x07D): - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not 1 <= self.write_count <= 0x079: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if self.write_byte_count != self.write_count * 2: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not context.validate( self.function_code, self.write_address, self.write_count ): - return self.doException(merror.IllegalAddress) + return self.doException(merror.ILLEGAL_ADDRESS) if not context.validate(self.function_code, self.read_address, self.read_count): - return self.doException(merror.IllegalAddress) + return self.doException(merror.ILLEGAL_ADDRESS) await context.async_setValues( self.function_code, self.write_address, self.write_registers ) @@ -206,9 +208,9 @@ class WriteSingleRegisterRequest(WriteSingleRegisterResponse): async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: """Run a write single register request against a datastore.""" if not 0 <= self.registers[0] <= 0xFFFF: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not context.validate(self.function_code, self.address, 1): - return self.doException(merror.IllegalAddress) + return self.doException(merror.ILLEGAL_ADDRESS) await context.async_setValues( self.function_code, self.address, self.registers @@ -248,9 +250,9 @@ def decode(self, data: bytes) -> None: async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: """Run a write single register request against a datastore.""" if not 1 <= self.count <= 0x07B: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not context.validate(self.function_code, self.address, self.count): - return self.doException(merror.IllegalAddress) + return self.doException(merror.ILLEGAL_ADDRESS) await context.async_setValues( self.function_code, self.address, self.registers @@ -303,12 +305,12 @@ def decode(self, data: bytes) -> None: async def update_datastore(self, context: ModbusSlaveContext) -> ModbusPDU: """Run a mask write register request against the store.""" if not 0x0000 <= self.and_mask <= 0xFFFF: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not 0x0000 <= self.or_mask <= 0xFFFF: - return self.doException(merror.IllegalValue) + return self.doException(merror.ILLEGAL_VALUE) if not context.validate(self.function_code, self.address, 1): - return self.doException(merror.IllegalAddress) - values = cast(int, (await context.async_getValues(self.function_code, self.address, 1))[0]) + return self.doException(merror.ILLEGAL_ADDRESS) + values = (await context.async_getValues(self.function_code, self.address, 1))[0] values = (values & self.and_mask) | (self.or_mask & ~self.and_mask) await context.async_setValues( self.function_code, self.address, [values] diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index e8c507fae..48510d54d 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -127,7 +127,7 @@ async def inner_handle(self): except ModbusException: pdu = ExceptionResponse( 40, - exception_code=merror.IllegalFunction + exception_code=merror.ILLEGAL_FUNCTION ) self.server_send(pdu, 0) pdu = None @@ -198,14 +198,14 @@ async def _async_execute(self, request, *addr): Log.error("requested slave does not exist: {}", request.slave_id) if self.server.ignore_missing_slaves: return # the client will simply timeout waiting for a response - response = request.doException(merror.GatewayNoResponse) + response = request.doException(merror.GATEWAY_NO_RESPONSE) except Exception as exc: # pylint: disable=broad-except Log.error( "Datastore unable to fulfill request: {}; {}", exc, traceback.format_exc(), ) - response = request.doException(merror.SlaveFailure) + response = request.doException(merror.SLAVE_FAILURE) # no response when broadcasting if not broadcast: response.transaction_id = request.transaction_id diff --git a/pymodbus/server/simulator/http_server.py b/pymodbus/server/simulator/http_server.py index ed6371ef2..761687fc3 100644 --- a/pymodbus/server/simulator/http_server.py +++ b/pymodbus/server/simulator/http_server.py @@ -364,15 +364,15 @@ def build_html_calls(self, params: dict, html: str) -> str: function_error = "" for i, txt in ( - (1, "IllegalFunction"), - (2, "IllegalAddress"), - (3, "IllegalValue"), - (4, "SlaveFailure"), - (5, "Acknowledge"), - (6, "SlaveBusy"), - (7, "MemoryParityError"), - (10, "GatewayPathUnavailable"), - (11, "GatewayNoResponse"), + (1, "ILLEGAL_FUNCTION"), + (2, "ILLEGAL_ADDRESS"), + (3, "ILLEGAL_VALUE"), + (4, "SLAVE_FAILURE"), + (5, "ACKNOWLEDGE"), + (6, "SLAVE_BUSY"), + (7, "MEMORY_PARITY_ERROR"), + (10, "GATEWAY_PATH_UNAVIABLE"), + (11, "GATEWAY_NO_RESPONSE"), ): selected = "selected" if i == self.call_response.error_response else "" function_error += f"" @@ -526,15 +526,15 @@ def build_json_calls(self, params: dict) -> dict: function_error = [] for i, txt in ( - (1, "IllegalFunction"), - (2, "IllegalAddress"), - (3, "IllegalValue"), - (4, "SlaveFailure"), - (5, "Acknowledge"), - (6, "SlaveBusy"), - (7, "MemoryParityError"), - (10, "GatewayPathUnavailable"), - (11, "GatewayNoResponse"), + (1, "ILLEGAL_FUNCTION"), + (2, "ILLEGAL_ADDRESS"), + (3, "ILLEGAL_VALUE"), + (4, "SLAVE_FAILURE"), + (5, "ACKNOWLEDGE"), + (6, "SLAVE_BUSY"), + (7, "MEMORY_PARITY_ERROR"), + (10, "GATEWAY_PATH_UNAVIABLE"), + (11, "GATEWAY_NO_RESPONSE"), ): function_error.append({ "value": i, diff --git a/test/framer/generator.py b/test/framer/generator.py index 9c709cc51..ef1e9f2b9 100755 --- a/test/framer/generator.py +++ b/test/framer/generator.py @@ -36,7 +36,7 @@ def set_calls(): result = server.buildFrame(response) print(f" response --> {result}") print(f" response --> {result.hex()}") - exception = request.doException(merror.IllegalAddress) + exception = request.doException(merror.ILLEGAL_ADDRESS) exception.transaction_id = tid exception.slave_id = dev_id result = server.buildFrame(exception) diff --git a/test/pdu/test_bit.py b/test/pdu/test_bit.py index d47c2ef2f..444927a24 100644 --- a/test/pdu/test_bit.py +++ b/test/pdu/test_bit.py @@ -33,7 +33,7 @@ async def test_bit_read_update_datastore_value_errors(self, mock_context): (bit_msg.ReadDiscreteInputsRequest(address=1, count=0x800)), ): result = await pdu.update_datastore(context) - assert ModbusExceptions.IllegalValue == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE async def test_bit_read_update_datastore_address_errors(self, mock_context): """Test bit read request encoding.""" @@ -43,7 +43,7 @@ async def test_bit_read_update_datastore_address_errors(self, mock_context): (bit_msg.ReadDiscreteInputsRequest(address=1, count=0x800)), ): result = await pdu.update_datastore(context) - assert ModbusExceptions.IllegalValue == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE async def test_bit_read_update_datastore_success(self, mock_context): """Test bit read request encoding.""" @@ -110,7 +110,7 @@ async def test_write_single_coil_update_datastore(self, mock_context): context = mock_context(False, default=True) request = bit_msg.WriteSingleCoilRequest(address=2, bits=[True]) result = await request.update_datastore(context) - assert result.exception_code == ModbusExceptions.IllegalAddress + assert result.exception_code == ModbusExceptions.ILLEGAL_ADDRESS context.valid = True result = await request.update_datastore(context) @@ -127,13 +127,13 @@ async def test_write_multiple_coils_update_datastore(self, mock_context): # too many values request = bit_msg.WriteMultipleCoilsRequest(address=2, bits=[]) result = await request.update_datastore(context) - assert result.exception_code == ModbusExceptions.IllegalValue + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE # does not validate context.valid = False request = bit_msg.WriteMultipleCoilsRequest(address=2, bits=[False] * 4) result = await request.update_datastore(context) - assert result.exception_code == ModbusExceptions.IllegalAddress + assert result.exception_code == ModbusExceptions.ILLEGAL_ADDRESS # validated request context.valid = True diff --git a/test/pdu/test_file_message.py b/test/pdu/test_file_message.py index 84eed5383..871986e21 100644 --- a/test/pdu/test_file_message.py +++ b/test/pdu/test_file_message.py @@ -44,11 +44,11 @@ async def test_read_fifo_queue_request(self, mock_context): handle.address = -1 result = await handle.update_datastore(context) - assert ModbusExceptions.IllegalValue == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE handle.values = [0x00] * 33 result = await handle.update_datastore(context) - assert ModbusExceptions.IllegalValue == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE async def test_read_fifo_queue_request_error(self, mock_context): """Test basic bit message encoding/decoding.""" diff --git a/test/pdu/test_register_read_messages.py b/test/pdu/test_register_read_messages.py index 52f8f1e1d..97129cc49 100644 --- a/test/pdu/test_register_read_messages.py +++ b/test/pdu/test_register_read_messages.py @@ -96,7 +96,7 @@ async def test_register_read_requests_count_errors(self): ] for request in requests: result = await request.update_datastore(None) - assert ModbusExceptions.IllegalValue == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE async def test_register_read_requests_validate_errors(self, mock_context): """This tests that the register request messages. @@ -112,7 +112,7 @@ async def test_register_read_requests_validate_errors(self, mock_context): ] for request in requests: result = await request.update_datastore(context) - assert ModbusExceptions.IllegalAddress == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_ADDRESS async def test_register_read_requests_update_datastore(self, mock_context): """This tests that the register request messages. @@ -145,15 +145,15 @@ async def test_read_write_multiple_registers_validate(self, mock_context): read_address=1, read_count=10, write_address=2, write_registers=[0x00] ) response = await request.update_datastore(context) - assert response.exception_code == ModbusExceptions.IllegalAddress + assert response.exception_code == ModbusExceptions.ILLEGAL_ADDRESS context.validate = lambda f, a, c: a == 2 response = await request.update_datastore(context) - assert response.exception_code == ModbusExceptions.IllegalAddress + assert response.exception_code == ModbusExceptions.ILLEGAL_ADDRESS request.write_byte_count = 0x100 response = await request.update_datastore(context) - assert response.exception_code == ModbusExceptions.IllegalValue + assert response.exception_code == ModbusExceptions.ILLEGAL_VALUE def test_read_write_multiple_registers_request_decode(self): """Test read/write multiple registers.""" diff --git a/test/pdu/test_register_write_messages.py b/test/pdu/test_register_write_messages.py index 5475d2f9b..d54d8af1a 100644 --- a/test/pdu/test_register_write_messages.py +++ b/test/pdu/test_register_write_messages.py @@ -83,11 +83,11 @@ async def test_write_single_register_request(self, mock_context): context = mock_context() request = WriteSingleRegisterRequest(address=0x00, registers=[0xF0000]) result = await request.update_datastore(context) - assert result.exception_code == ModbusExceptions.IllegalValue + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE request.registers[0] = 0x00FF result = await request.update_datastore(context) - assert result.exception_code == ModbusExceptions.IllegalAddress + assert result.exception_code == ModbusExceptions.ILLEGAL_ADDRESS context.valid = True result = await request.update_datastore(context) @@ -98,11 +98,11 @@ async def test_write_multiple_register_request(self, mock_context): context = mock_context() request = WriteMultipleRegistersRequest(address=0x00, registers=[0x00] * 10) result = await request.update_datastore(context) - assert result.exception_code == ModbusExceptions.IllegalAddress + assert result.exception_code == ModbusExceptions.ILLEGAL_ADDRESS request.count = 0x800 # outside of range result = await request.update_datastore(context) - assert result.exception_code == ModbusExceptions.IllegalValue + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE context.valid = True request = WriteMultipleRegistersRequest(address=0x00, registers=[0x00] * 10) @@ -151,15 +151,15 @@ async def test_mask_write_register_request_invalid_update_datastore(self, mock_c context = mock_context(valid=False, default=0x0000) handle = MaskWriteRegisterRequest(0x0000, -1, 0x1010) result = await handle.update_datastore(context) - assert ModbusExceptions.IllegalValue == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE handle = MaskWriteRegisterRequest(0x0000, 0x0101, -1) result = await handle.update_datastore(context) - assert ModbusExceptions.IllegalValue == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_VALUE handle = MaskWriteRegisterRequest(0x0000, 0x0101, 0x1010) result = await handle.update_datastore(context) - assert ModbusExceptions.IllegalAddress == result.exception_code + assert result.exception_code == ModbusExceptions.ILLEGAL_ADDRESS # -----------------------------------------------------------------------# # Mask Write Register Response