| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using Plugins.Motion.Models;
- using TeamAAS.FlowEditor.Models;
- using TeamAAS.FlowEditor.Plugins;
- using TeamAAS.Motion;
- namespace Plugins.Motion
- {
- [Serializable]
- [Plugin("轴使能", PluginCategory.硬件模块, typeof(MotionEnableModel), "Power",
- Description = "对指定轴或全部轴上使能")]
- public class MotionEnablePlugin : BasePlugin<MotionEnableModel>
- {
- public override List<OutputField> DeclareOutputs() => new List<OutputField>
- {
- new OutputField("结果", typeof(bool)),
- new OutputField("使能", typeof(bool)),
- new OutputField("最终位置", typeof(double)),
- };
- public override NodeRunStatus PluginRun(CancellationToken token, out Dictionary<string, object> results)
- {
- var res = new Dictionary<string, object>();
- results = res;
- NodeRunStatus Fail(string m)
- {
- res["Error"] = m;
- res["结果"] = false;
- Log(1, $"轴使能失败: {m}", TeamAAS.LogLevel.Error);
- return NodeRunStatus.Failed;
- }
- try
- {
- var card = MotionPluginHelper.GetCard(Service<MotionManager>(), Model.MotionCardName, out var err);
- if (card == null) return Fail(err);
- err = MotionPluginHelper.EnsureConnected(card, Model.AutoConnect);
- if (err != null) return Fail(err);
- Log(3, $"轴使能 卡={card.Name} 轴={Model.AxisNo}");
- if (!card.SetEnable(Model.AxisNo, true))
- return Fail("下发使能失败");
- if (Model.AxisNo >= 0)
- MotionPluginHelper.FillStatus(res, card.GetAxisStatus(Model.AxisNo));
- else
- res["使能"] = true;
- res["结果"] = true;
- return NodeRunStatus.Success;
- }
- catch (OperationCanceledException) { throw; }
- catch (Exception ex) { return Fail(ex.Message); }
- }
- }
- [Serializable]
- [Plugin("轴下使能", PluginCategory.硬件模块, typeof(MotionDisableModel), "PowerOff",
- Description = "对指定轴或全部轴下使能")]
- public class MotionDisablePlugin : BasePlugin<MotionDisableModel>
- {
- public override List<OutputField> DeclareOutputs() => new List<OutputField>
- {
- new OutputField("结果", typeof(bool)),
- new OutputField("使能", typeof(bool)),
- new OutputField("最终位置", typeof(double)),
- };
- public override NodeRunStatus PluginRun(CancellationToken token, out Dictionary<string, object> results)
- {
- var res = new Dictionary<string, object>();
- results = res;
- NodeRunStatus Fail(string m)
- {
- res["Error"] = m;
- res["结果"] = false;
- Log(1, $"轴下使能失败: {m}", TeamAAS.LogLevel.Error);
- return NodeRunStatus.Failed;
- }
- try
- {
- var card = MotionPluginHelper.GetCard(Service<MotionManager>(), Model.MotionCardName, out var err);
- if (card == null) return Fail(err);
- err = MotionPluginHelper.EnsureConnected(card, Model.AutoConnect);
- if (err != null) return Fail(err);
- Log(3, $"轴下使能 卡={card.Name} 轴={Model.AxisNo}");
- card.Stop(Model.AxisNo);
- if (!card.SetEnable(Model.AxisNo, false))
- return Fail("下发下使能失败");
- if (Model.AxisNo >= 0)
- MotionPluginHelper.FillStatus(res, card.GetAxisStatus(Model.AxisNo));
- else
- res["使能"] = false;
- res["结果"] = true;
- return NodeRunStatus.Success;
- }
- catch (OperationCanceledException) { throw; }
- catch (Exception ex) { return Fail(ex.Message); }
- }
- }
- }
|