Modbus exception-injection profile — wire-level coverage for codes 0x01/0x03/0x04/0x05/0x06/0x0A/0x0B #174
Reference in New Issue
Block a user
Delete Branch "modbus-exception-injection-profile"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes the integration-side gap for the driver's Modbus-exception → OPC UA StatusCode mapping. pymodbus's simulator naturally emits only codes 0x02 + 0x03; unit tests lock the translation function; integration coverage was previously just one case (DL205 profile @ unmapped register). This PR adds wire-level coverage for the remaining seven codes without depending on device-specific quirks.
What lands
Docker/exception_injector.py— standalone pure-stdlib Modbus/TCP server (~200 lines). Speaks the wire protocol directly (FC 01/02/03/04/05/06/15/16), dispatches on (fc, address), and responds with[fc | 0x80, exception_code]on matching rules.Docker/profiles/exception_injection.json— rules for every exception code on FC03 (1000-1007), FC06 (2000-2001), FC16 (3000).Docker/docker-compose.yml— newexception_injectioncompose profile binds:5020and runs the injector.Dockerfile— COPY'sexception_injector.pyinto the existing pymodbus image (no new pip install).ExceptionInjectionTests.cs— 11 tests: eight FC03-read theories (one per exception code), two FC06-write theories (0x04 + 0x06), one sanity-check non-injected read.Test baselines
MODBUS_SIM_PROFILEmismatchDocs
Docker/README.md§Exception injection — explains what pymodbus can and can't emit, what the injector does, where the rules live, how to append new ones.docs/drivers/Modbus-Test-Fixture.md— follow-up #2 strikethrough (shipped); unit-level section addsExceptionInjectionTestsnext toDL205ExceptionCodeTestsso the split is explicit.Extending the coverage
Append-only: add a
{fc, address, exception, description}entry to the JSON, restart the service, add an[InlineData]row inExceptionInjectionTests.