From 9726a58213f14201845431c6bbac93ea7c1fcdcc Mon Sep 17 00:00:00 2001 From: Stuart Longland Date: Thu, 4 Jun 2015 09:44:27 +1000 Subject: [PATCH] WriteMultipleRegistersRequest: Handle values=None case 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__. --- pymodbus/register_write_message.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pymodbus/register_write_message.py b/pymodbus/register_write_message.py index 4ff21ac9c..b49db4901 100644 --- a/pymodbus/register_write_message.py +++ b/pymodbus/register_write_message.py @@ -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