pymodbus-dev / pymodbus

A full modbus protocol written in python
Other
2.25k stars 921 forks source link

Use explicit ValueError when called with incorrect function code #2089

Closed alexrudd2 closed 6 months ago

alexrudd2 commented 6 months ago

See https://github.com/pymodbus-dev/pymodbus/pull/1599 for background.

The current code has a check if fc_as_hex in self._write_fc:. If this check fails, it means the function was called with a Modbus function code which isn't a write.

This will never happen normally. If there is bad calling code, a confusing NameError is thrown because self.result is undefined.

This PR makes the check explicit (and solves another mypy error). An alternative is to simply delete the check.