/// <summary> ///设置取指定名称的初始化参数的当前值 /// </summary> /// <param name="name">参数名称,如果参数名称不在InitParamNames中,将会抛出一个ArgumentException异常</param> /// <param name="value">参数值</param> /// <returns>操作成功返回True,失败返回false,可通过GetInitErrorInfo()获取错误信息</returns> public bool SetInitParamValue(string name, object value) { _CheckInitName(name, "SetInitParamValue(name, value)"); if (null == value) { throw new Exception("SetInitParamValue(name, value) failed By: value = null"); } if (!GetInitParamDescribe(name).ParamType.IsAssignableFrom(value.GetType())) { throw new ArgumentException(string.Format("SetInitParamValue(name = {0}, value) faile By: value's Type = {1} can't Assignable to InitParam's Type:{2}", name, value.GetType(), GetInitParamDescribe(name).ParamType.Name)); } if (name == "IP") { string tmp = value as string; if (!JFFunctions.IsIPAddress(tmp)) { _initErrorInfo = string.Format("SetInitParamValue(string name = {0},...) failed By: name isnot Legal ip address", name); return(false); } _cmrIP = tmp; _initErrorInfo = "Success"; return(true); } _initErrorInfo = string.Format("SetInitParamValue(string name = {0},...) failed By: name is not included by InitParamNames:{1}", name, string.Join("|", InitParamNames)); return(false); }
/// <summary> /// 对象初始化 /// </summary> /// <returns>操作成功返回True,失败返回false,可通过GetInitErrorInfo()获取错误信息</returns> public bool Initialize() { if (!JFFunctions.IsIPAddress(_cmrIP)) { _initErrorInfo = "Initialize()failed by IP = \"" + _cmrIP + "\" is not legal ip address"; IsInitOK = false; return(false); } IsInitOK = true; _initErrorInfo = "Success"; return(true); }
/// <summary> /// 对象初始化 /// </summary> /// <returns>操作成功返回True,失败返回false,可通过GetInitErrorInfo()获取错误信息</returns> public bool Initialize() { if (IsDeviceOpen) { CloseDevice(); } if (linkMode == null) { _initError = "Initialize Failed By:LinkMode is not set"; IsInitOK = false; return(false); } if (linkMode == linkModeParamRange[0] as string) //串口连接 { if (JFFunctions.IsSerialPortName(linkParam)) { _initError = "Success"; IsInitOK = true; return(true); } _initError = "LinkParam = " + linkParam + " is not a legal serial-port name"; IsInitOK = false; return(false); } else if (linkMode == linkModeParamRange[1] as string)//TCP/IP { if (JFFunctions.IsIPAddress(linkParam)) { _initError = "Success"; IsInitOK = true; return(true); } _initError = "LinkParam = " + linkParam + " is not a legal ip address"; IsInitOK = false; return(false); } else if (linkMode == linkModeParamRange[2] as string) //SN { if (!string.IsNullOrWhiteSpace(linkParam)) { _initError = "Success"; IsInitOK = true; return(true); } _initError = "LinkParam = null or whitespace when linkmode = SN"; IsInitOK = false; return(false); } _initError = "Initialize Failed By:LinkMode = " + linkMode + " is not included in the values{0:使用串口 1:使用TCP 2:使用SN}"; IsInitOK = false; return(false); }