mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-02 15:50:47 +08:00
重写了节点的view、viewmodel关系,实现了对画布元素的选取功能,重构了底层依赖,添加了对net .Framework4.6.1以上的Framework类库支持
This commit is contained in:
@@ -1,30 +1,31 @@
|
||||
using Serein.Library.Http;
|
||||
using Serein.NodeFlow;
|
||||
using Serein.NodeFlow.Model;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Enums;
|
||||
using Serein.Library.Attributes;
|
||||
using Serein.Library.Core.NodeFlow;
|
||||
using Serein.Library.Core.NodeFlow.Tool;
|
||||
using static MyDll.PlcDevice;
|
||||
namespace MyDll
|
||||
{
|
||||
# region Web Api 层
|
||||
public class ApiController: ControllerBase
|
||||
{
|
||||
[AutoInjection]
|
||||
public required PlcDevice PLCDevice { get; set; }
|
||||
//public class ApiController: ControllerBase
|
||||
//{
|
||||
// [AutoInjection]
|
||||
// public required PlcDevice PLCDevice { get; set; }
|
||||
|
||||
// example => http://127.0.0.1:8089/api/trigger?type=超宽光电信号&value=网络触发
|
||||
[ApiPost]
|
||||
public dynamic Trigger([IsUrlData] string type, [IsUrlData]string value)
|
||||
{
|
||||
if (Enum.TryParse(type, out SignalType result) && Enum.IsDefined(typeof(SignalType), result))
|
||||
{
|
||||
PLCDevice.TriggerSignal(result, value);// 通过 Web Api 模拟外部输入信号
|
||||
return new {state = "succeed" };
|
||||
}
|
||||
return new { state = "fail" };
|
||||
}
|
||||
// // example => http://127.0.0.1:8089/api/trigger?type=超宽光电信号&value=网络触发
|
||||
// [ApiPost]
|
||||
// public dynamic Trigger([IsUrlData] string type, [IsUrlData]string value)
|
||||
// {
|
||||
// if (Enum.TryParse(type, out SignalType result) && Enum.IsDefined(typeof(SignalType), result))
|
||||
// {
|
||||
// PLCDevice.TriggerSignal(result, value);// 通过 Web Api 模拟外部输入信号
|
||||
// return new {state = "succeed" };
|
||||
// }
|
||||
// return new { state = "fail" };
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region 设备层
|
||||
@@ -69,18 +70,18 @@ namespace MyDll
|
||||
public class LogicControl
|
||||
{
|
||||
[AutoInjection]
|
||||
public required PlcDevice MyPlc { get; set; }
|
||||
public PlcDevice MyPlc { get; set; }
|
||||
|
||||
|
||||
#region 初始化、初始化完成以及退出的事件
|
||||
[MethodDetail(DynamicNodeType.Init)]
|
||||
public void Init(DynamicContext context)
|
||||
[NodeAction(NodeType.Init)]
|
||||
public void Init(IDynamicContext context)
|
||||
{
|
||||
context.InitService<PlcDevice>();
|
||||
context.SereinIoc.Register<PlcDevice>();
|
||||
}
|
||||
|
||||
[MethodDetail(DynamicNodeType.Loading)]
|
||||
public void Loading(DynamicContext context)
|
||||
[NodeAction(NodeType.Loading)]
|
||||
public void Loading(IDynamicContext context)
|
||||
{
|
||||
#region 初始化Web Api、Db
|
||||
|
||||
@@ -124,8 +125,8 @@ namespace MyDll
|
||||
Console.WriteLine("初始化完成");
|
||||
}
|
||||
|
||||
[MethodDetail(DynamicNodeType.Exit)]
|
||||
public void Exit(DynamicContext context)
|
||||
[NodeAction(NodeType.Exit)]
|
||||
public void Exit(IDynamicContext context)
|
||||
{
|
||||
MyPlc.Disconnect();
|
||||
MyPlc.CancelTask();
|
||||
@@ -135,8 +136,8 @@ namespace MyDll
|
||||
|
||||
#region 触发器
|
||||
|
||||
[MethodDetail(DynamicNodeType.Flipflop, "等待信号触发")]
|
||||
public async Task<FlipflopContext> WaitTask(SignalType triggerType = SignalType.光电1)
|
||||
[NodeAction(NodeType.Flipflop, "等待信号触发")]
|
||||
public async Task<IFlipflopContext> WaitTask(SignalType triggerType = SignalType.光电1)
|
||||
{
|
||||
/*if (!Enum.TryParse(triggerValue, out SignalType triggerType) && Enum.IsDefined(typeof(SignalType), triggerType))
|
||||
{
|
||||
@@ -144,50 +145,25 @@ namespace MyDll
|
||||
}*/
|
||||
|
||||
try
|
||||
{
|
||||
//Console.WriteLine($"{Environment.NewLine}订阅信号 - {triggerValue}");
|
||||
|
||||
{
|
||||
var tcs = MyPlc.CreateTcs(triggerType);
|
||||
var result = await tcs.Task;
|
||||
//Interlocked.Increment(ref MyPlc.Count); // 原子自增
|
||||
//Console.WriteLine($"信号触发[{triggerType}] : {MyPlc.Count}{Environment.NewLine} thread :{Thread.CurrentThread.ManagedThreadId}{Environment.NewLine}");
|
||||
return new FlipflopContext(FlowStateType.Succeed, MyPlc.Count);
|
||||
}
|
||||
catch (TcsSignalException)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// await Console.Out.WriteLineAsync($"取消等待信号[{triggerType}]");
|
||||
return new FlipflopContext(FlowStateType.Error);
|
||||
}
|
||||
}
|
||||
[MethodDetail(DynamicNodeType.Flipflop, "等待信号触发")]
|
||||
public async Task<FlipflopContext> WaitTask2(string triggerValue = nameof(SignalType.光电1))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Enum.TryParse(triggerValue, out SignalType triggerType) && Enum.IsDefined(typeof(SignalType), triggerType))
|
||||
{
|
||||
throw new TcsSignalException("parameter[triggerValue] is not a value in an enumeration");
|
||||
}
|
||||
|
||||
var tcs = MyPlc.CreateTcs(triggerType);
|
||||
var result = await tcs.Task;
|
||||
|
||||
Interlocked.Increment(ref MyPlc.Count); // 原子自增
|
||||
Console.WriteLine($"信号触发[{triggerType}] : {MyPlc.Count}");
|
||||
return new FlipflopContext(FlowStateType.Succeed, MyPlc.Count);
|
||||
}
|
||||
catch(TcsSignalException ex)
|
||||
{
|
||||
// await Console.Out.WriteLineAsync($"取消等待信号[{triggerValue}]");
|
||||
return new FlipflopContext(ex.FsState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 动作
|
||||
|
||||
[MethodDetail(DynamicNodeType.Action, "初始化")]
|
||||
[NodeAction(NodeType.Action, "初始化")]
|
||||
public PlcDevice PlcInit(string ip = "192.168.1.1",
|
||||
int port = 6688,
|
||||
string tips = "测试")
|
||||
@@ -197,7 +173,7 @@ namespace MyDll
|
||||
}
|
||||
|
||||
|
||||
[MethodDetail(DynamicNodeType.Action, "自增")]
|
||||
[NodeAction(NodeType.Action, "自增")]
|
||||
public PlcDevice 自增(int number = 1)
|
||||
{
|
||||
MyPlc.Count += number;
|
||||
@@ -205,9 +181,9 @@ namespace MyDll
|
||||
}
|
||||
|
||||
|
||||
[MethodDetail(DynamicNodeType.Action, "模拟循环触发")]
|
||||
public void 模拟循环触发(DynamicContext context,
|
||||
int time = 20,
|
||||
[NodeAction(NodeType.Action, "模拟循环触发")]
|
||||
public void 模拟循环触发(IDynamicContext context,
|
||||
int time = 200,
|
||||
int count = 5,
|
||||
SignalType signal = SignalType.光电1)
|
||||
{
|
||||
@@ -217,24 +193,25 @@ namespace MyDll
|
||||
};
|
||||
_ = context.CreateTimingTask(action, time, count);
|
||||
}
|
||||
[MethodDetail(DynamicNodeType.Action, "重置计数")]
|
||||
[NodeAction(NodeType.Action, "重置计数")]
|
||||
public void 重置计数()
|
||||
{
|
||||
MyPlc.Count = 0;
|
||||
}
|
||||
[MethodDetail(DynamicNodeType.Action, "触发光电")]
|
||||
|
||||
[NodeAction(NodeType.Action, "触发光电1")]
|
||||
public void 光电1信号触发(int data)
|
||||
{
|
||||
MyPlc.Write($"信号源[光电1] - 模拟写入 : {data}{Environment.NewLine}");
|
||||
}
|
||||
|
||||
[MethodDetail(DynamicNodeType.Action, "触发光电")]
|
||||
[NodeAction(NodeType.Action, "触发光电2")]
|
||||
public void 光电2信号触发(int data)
|
||||
{
|
||||
MyPlc.Write($"信号源[光电2] - 模拟写入 : {data}{Environment.NewLine}");
|
||||
}
|
||||
|
||||
[MethodDetail(DynamicNodeType.Action, "触发光电")]
|
||||
[NodeAction(NodeType.Action, "触发光电3")]
|
||||
public void 光电3信号触发(int data)
|
||||
{
|
||||
MyPlc.Write($"信号源[光电3] - 模拟写入 : {data}{Environment.NewLine}");
|
||||
|
||||
Reference in New Issue
Block a user