Skip to content

Commit

Permalink
Merge pull request #63 from sunspec/development
Browse files Browse the repository at this point in the history
Updated data conversion error detail #62
  • Loading branch information
bobfox authored Apr 27, 2022
2 parents bac4acf + 3cb5a3a commit 552ad76
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions sunspec2/modbus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class SunSpecModbusClientError(Exception):
pass


class SunSpecModbusValueError(Exception):
pass


class SunSpecModbusClientTimeout(SunSpecModbusClientError):
pass

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

def write(self):
"""Write the point to the physical device"""

data = self.info.to_data(self.value, int(self.len) * 2)
try:
data = self.info.to_data(self.value, int(self.len) * 2)
except Exception as e:
raise SunSpecModbusValueError('Point value error for %s %s: %s' % (self.pdef.get(mdef.NAME), self.value,
str(e)))
model_addr = self.model.model_addr
point_offset = self.offset
addr = model_addr + point_offset
Expand Down Expand Up @@ -112,7 +119,10 @@ def write_points(self, start_addr=None, next_addr=None, data=None):
data = b''
if point.dirty:
point_len = point.len
point_data = point.info.to_data(point.value, int(point_len) * 2)
try:
point_data = point.info.to_data(point.value, int(point_len) * 2)
except Exception as e:
raise SunSpecModbusValueError('Point value error for %s %s: %s' % (name, point.value, str(e)))
if not data:
start_addr = point_addr
next_addr = point_addr + point_len
Expand Down

0 comments on commit 552ad76

Please sign in to comment.