diff -r fda6c1a37662 -r f62625418bff modbus/mb_utils.py --- a/modbus/mb_utils.py Mon Mar 27 10:19:14 2023 +0200 +++ b/modbus/mb_utils.py Fri Oct 28 12:39:15 2022 +0800 @@ -22,8 +22,8 @@ # This code is made available on the understanding that it will not be # used in safety-critical situations without a full and competent review. -from __future__ import absolute_import -from __future__ import division + + from six.moves import xrange # dictionary implementing: @@ -48,7 +48,7 @@ # Configuration tree value acces helper, for multiple values def GetCTVals(child, indexes): - return map(lambda index: GetCTVal(child, index), indexes) + return [GetCTVal(child, index) for index in indexes] def GetTCPServerNodePrinted(self, child): @@ -60,7 +60,7 @@ {"%(locnodestr)s", "%(config_name)s", "%(host)s", "%(port)s", %(slaveid)s, {naf_tcp, {.tcp = {NULL, NULL, DEF_CLOSE_ON_SILENCE}}}, -1 /* mb_nd */, 0 /* init_state */}''' location = ".".join(map(str, child.GetCurrentLocation())) - config_name, host, port, slaveid = GetCTVals(child, range(4)) + config_name, host, port, slaveid = GetCTVals(child, list(range(4))) if host == "#ANY#": host = '' # slaveid = GetCTVal(child, 2) @@ -90,16 +90,16 @@ request_dict["locreqstr"] = "_".join(map(str, child.GetCurrentLocation())) request_dict["nodeid"] = str(nodeid) request_dict["address"] = GetCTVal(child, 2) - if int(request_dict["address"]) not in xrange(65536): + if int(request_dict["address"]) not in range(65536): self.GetCTRoot().logger.write_error( "Modbus plugin: Invalid Start Address in server memory area node %(locreqstr)s (Must be in the range [0..65535])\nModbus plugin: Aborting C code generation for this node\n" % request_dict) return None request_dict["count"] = GetCTVal(child, 1) - if int(request_dict["count"]) not in xrange(1, 65537): + if int(request_dict["count"]) not in range(1, 65537): self.GetCTRoot().logger.write_error( "Modbus plugin: Invalid number of channels in server memory area node %(locreqstr)s (Must be in the range [1..65536-start_address])\nModbus plugin: Aborting C code generation for this node\n" % request_dict) return None - if (int(request_dict["address"]) + int(request_dict["count"])) not in xrange(1, 65537): + if (int(request_dict["address"]) + int(request_dict["count"])) not in range(1, 65537): self.GetCTRoot().logger.write_error( "Modbus plugin: Invalid number of channels in server memory area node %(locreqstr)s (Must be in the range [1..65536-start_address])\nModbus plugin: Aborting C code generation for this node\n" % request_dict) return None @@ -122,7 +122,7 @@ {"%(locnodestr)s", "%(config_name)s", "%(device)s", "",%(slaveid)s, {naf_rtu, {.rtu = {NULL, %(baud)s /*baud*/, %(parity)s /*parity*/, 8 /*data bits*/, %(stopbits)s, 0 /* ignore echo */}}}, -1 /* mb_nd */, 0 /* init_state */}''' location = ".".join(map(str, child.GetCurrentLocation())) - config_name, device, baud, parity, stopbits, slaveid = GetCTVals(child, range(6)) + config_name, device, baud, parity, stopbits, slaveid = GetCTVals(child, list(range(6))) node_dict = {"locnodestr": location, "config_name": config_name, @@ -143,7 +143,7 @@ {"%(locnodestr)s", "%(config_name)s", "%(device)s", "", {naf_rtu, {.rtu = {NULL, %(baud)s /*baud*/, %(parity)s /*parity*/, 8 /*data bits*/, %(stopbits)s, 0 /* ignore echo */}}}, -1 /* mb_nd */, 0 /* init_state */, %(coms_period)s /* communication period (ms)*/, %(coms_delay)s /* inter request delay (ms)*/, 0 /* prev_error */}''' location = ".".join(map(str, child.GetCurrentLocation())) - config_name, device, baud, parity, stopbits, coms_period, coms_delay = GetCTVals(child, range(7)) + config_name, device, baud, parity, stopbits, coms_period, coms_delay = GetCTVals(child, list(range(7))) node_dict = {"locnodestr": location, "config_name": config_name, @@ -165,7 +165,7 @@ {"%(locnodestr)s", "%(config_name)s", "%(host)s", "%(port)s", {naf_tcp, {.tcp = {NULL, NULL, DEF_CLOSE_ON_SILENCE}}}, -1 /* mb_nd */, 0 /* init_state */, %(coms_period)s /* communication period (ms)*/, %(coms_delay)s /* inter request delay (ms)*/, 0 /* prev_error */}''' location = ".".join(map(str, child.GetCurrentLocation())) - config_name, host, port, coms_period, coms_delay = GetCTVals(child, range(5)) + config_name, host, port, coms_period, coms_delay = GetCTVals(child, list(range(5))) node_dict = {"locnodestr": location, "config_name": config_name, @@ -211,19 +211,19 @@ "iotype": modbus_function_dict[GetCTVal(child, 0)][1], "maxcount": modbus_function_dict[GetCTVal(child, 0)][2]} - if int(request_dict["slaveid"]) not in xrange(256): + if int(request_dict["slaveid"]) not in range(256): self.GetCTRoot().logger.write_error( "Modbus plugin: Invalid slaveID in TCP client request node %(locreqstr)s (Must be in the range [0..255])\nModbus plugin: Aborting C code generation for this node\n" % request_dict) return None - if int(request_dict["address"]) not in xrange(65536): + if int(request_dict["address"]) not in range(65536): self.GetCTRoot().logger.write_error( "Modbus plugin: Invalid Start Address in TCP client request node %(locreqstr)s (Must be in the range [0..65535])\nModbus plugin: Aborting C code generation for this node\n" % request_dict) return None - if int(request_dict["count"]) not in xrange(1, 1 + int(request_dict["maxcount"])): + if int(request_dict["count"]) not in range(1, 1 + int(request_dict["maxcount"])): self.GetCTRoot().logger.write_error( "Modbus plugin: Invalid number of channels in TCP client request node %(locreqstr)s (Must be in the range [1..%(maxcount)s])\nModbus plugin: Aborting C code generation for this node\n" % request_dict) return None - if (int(request_dict["address"]) + int(request_dict["count"])) not in xrange(1, 65537): + if (int(request_dict["address"]) + int(request_dict["count"])) not in range(1, 65537): self.GetCTRoot().logger.write_error( "Modbus plugin: Invalid number of channels in TCP client request node %(locreqstr)s (start_address + nr_channels must be less than 65536)\nModbus plugin: Aborting C code generation for this node\n" % request_dict) return None