From 2e889843b4c171f2d6ad8e0d53084040703d11f6 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 09 十一月 2026 13:18:21 +0800
Subject: [PATCH] docs: CAN 总线级应答器 + 硬件调试页多标签多会话 设计规格
---
SimpleUtil/HMI.Simple.Util/ParameterUtil.cs | 242 +++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 207 insertions(+), 35 deletions(-)
diff --git a/SimpleUtil/HMI.Simple.Util/ParameterUtil.cs b/SimpleUtil/HMI.Simple.Util/ParameterUtil.cs
index e979546..8e1054e 100644
--- a/SimpleUtil/HMI.Simple.Util/ParameterUtil.cs
+++ b/SimpleUtil/HMI.Simple.Util/ParameterUtil.cs
@@ -1,4 +1,4 @@
-锘縰sing Microsoft.Win32;
+锘縰sing NationalInstruments.TestStand.Interop.API;
using System;
using System.Collections.Generic;
using System.IO;
@@ -8,8 +8,12 @@
{
public class ParameterUtil
{
- private static string Company = "JingCe";
- private static string Program = "HMI";
+ /// <summary>
+ /// 鏍规嵁璺緞鍜屽弬鏁板悕鑾峰彇鍙傛暟鍊�
+ /// </summary>
+ /// <param name="path">璺緞</param>
+ /// <param name="name">鍙傛暟鍚�</param>
+ /// <returns>鍙傛暟鍊�</returns>
public static string GetCommonParameterValue(string path, string name)
{
if (!File.Exists(path)) return null;
@@ -22,45 +26,28 @@
/// <summary>
/// 鑾峰彇HMI閲岄厤缃殑鍙傛暟
/// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
+ /// <param name="name">鍙傛暟鍚�</param>
+ /// <returns>鍙傛暟鍊�</returns>
public static string GetCommonParameterValue(string name, out string errMsg)
{
errMsg = string.Empty;
try
{
- string registryPath = $@"SOFTWARE\{Company}\{Program}";
- // 灏濊瘯鎵撳紑娉ㄥ唽琛ㄩ敭
- using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryPath))
+ string value = RegUtil.GetLocaltion();
+ string path = Path.Combine(value, "Config", "Parameter", "CommonParameter.data");
+ if (!File.Exists(path))
{
- if (key == null)
- {
- errMsg = "娉ㄥ唽琛ㄤ笉瀛樺湪锛岃鍏堣繍琛屼竴娆MI";
- return null;
- }
-
- string value = key.GetValue("Location")?.ToString();
- if (string.IsNullOrEmpty(value))
- {
- errMsg = "娉ㄥ唽琛ㄤ笉瀛樺湪锛岃鍏堣繍琛屼竴娆MI";
- return null;
- }
- string path = Path.Combine(value, "Config", "Parameter", "CommonParameter.data");
- if (!File.Exists(path))
- {
- errMsg = "鏈壘鍒伴厤缃枃浠�";
- return null;
- }
- List<ParameterData> datas = XmlHelper.DeserializeFromXml<List<ParameterData>>(path);
- ParameterData data = datas.FirstOrDefault(d => d.Name == name);
- if (data == null)
- {
- errMsg = "鏈壘鍒板弬鏁帮紝璇锋鏌ラ厤缃�";
- return null;
- }
- ;
- return data.Value;
+ errMsg = "鏈壘鍒伴厤缃枃浠�";
+ return null;
}
+ List<ParameterData> datas = XmlHelper.DeserializeFromXml<List<ParameterData>>(path);
+ ParameterData data = datas.FirstOrDefault(d => d.Name == name);
+ if (data == null)
+ {
+ errMsg = "鏈壘鍒板弬鏁帮紝璇锋鏌ラ厤缃�";
+ return null;
+ }
+ return data.Value;
}
catch (Exception ex)
{
@@ -68,5 +55,190 @@
return null;
}
}
+
+ private static void WriteParameterData(SequenceContext context, ParameterData data)
+ {
+ string prefix = "SystemSetting";
+
+ if (data.IsArray)
+ {
+ PropertyValueTypes type;
+ if (data.Type == "Bool")
+ {
+ type = PropertyValueTypes.PropValType_Boolean;
+ }
+ else if (data.Type == "Int")
+ {
+ type = PropertyValueTypes.PropValType_Number;
+ }
+ else if (data.Type == "Double")
+ {
+ type = PropertyValueTypes.PropValType_Number;
+ }
+ else
+ {
+ type = PropertyValueTypes.PropValType_String;
+ }
+ string[] arr = data.Value?.Split(',') ?? new string[0];
+ if (arr.Length > 0)
+ {
+ context.StationGlobals.DeleteSubProperty($"{prefix}.{data.Name}", 2);
+
+ context.StationGlobals.NewSubProperty($"{prefix}.{data.Name}", type, true, null, 1);
+ context.StationGlobals.GetPropertyObject($"{prefix}.{data.Name}", 0).SetNumElements(arr.Length);
+ for (int i = 0; i < arr.Length; i++)
+ {
+ if (type == PropertyValueTypes.PropValType_String)
+ {
+ context.StationGlobals.SetValString($"{prefix}.{data.Name}[{i}]", 0, arr[i]);
+ }
+ if (data.Type == "Int")
+ {
+ context.StationGlobals.SetValNumber($"{prefix}.{data.Name}[{i}]", 0, int.Parse(arr[i]));
+ }
+ if (data.Type == "Double")
+ {
+ context.StationGlobals.SetValNumber($"{prefix}.{data.Name}[{i}]", 0, double.Parse(arr[i]));
+ }
+ if (data.Type == "Bool")
+ {
+ context.StationGlobals.SetValBoolean($"{prefix}.{data.Name}[{i}]", 0, bool.Parse(arr[i]));
+ }
+ }
+ }
+ }
+ else
+ {
+ if (data.Type == "Bool")
+ {
+ context.StationGlobals.SetValBoolean($"{prefix}.{data.Name}", 1, bool.Parse(data.Value));
+ }
+ else if (data.Type == "Int")
+ {
+ context.StationGlobals.SetValNumber($"{prefix}.{data.Name}", 1, int.Parse(data.Value));
+ }
+ else if (data.Type == "Double")
+ {
+ context.StationGlobals.SetValNumber($"{prefix}.{data.Name}", 1, double.Parse(data.Value));
+ }
+ else
+ {
+ context.StationGlobals.SetValString($"{prefix}.{data.Name}", 1, data.Value);
+ }
+ }
+ }
+
+ /// <summary>
+ /// 灏嗗弬鏁板啓杩汦ngine鐨凷tationGlobals.StationState
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static bool WriteConfigToContext(object instance, out string errMsg)
+ {
+ errMsg = string.Empty;
+ try
+ {
+ string value = RegUtil.GetLocaltion();
+ string path = Path.Combine(value, "Config", "Parameter", "CommonParameter.data");
+ return WriteConfigToContext(path, instance, out errMsg);
+ }
+ catch (Exception ex)
+ {
+ errMsg = ex.Message;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// 灏嗗弬鏁板啓杩汦ngine鐨凷tationGlobals.StationState
+ /// </summary>
+ /// <param name="xmlPath">缁濆璺緞</param>
+ /// <param name="instance">TestStand涓婁笅鏂�</param>
+ /// <param name="errMsg">寮傚父淇℃伅</param>
+ /// <returns>鏄惁鎴愬姛</returns>
+ public static bool WriteConfigToContext(string xmlPath, object instance, out string errMsg)
+ {
+ errMsg = string.Empty;
+ try
+ {
+ SequenceContext context = (SequenceContext)instance;
+ if (string.IsNullOrEmpty(xmlPath))
+ {
+ throw new Exception("閰嶇疆鏂囦欢璺緞涓嶈兘涓虹┖");
+ }
+ if (!File.Exists(xmlPath))
+ {
+ throw new Exception("鏈壘鍒伴厤缃枃浠�");
+ }
+ List<ParameterData> datas = XmlHelper.DeserializeFromXml<List<ParameterData>>(xmlPath);
+ foreach (var data in datas)
+ {
+ WriteParameterData(context, data);
+ }
+ return true;
+ }
+ catch (Exception ex)
+ {
+ errMsg = ex.Message;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// 灏嗗弬鏁板啓杩汦ngine鐨凷tationGlobals.StationState
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static bool WriteConfigToEngineByName(string xmlPath, object instance, string name, out string errMsg)
+ {
+ errMsg = string.Empty;
+ try
+ {
+ SequenceContext context = (SequenceContext)instance;
+ if (string.IsNullOrEmpty(xmlPath))
+ {
+ throw new Exception("閰嶇疆鏂囦欢璺緞涓嶈兘涓虹┖");
+ }
+ if (!File.Exists(xmlPath))
+ {
+ throw new Exception("鏈壘鍒伴厤缃枃浠�");
+ }
+ List<ParameterData> datas = XmlHelper.DeserializeFromXml<List<ParameterData>>(xmlPath);
+ ParameterData data = datas.FirstOrDefault(d => d.Name == name);
+ if (data == null)
+ {
+ throw new Exception("鏈壘鍒板弬鏁帮紝璇锋鏌ラ厤缃�");
+ }
+ WriteParameterData(context, data);
+ return true;
+ }
+ catch (Exception ex)
+ {
+ errMsg = ex.Message;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// 灏嗗弬鏁板啓杩汦ngine鐨凷tationGlobals.StationState
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static bool WriteConfigToEngineByName(object instance, string name, out string errMsg)
+ {
+ errMsg = string.Empty;
+ try
+ {
+ SequenceContext engine = (SequenceContext)instance;
+ string value = RegUtil.GetLocaltion();
+ string path = Path.Combine(value, "Config", "Parameter", "CommonParameter.data");
+ return WriteConfigToEngineByName(path, instance, name, out errMsg);
+ }
+ catch (Exception ex)
+ {
+ errMsg = ex.Message;
+ return false;
+ }
+ }
}
}
--
Gitblit v1.9.1