|
@@ -2942,6 +2942,49 @@ namespace EIP_Protocol
|
|
return (nRet, "OK");
|
|
return (nRet, "OK");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 一次读取单个标签
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <typeparam name="T">需要读取的标签结构</typeparam>
|
|
|
|
+ /// <param name="strTagName">需要读取的标签名</param>
|
|
|
|
+ /// <param name="nCount">读取标签的个数</param>
|
|
|
|
+ /// <param name="outObj">返回相应标签值对象</param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public (int, string) Read_SingleTag<T>(string strTagName, int nCount, out T outObj)
|
|
|
|
+ {
|
|
|
|
+ outObj = default(T);
|
|
|
|
+ byte[] pBuf = null;
|
|
|
|
+ int nRet = 0;
|
|
|
|
+ string strRet = "";
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ (nRet, strRet) = Read_Tag(strTagPrefix + strTagName, nCount, out pBuf);
|
|
|
|
+ if (nRet != 0) return (nRet, strRet);
|
|
|
|
+
|
|
|
|
+ string str = typeof(T).Name;
|
|
|
|
+ string[] substrings = { "Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UInt32", "Int64", "UInt64", "Single", "Double", "String" };
|
|
|
|
+
|
|
|
|
+ bool containsAny = substrings.Any(substring => str.Contains(substring));
|
|
|
|
+ if (containsAny)
|
|
|
|
+ {
|
|
|
|
+ if (str != strRet) return (120, "变量类型不一致");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (str == "String")
|
|
|
|
+ {
|
|
|
|
+ outObj = (T)(object)System.Text.Encoding.UTF8.GetString(pBuf);
|
|
|
|
+ return (0, "OK");
|
|
|
|
+ }
|
|
|
|
+ outObj = (T)ByteToStruct(pBuf, typeof(T));
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ return (110, ex.ToString());
|
|
|
|
+ }
|
|
|
|
+ return (0, "OK");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private Form _processingForm;
|
|
private Form _processingForm;
|
|
|
|
|
|
private void ShowProcessingDialog(Control uiControl)
|
|
private void ShowProcessingDialog(Control uiControl)
|