Skip to content

Commit

Permalink
Use explicit ValueError when called with incorrect function code (#2089)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd2 authored Mar 7, 2024
1 parent 7c4a310 commit 07c43b5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pymodbus/datastore/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ def getValues(self, fc_as_hex, _address, _count=1):
def setValues(self, fc_as_hex, address, values):
"""Set the datastore with the supplied values."""
group_fx = self.decode(fc_as_hex)
if fc_as_hex in self._write_fc:
func_fc = self.__set_callbacks[f"{group_fx}{fc_as_hex}"]
if fc_as_hex in {0x0F, 0x10}:
self.result = func_fc(address, values)
else:
self.result = func_fc(address, values[0])
if fc_as_hex not in self._write_fc:
raise ValueError(f"setValues() called with an non-write function code {fc_as_hex}")
func_fc = self.__set_callbacks[f"{group_fx}{fc_as_hex}"]
if fc_as_hex in {0x0F, 0x10}: # Write Multiple Coils, Write Multiple Registers
self.result = func_fc(address, values)
else:
self.result = func_fc(address, values[0])
if self.result.isError():
return self.result
return None
Expand Down

0 comments on commit 07c43b5

Please sign in to comment.