modbus/mb_utils.py
changeset 2647 990004083eb8
parent 2437 105c20fdeb19
child 2654 7575050a80c5
equal deleted inserted replaced
2640:1b4b335e19ea 2647:990004083eb8
   182             The string that should be added on C code - if everything goes allright
   182             The string that should be added on C code - if everything goes allright
   183     """
   183     """
   184 
   184 
   185     req_init_template = '''/*request %(locreqstr)s*/
   185     req_init_template = '''/*request %(locreqstr)s*/
   186 {"%(locreqstr)s", %(nodeid)s, %(slaveid)s, %(iotype)s, %(func_nr)s, %(address)s , %(count)s,
   186 {"%(locreqstr)s", %(nodeid)s, %(slaveid)s, %(iotype)s, %(func_nr)s, %(address)s , %(count)s,
   187 DEF_REQ_SEND_RETRIES, 0 /* error_code */, 0 /* prev_code */, {%(timeout_s)d, %(timeout_ns)d} /* timeout */,
   187 DEF_REQ_SEND_RETRIES, 0 /* error_code */, 0 /* prev_code */, {%(timeout_s)d, %(timeout_ns)d} /* timeout */, %(write_on_change)d /* write_on_change */,
   188 {%(buffer)s}, {%(buffer)s}}'''
   188 {%(buffer)s}, {%(buffer)s}}'''
   189 
   189 
   190     timeout = int(GetCTVal(child, 4))
   190     timeout = int(GetCTVal(child, 4))
   191     timeout_s = timeout // 1000
   191     timeout_s = timeout // 1000
   192     timeout_ms = timeout - (timeout_s * 1000)
   192     timeout_ms = timeout - (timeout_s * 1000)
   196         "locreqstr": "_".join(map(str, child.GetCurrentLocation())),
   196         "locreqstr": "_".join(map(str, child.GetCurrentLocation())),
   197         "nodeid": str(nodeid),
   197         "nodeid": str(nodeid),
   198         "slaveid": GetCTVal(child, 1),
   198         "slaveid": GetCTVal(child, 1),
   199         "address": GetCTVal(child, 3),
   199         "address": GetCTVal(child, 3),
   200         "count": GetCTVal(child, 2),
   200         "count": GetCTVal(child, 2),
       
   201         "write_on_change": GetCTVal(child, 5),
   201         "timeout": timeout,
   202         "timeout": timeout,
   202         "timeout_s": timeout_s,
   203         "timeout_s": timeout_s,
   203         "timeout_ns": timeout_ns,
   204         "timeout_ns": timeout_ns,
   204         "buffer": ",".join(['0'] * int(GetCTVal(child, 2))),
   205         "buffer": ",".join(['0'] * int(GetCTVal(child, 2))),
   205         "func_nr": modbus_function_dict[GetCTVal(child, 0)][0],
   206         "func_nr": modbus_function_dict[GetCTVal(child, 0)][0],
   220         return None
   221         return None
   221     if (int(request_dict["address"]) + int(request_dict["count"])) not in xrange(1, 65537):
   222     if (int(request_dict["address"]) + int(request_dict["count"])) not in xrange(1, 65537):
   222         self.GetCTRoot().logger.write_error(
   223         self.GetCTRoot().logger.write_error(
   223             "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)
   224             "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)
   224         return None
   225         return None
       
   226     if (request_dict["write_on_change"] and (request_dict["iotype"] == 'req_input')):
       
   227         self.GetCTRoot().logger.write_error(
       
   228             "Modbus plugin: (warning) MB client request node %(locreqstr)s has option 'write_on_change' enabled.\nModbus plugin: This option will be ignored by the Modbus read function.\n" % request_dict)
       
   229         # NOTE: this is only a warning (we don't wish to abort code generation) so following line must be left commented out!
       
   230         # return None
       
   231     
   225 
   232 
   226     return req_init_template % request_dict
   233     return req_init_template % request_dict