From 76d74124f6011a25ee1cdbc322ab22e2c36d7beb Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期五, 16 一月 2026 12:23:27 +0800
Subject: [PATCH] 添加运动控制菜单底层逻辑
---
LB_VisionProcesses/MotionControl/MotionControlConfig.cs | 189 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 189 insertions(+), 0 deletions(-)
diff --git a/LB_VisionProcesses/MotionControl/MotionControlConfig.cs b/LB_VisionProcesses/MotionControl/MotionControlConfig.cs
new file mode 100644
index 0000000..7beb5bc
--- /dev/null
+++ b/LB_VisionProcesses/MotionControl/MotionControlConfig.cs
@@ -0,0 +1,189 @@
+锘縰sing LB_VisionProcesses.Communicators;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LB_VisionProcesses.MotionControl
+{
+ [Serializable]
+ [Process("杩愬姩鎺у埗妯″潡", Category = "杩愬姩鎺у埗宸ュ叿", Description = "鍒涘缓杩愬姩鎺у埗宸ュ叿")]
+ public class MotionControlConfig : IProcess
+ {
+ /// <summary>
+ /// 杩愬姩鎺у埗妯″潡闆嗗悎(Key:閫氳鍚嶏紝Value:閫氳鍙ユ焺)
+ /// </summary>
+ public ConcurrentDictionary<string, BaseMotionControl> dicMotionControls { get; set; }
+
+ /// <summary>
+ /// 閫氳闆嗗悎(Key:閫氳鍚嶏紝Value:閫氳鍙ユ焺)
+ /// </summary>
+ public ConcurrentDictionary<string, BaseCommunicator> dicCommunicators { get; set; }
+
+ public MotionControlConfig(ConcurrentDictionary<string, BaseMotionControl> dicMotionControl)
+ {
+ this.dicMotionControls = dicMotionControl;
+ strProcessClass = "LB_VisionProcesses.Communicators.MotionControlConfig";
+
+ Params.Inputs.Add("杩愬姩鎺у埗鍚嶇О", "");
+ //Params.Inputs.Add("X杞碢LC鍦板潃", "");
+ //Params.Inputs.Add("X杞存娴嬩綅缃�", "");
+ //Params.Inputs.Add("Y杞碢LC鍦板潃", "");
+ //Params.Inputs.Add("Z杞碢LC鍦板潃", "");
+ //Params.Inputs.Add("W杞碢LC鍦板潃", "");
+ Params.Outputs.Add("鏀跺埌鐨勪俊鎭�", "");
+ }
+
+ public override object Clone()
+ {
+ return MemberwiseClone();
+ }
+
+ public override void Dispose()
+ {
+ return;
+ }
+
+ public override void InitRunParams()
+ {
+ Result = true;
+ Msg = "";
+
+ if (Record != null)
+ {
+ Record.Dispose();
+ }
+ }
+ /// <summary>
+ /// 鍔犺浇绠楁硶
+ /// </summary>
+ /// <param name="fullPath">瀹屾暣璺緞甯�.json</param>
+ /// <returns></returns>
+ public override bool Load(string fullPath)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(fullPath))
+ return false;
+
+ if (!fullPath.Contains(".json"))
+ {
+ Debug.WriteLine("鏂囦欢璺緞涓嶅畬鏁�");
+ return false;
+ }
+ if (string.IsNullOrEmpty(fullPath) || fullPath.Trim() == "")
+ {
+ Debug.WriteLine("鏂囦欢璺緞涓嶅畬鏁�");
+ return false;
+ }
+
+ // 鑾峰彇涓嶅甫鏂囦欢鍚嶇殑鐩綍璺緞
+ string directoryPath = Path.GetDirectoryName(fullPath);
+ strProcessName = Path.GetFileNameWithoutExtension(fullPath);
+
+ if (!File.Exists(fullPath))
+ {
+ Debug.WriteLine("鏂囦欢涓嶅瓨鍦ㄥ垱寤虹┖鏂囦欢");
+ Save(directoryPath);
+ return true;
+ }
+
+ string strJson = string.Empty;
+ using (StreamReader streamReader = new StreamReader(fullPath, Encoding.UTF8))
+ {
+ strJson = streamReader.ReadToEnd();
+ streamReader.Close();
+ }
+ Params = JsonConvert.DeserializeObject<ProcessParams>(strJson);
+ if (Params == null)
+ return false;
+
+ Params.FixDeserializedData();
+ return true;
+ }
+ catch { return false; }
+ }
+
+ public override bool Run()
+ {
+ InitRunParams();
+ Params.Outputs["鏀跺埌娑堟伅"] = "";
+ string MotionControlName = Params.Inputs["杩愬姩鎺у埗鍚嶇О"].ToString();
+ if (!dicMotionControls.ContainsKey(MotionControlName))
+ {
+ Msg = $"杩愬姩鎺у埗[{MotionControlName}]涓嶅瓨鍦�";
+ Result = false;
+ return Result;
+ }
+ BaseMotionControl BaseMotionControl = dicMotionControls[MotionControlName];
+
+ if (BaseMotionControl == null)
+ {
+ Msg = $"杩愬姩鎺у埗[{MotionControlName}]鏈疄渚嬪寲";
+ Result = false;
+ return Result;
+ }
+
+ if (!BaseMotionControl.bConnected)
+ {
+ Msg = $"杩愬姩鎺у埗[{MotionControlName}]鏈繛鎺�";
+ Result = false;
+ return Result;
+ }
+
+ return true;
+ }
+
+ /// <summary>
+ /// 淇濆瓨绠楁硶
+ /// </summary>
+ /// <param name="filePath">涓嶅甫.json</param>
+ /// <returns></returns>
+ public override bool Save(string filePath = null)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(filePath) || filePath.Trim() == "")
+ {
+ Debug.WriteLine("鏂囦欢璺緞涓嶅畬鏁�");
+ return false;
+ }
+
+ string strJson = string.Empty;
+ var settings = new JsonSerializerSettings
+ {
+ Formatting = Newtonsoft.Json.Formatting.Indented,
+ // 鑷畾涔夌缉杩涳紙4绌烘牸锛�
+ ContractResolver = new DefaultContractResolver
+ {
+ NamingStrategy = new CamelCaseNamingStrategy()
+ }
+ };
+ strJson = JsonConvert.SerializeObject(Params, settings);
+
+ Params = JsonConvert.DeserializeObject<ProcessParams>(strJson);
+ if (Params == null)
+ return false;
+
+ //鍒ゆ柇鏂囦欢澶规槸鍚﹀瓨鍦紝闃插憜杈撳叆涓烘枃浠跺悕绉�
+ if (!Directory.Exists(filePath))
+ {
+ try
+ {
+ Directory.CreateDirectory(filePath);
+ }
+ catch (Exception)
+ { }
+ }
+ File.WriteAllText(filePath + "//" + strProcessName + ".json", strJson, Encoding.UTF8);
+ return true;
+ }
+ catch { return false; }
+ }
+ }
+}
--
Gitblit v1.9.3