modbus/web_settings.py
changeset 3869 b722c800b6c7
parent 3743 5450dd9e9370
equal deleted inserted replaced
3868:e9807c28a788 3869:b722c800b6c7
   470     # addr_type will be one of "tcp", "rtu" or "ascii"
   470     # addr_type will be one of "tcp", "rtu" or "ascii"
   471     addr_type   = GetParamFuncs["addr_type"  ](C_node_id)   
   471     addr_type   = GetParamFuncs["addr_type"  ](C_node_id)   
   472     # For some operations we cannot use the config name (e.g. filename to store config)
   472     # For some operations we cannot use the config name (e.g. filename to store config)
   473     # because the user may be using characters that are invalid for that purpose ('/' for
   473     # because the user may be using characters that are invalid for that purpose ('/' for
   474     # example), so we create a hash of the config_name, and use that instead.
   474     # example), so we create a hash of the config_name, and use that instead.
   475     config_hash = hashlib.md5(config_name).hexdigest()
   475     config_hash = hashlib.md5(config_name.encode()).hexdigest()
   476     
   476     
   477     #PLCObject.LogMessage("Modbus web server extension::_AddWebNode("+str(C_node_id)+") config_name="+config_name)
   477     #PLCObject.LogMessage("Modbus web server extension::_AddWebNode("+str(C_node_id)+") config_name="+config_name)
   478 
   478 
   479     # Add the new entry to the global list
   479     # Add the new entry to the global list
   480     # Note: it is OK, and actually necessary, to do this _before_ seting all the parameters in WebNode_entry
   480     # Note: it is OK, and actually necessary, to do this _before_ seting all the parameters in WebNode_entry
   626 
   626 
   627     # XXX TODO : stop reading from PLC .so file. This code is template code
   627     # XXX TODO : stop reading from PLC .so file. This code is template code
   628     #            that can use modbus extension build data
   628     #            that can use modbus extension build data
   629     for name, web_label, c_dtype, web_dtype, coerce_function in TCPclient_parameters + RTUclient_parameters + General_parameters:
   629     for name, web_label, c_dtype, web_dtype, coerce_function in TCPclient_parameters + RTUclient_parameters + General_parameters:
   630         ParamFuncName                      = "__modbus_get_ClientNode_" + name        
   630         ParamFuncName                      = "__modbus_get_ClientNode_" + name        
   631         GetClientParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
   631         func                               = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
   632         GetClientParamFuncs[name].restype  = c_dtype
   632         func.restype                       = c_dtype
   633         GetClientParamFuncs[name].argtypes = [ctypes.c_int]
   633         func.argtypes                      = [ctypes.c_int]
       
   634         GetClientParamFuncs[name] = (lambda *a,**k: func(*a,**k).decode()) if c_dtype == ctypes.c_char_p else func
   634         
   635         
   635     for name, web_label, c_dtype, web_dtype, coerce_function in TCPclient_parameters + RTUclient_parameters:
   636     for name, web_label, c_dtype, web_dtype, coerce_function in TCPclient_parameters + RTUclient_parameters:
   636         ParamFuncName                      = "__modbus_set_ClientNode_" + name
   637         ParamFuncName                      = "__modbus_set_ClientNode_" + name
   637         SetClientParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
   638         SetClientParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
   638         SetClientParamFuncs[name].restype  = None
   639         SetClientParamFuncs[name].restype  = None
   641 
   642 
   642     # XXX TODO : stop reading from PLC .so file. This code is template code
   643     # XXX TODO : stop reading from PLC .so file. This code is template code
   643     #            that can use modbus extension build data
   644     #            that can use modbus extension build data
   644     for name, web_label, c_dtype, web_dtype, coerce_function in TCPserver_parameters + RTUslave_parameters + General_parameters:
   645     for name, web_label, c_dtype, web_dtype, coerce_function in TCPserver_parameters + RTUslave_parameters + General_parameters:
   645         ParamFuncName                      = "__modbus_get_ServerNode_" + name        
   646         ParamFuncName                      = "__modbus_get_ServerNode_" + name        
   646         GetServerParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
   647         func                               = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
   647         GetServerParamFuncs[name].restype  = c_dtype
   648         func.restype                       = c_dtype
   648         GetServerParamFuncs[name].argtypes = [ctypes.c_int]
   649         func.argtypes                      = [ctypes.c_int]
   649         
   650         GetServerParamFuncs[name] = (lambda *a,**k: func(*a,**k).decode()) if c_dtype == ctypes.c_char_p else func
       
   651 
   650     for name, web_label, c_dtype, web_dtype, coerce_function in TCPserver_parameters + RTUslave_parameters:
   652     for name, web_label, c_dtype, web_dtype, coerce_function in TCPserver_parameters + RTUslave_parameters:
   651         ParamFuncName                      = "__modbus_set_ServerNode_" + name
   653         ParamFuncName                      = "__modbus_set_ServerNode_" + name
   652         SetServerParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
   654         SetServerParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
   653         SetServerParamFuncs[name].restype  = None
   655         SetServerParamFuncs[name].restype  = None
   654         SetServerParamFuncs[name].argtypes = [ctypes.c_int, c_dtype]
   656         SetServerParamFuncs[name].argtypes = [ctypes.c_int, c_dtype]