Skip to content

Commit 552ad76

Browse files
author
bobfox
authored
Merge pull request #63 from sunspec/development
Updated data conversion error detail #62
2 parents bac4acf + 3cb5a3a commit 552ad76

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

sunspec2/modbus/client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class SunSpecModbusClientError(Exception):
3636
pass
3737

3838

39+
class SunSpecModbusValueError(Exception):
40+
pass
41+
42+
3943
class SunSpecModbusClientTimeout(SunSpecModbusClientError):
4044
pass
4145

@@ -52,8 +56,11 @@ def read(self):
5256

5357
def write(self):
5458
"""Write the point to the physical device"""
55-
56-
data = self.info.to_data(self.value, int(self.len) * 2)
59+
try:
60+
data = self.info.to_data(self.value, int(self.len) * 2)
61+
except Exception as e:
62+
raise SunSpecModbusValueError('Point value error for %s %s: %s' % (self.pdef.get(mdef.NAME), self.value,
63+
str(e)))
5764
model_addr = self.model.model_addr
5865
point_offset = self.offset
5966
addr = model_addr + point_offset
@@ -112,7 +119,10 @@ def write_points(self, start_addr=None, next_addr=None, data=None):
112119
data = b''
113120
if point.dirty:
114121
point_len = point.len
115-
point_data = point.info.to_data(point.value, int(point_len) * 2)
122+
try:
123+
point_data = point.info.to_data(point.value, int(point_len) * 2)
124+
except Exception as e:
125+
raise SunSpecModbusValueError('Point value error for %s %s: %s' % (name, point.value, str(e)))
116126
if not data:
117127
start_addr = point_addr
118128
next_addr = point_addr + point_len

0 commit comments

Comments
 (0)