Skip to content

Commit

Permalink
WriteMultipleRegistersRequest: Handle values=None case
Browse files Browse the repository at this point in the history
Currently, if None is passed in explicitly, or if values is not given,
the 'values' object is correctly identified as *not* having an __iter__
attribute, but is incorrectly identified as being a valid register value.
This breaks testInvalidWriteMultipleRegistersRequest.

Solution: if we see None, replace this with [] and skip the check for
__iter__.
  • Loading branch information
sjlongland committed Jun 3, 2015
1 parent fec7ac3 commit 9726a58
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pymodbus/register_write_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ def __init__(self, address=None, values=None, **kwargs):
'''
ModbusRequest.__init__(self, **kwargs)
self.address = address
self.values = values or []
if not hasattr(values, '__iter__'):
self.values = [values]
if values is None:
values = []
elif not hasattr(values, '__iter__'):
values = [values]
self.values = values
self.count = len(self.values)
self.byte_count = self.count * 2

Expand Down

0 comments on commit 9726a58

Please sign in to comment.