Skip to content

Commit 89153e6

Browse files
committed
Fix pymodbus TCP / RTU forwarder
Getting response of WriteSingleRegister is read correctly. Problem described at <pymodbus-dev#2660>
1 parent b4cecc3 commit 89153e6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pymodbus/datastore/remote.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ def reset(self):
3333

3434
def getValues(self, fc_as_hex, _address, _count=1):
3535
"""Get values from remote device."""
36-
if fc_as_hex in self._write_fc:
37-
return [0]
38-
group_fx = self.decode(fc_as_hex)
39-
func_fc = self.__get_callbacks[group_fx]
40-
self.result = func_fc(_address, _count)
36+
if not fc_as_hex in self._write_fc:
37+
group_fx = self.decode(fc_as_hex)
38+
func_fc = self.__get_callbacks[group_fx]
39+
self.result = func_fc(_address, _count)
4140
return self.__extract_result(self.decode(fc_as_hex), self.result)
4241

4342
def setValues(self, fc_as_hex, address, values):
@@ -116,7 +115,11 @@ def __extract_result(self, fc_as_hex, result):
116115
if fc_as_hex in {"d", "c"}:
117116
return result.bits
118117
if fc_as_hex in {"h", "i"}:
119-
return result.registers
118+
if result.registers:
119+
return result.registers
120+
else:
121+
# WriteSingleRegisterResponse don't have registers value set
122+
return [result.value]
120123
else:
121124
return result
122125
return None

0 commit comments

Comments
 (0)