| | |
| | | public class ParameterUtil |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// 根据路径和参数名获取参数值 |
| | | /// </summary> |
| | | /// <param name="path"></param> |
| | | /// <param name="name"></param> |
| | | /// <returns></returns> |
| | | /// <param name="path">路径</param> |
| | | /// <param name="name">参数名</param> |
| | | /// <returns>参数值</returns> |
| | | public static string GetCommonParameterValue(string path, string name) |
| | | { |
| | | if (!File.Exists(path)) return null; |
| | |
| | | /// <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; |
| | |
| | | private static void WriteParameterData(SequenceContext context, ParameterData data) |
| | | { |
| | | string prefix = "SystemSetting"; |
| | | if (data.Type == "Bool") |
| | | |
| | | if (data.IsArray) |
| | | { |
| | | context.StationGlobals.SetValBoolean($"{prefix}.{data.Name}", 1, bool.Parse(data.Value)); |
| | | } |
| | | else if (data.Type == "Int") |
| | | { |
| | | context.StationGlobals.SetValInteger64($"{prefix}.{data.Name}", 1, int.Parse(data.Value)); |
| | | } |
| | | else if (data.Type == "Double") |
| | | { |
| | | context.StationGlobals.SetValNumber($"{prefix}.{data.Name}", 1, double.Parse(data.Value)); |
| | | 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 |
| | | { |
| | | context.StationGlobals.SetValString($"{prefix}.{data.Name}", 1, data.Value); |
| | | 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> |
| | | /// 将参数写进Engine的StationGlobals.StationState |
| | | /// </summary> |
| | | /// <param name="name"></param> |
| | | /// <returns></returns> |
| | | /// <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; |