diff --git a/Library.Core/NodeFlow/FlipflopContext.cs b/Library.Core/NodeFlow/FlipflopContext.cs
index f59edf6..3ef05f4 100644
--- a/Library.Core/NodeFlow/FlipflopContext.cs
+++ b/Library.Core/NodeFlow/FlipflopContext.cs
@@ -38,6 +38,11 @@ namespace Serein.Library.Core.NodeFlow
{
// 获取 Task<> 的泛型参数类型
var innerType = type.GetGenericArguments()[0];
+ if (innerType.IsGenericType && type.GetGenericTypeDefinition() == typeof(IFlipflopContext<>))
+ {
+ var flipflop = type.GetGenericArguments()[0];
+ return true;
+ }
// 判断 innerType 是否继承 IFlipflopContext
//if (typeof(IFlipflopContext).IsAssignableFrom(innerType))
@@ -50,11 +55,11 @@ namespace Serein.Library.Core.NodeFlow
//}
// 检查泛型参数是否为 Flipflop<>
- if (innerType == typeof(IFlipflopContext))
+ //if (innerType == typeof(IFlipflopContext))
//if (innerType.IsGenericType && innerType.GetGenericTypeDefinition() == typeof(FlipflopContext<>))
- {
- return true;
- }
+ //{
+ //return true;
+ //}
}
return false;
@@ -64,20 +69,21 @@ namespace Serein.Library.Core.NodeFlow
///
/// 触发器上下文
///
- public class FlipflopContext : IFlipflopContext
+ public class FlipflopContext : IFlipflopContext
{
public FlipflopStateType State { get; set; }
- public TriggerData TriggerData { get; set; }
+ public TriggerType Type { get; set; }
+ public TResult Value { get; set; }
public FlipflopContext(FlipflopStateType ffState)
{
State = ffState;
}
- public FlipflopContext(FlipflopStateType ffState, TriggerData data)
+ public FlipflopContext(FlipflopStateType ffState, TResult value)
{
State = ffState;
- TriggerData = data;
+ Value = value;
}
diff --git a/Library.Framework/NodeFlow/FlipflopContext.cs b/Library.Framework/NodeFlow/FlipflopContext.cs
index 93092db..61136c3 100644
--- a/Library.Framework/NodeFlow/FlipflopContext.cs
+++ b/Library.Framework/NodeFlow/FlipflopContext.cs
@@ -40,13 +40,18 @@ namespace Serein.Library.Framework.NodeFlow
{
// 获取 Task<> 的泛型参数类型
var innerType = type.GetGenericArguments()[0];
-
- // 检查泛型参数是否为 Flipflop<>
- if (innerType == typeof(FlipflopContext))
- //if (innerType.IsGenericType && innerType.GetGenericTypeDefinition() == typeof(FlipflopContext<>))
+ if (innerType.IsGenericType && type.GetGenericTypeDefinition() == typeof(IFlipflopContext<>))
{
+ var flipflop = type.GetGenericArguments()[0];
return true;
}
+
+ //// 检查泛型参数是否为 Flipflop<>
+ //if (innerType == typeof(FlipflopContext))
+ ////if (innerType.IsGenericType && innerType.GetGenericTypeDefinition() == typeof(FlipflopContext<>))
+ //{
+ // return true;
+ //}
}
return false;
@@ -56,24 +61,22 @@ namespace Serein.Library.Framework.NodeFlow
///
/// 触发器上下文
///
- public class FlipflopContext : IFlipflopContext
+ public class FlipflopContext : IFlipflopContext
{
public FlipflopStateType State { get; set; }
- //public TResult? Data { get; set; }
- public TriggerData TriggerData { get; set; }
+
+ public TriggerType Type { get; set; }
+ public TResult Value { get; set; }
public FlipflopContext(FlipflopStateType ffState)
{
State = ffState;
}
- public FlipflopContext(FlipflopStateType ffState, object data)
+
+ public FlipflopContext(FlipflopStateType ffState, TResult value)
{
State = ffState;
- TriggerData = new TriggerData
- {
- Type = TriggerType.External,
- Value = data
- };
+ Value = value;
}
}
diff --git a/Library/Api/IFlipflopContext.cs b/Library/Api/IFlipflopContext.cs
index 88e8947..36134f3 100644
--- a/Library/Api/IFlipflopContext.cs
+++ b/Library/Api/IFlipflopContext.cs
@@ -3,9 +3,24 @@ using Serein.Library.NodeFlow.Tool;
namespace Serein.Library.Api
{
- public interface IFlipflopContext
+ ///
+ /// 触发器必须使用该接口作为返回值,同时必须用Task泛型表示,否则将不会进行等待触发。
+ ///
+ public interface IFlipflopContext
{
+ ///
+ /// 触发器完成的状态(根据业务场景手动设置)
+ ///
FlipflopStateType State { get; set; }
- TriggerData TriggerData { get; set; }
+ ///
+ /// 触发传递的数据
+ ///
+ //TriggerData TriggerData { get; set; }
+
+ TriggerType Type { get; set; }
+ ///
+ /// 触发传递的数据
+ ///
+ TResult Value { get; }
}
}
diff --git a/Library/Enums/NodeType.cs b/Library/Enums/NodeType.cs
index 388049b..a009330 100644
--- a/Library/Enums/NodeType.cs
+++ b/Library/Enums/NodeType.cs
@@ -22,7 +22,7 @@ namespace Serein.Library.Enums
Exit,
///
- /// 触发器(建议手动设置返回类型,方便视图直观)
+ /// 触发器(返回值必须为Task<IFlipflopContext<TResult>>)
///
Flipflop,
///
diff --git a/Library/Network/Http/Attribute.cs b/Library/Network/Http/Attribute.cs
index 8468ba1..485b3f3 100644
--- a/Library/Network/Http/Attribute.cs
+++ b/Library/Network/Http/Attribute.cs
@@ -34,7 +34,7 @@ namespace Serein.Library.Web
}
///
- /// 自动注册控制器
+ /// 标记该类为 Web Api 处理类
///
public class AutoHostingAttribute : Attribute
{
diff --git a/Library/Network/WebSocket/Attribute.cs b/Library/Network/WebSocket/Attribute.cs
index fec73bb..730e38b 100644
--- a/Library/Network/WebSocket/Attribute.cs
+++ b/Library/Network/WebSocket/Attribute.cs
@@ -13,14 +13,14 @@ namespace Serein.Library.Network.WebSocketCommunication
/// 使用方式:
/// [AutoSocketModule(ThemeKey = "theme", DataKey = "data")]
/// public class PlcSocketService : ISocketHandleModule
- /// 类中方法示例:void AddUser(string name,age 35)
+ /// 类中方法示例:void AddUser(string name,int age)
/// Json示例:{ "theme":"AddUser", //【ThemeKey】
/// "data": { // 【DataKey】
/// "name":"张三",
/// "age":35, } }
- /// WebSocket中收到以上该Json时,通过ThemeKey获取到"AddUser",然后找到AddUser()方法,并将"data"作为数据对象,取出相应数据作为入参(args:"张三",35)进行调用(如果有)
+ /// WebSocket中收到以上该Json时,通过ThemeKey获取到"AddUser",然后找到AddUser()方法
+ /// 然后根据方法入参名称,从data对应的json数据中取出"name""age"对应的数据作为入参进行调用。AddUser("张三",35)
///
- ///
///
[AttributeUsage(AttributeTargets.Class)]
public sealed class AutoSocketModuleAttribute : Attribute
diff --git a/Library/Network/WebSocket/WebSocketServer.cs b/Library/Network/WebSocket/WebSocketServer.cs
index 0471a7e..5ae87ed 100644
--- a/Library/Network/WebSocket/WebSocketServer.cs
+++ b/Library/Network/WebSocket/WebSocketServer.cs
@@ -24,7 +24,16 @@ namespace Serein.Library.Network.WebSocketCommunication
{
listener = new HttpListener();
listener.Prefixes.Add(url);
- listener.Start();
+ try
+ {
+ listener.Start();
+ }
+ catch (Exception ex)
+ {
+ await Console.Out.WriteLineAsync(ex.Message);
+ return;
+ }
+
while (true)
{
diff --git a/Library/NodeAttribute.cs b/Library/NodeAttribute.cs
index 16b652e..7a720a4 100644
--- a/Library/NodeAttribute.cs
+++ b/Library/NodeAttribute.cs
@@ -104,10 +104,6 @@ namespace Serein.Library.Attributes
///
public NodeType MethodDynamicType;
///
- /// 显示标注方法返回类型,不影响运行逻辑(用于表示触发器触发后返回的数据)
- ///
- public Type ReturnType;
- ///
/// 暂无意义
///
public string LockName;
diff --git a/Library/Utils/ConvertHelper.cs b/Library/Utils/ConvertHelper.cs
new file mode 100644
index 0000000..c85cb10
--- /dev/null
+++ b/Library/Utils/ConvertHelper.cs
@@ -0,0 +1,209 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Serein.Library.Utils
+{
+ public static class ConvertHelper
+ {
+ public static TResult ToConvert(this object data)
+ {
+ var type = typeof(TResult);
+ if (data is null && type.IsValueType)
+ {
+ return default;
+ }
+ return (TResult)data.ToConvert(type);
+
+ }
+ public static object ToConvert(this object data,Type type)
+ {
+ if (type.IsValueType)
+ {
+ if (data == null)
+ {
+ return Activator.CreateInstance(type);
+ }
+ else
+ {
+ return ConvertHelper.ValueParse(type, data);
+ }
+ }
+ return data;
+
+ }
+
+
+
+ public static T ValueParse(object value) where T : struct, IComparable
+ {
+ string valueStr = value.ToString();
+ return valueStr.ToValueData() ;
+ }
+
+ public static object ValueParse(Type type, object value)
+ {
+ string valueStr = value.ToString();
+ return valueStr.ToValueData(type);
+
+ }
+
+
+ public static T ToValueData(this string valueStr) where T : struct, IComparable
+ {
+ if (string.IsNullOrEmpty(valueStr))
+ {
+ return default(T);
+ }
+ var type = typeof(T);
+ object result;
+ if (type.IsEnum)
+ {
+ result = Enum.Parse(type, valueStr);
+ }
+ else if (type == typeof(bool))
+ {
+ result = bool.Parse(valueStr);
+ }
+ else if (type == typeof(float))
+ {
+ result = float.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(decimal))
+ {
+ result = decimal.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(double))
+ {
+ result = double.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(sbyte))
+ {
+ result = sbyte.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(byte))
+ {
+ result = byte.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(short))
+ {
+ result = short.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(ushort))
+ {
+ result = ushort.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(int))
+ {
+ result = int.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(uint))
+ {
+ result = uint.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(long))
+ {
+ result = long.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(ulong))
+ {
+ result = ulong.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+#if NET6_0 || NET7_0 || NET8_0
+ else if (type == typeof(nint))
+ {
+ result = nint.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(nuint))
+ {
+ result = nuint.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+#endif
+ else
+ {
+ throw new ArgumentException("非预期值类型");
+ }
+
+ return (T)result;
+ }
+ public static object ToValueData(this string valueStr, Type type)
+ {
+ if (string.IsNullOrEmpty(valueStr))
+ {
+ return Activator.CreateInstance(type);
+ }
+ object result;
+ if (type.IsEnum)
+ {
+ result = Enum.Parse(type, valueStr);
+ }
+ else if (type == typeof(bool))
+ {
+ result = bool.Parse(valueStr);
+ }
+ else if (type == typeof(float))
+ {
+ result = float.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(decimal))
+ {
+ result = decimal.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(double))
+ {
+ result = double.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(sbyte))
+ {
+ result = sbyte.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(byte))
+ {
+ result = byte.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(short))
+ {
+ result = short.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(ushort))
+ {
+ result = ushort.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(int))
+ {
+ result = int.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(uint))
+ {
+ result = uint.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(long))
+ {
+ result = long.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(ulong))
+ {
+ result = ulong.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+#if NET6_0 || NET7_0 || NET8_0
+ else if (type == typeof(nint))
+ {
+ result = nint.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+ else if (type == typeof(nuint))
+ {
+ result = nuint.Parse(valueStr, CultureInfo.InvariantCulture);
+ }
+#endif
+ else
+ {
+ throw new ArgumentException("非预期值类型");
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/Library/Utils/ExpressionHelper.cs b/Library/Utils/ExpressionHelper.cs
index 88541d3..02c2615 100644
--- a/Library/Utils/ExpressionHelper.cs
+++ b/Library/Utils/ExpressionHelper.cs
@@ -358,8 +358,8 @@ namespace Serein.Library.Utils
);
// 创建 lambda 表达式
- var lambda = Expression.Lambda>>(
- Expression.Convert(methodCall, typeof(Task)),
+ var lambda = Expression.Lambda>>>(
+ Expression.Convert(methodCall, typeof(Task>)),
instanceParam,
argsParam
);
diff --git a/Library/Utils/ChannelFlowTrigger.cs b/Library/Utils/FlowTrigger.cs
similarity index 63%
rename from Library/Utils/ChannelFlowTrigger.cs
rename to Library/Utils/FlowTrigger.cs
index 9363c0b..384975c 100644
--- a/Library/Utils/ChannelFlowTrigger.cs
+++ b/Library/Utils/FlowTrigger.cs
@@ -1,5 +1,7 @@
-using System;
+using Serein.Library.Utils;
+using System;
using System.Collections.Concurrent;
+using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using System.Threading.Channels;
@@ -22,28 +24,29 @@ namespace Serein.Library.NodeFlow.Tool
Overtime
}
- public class TriggerData
+ public class TriggerResult
{
public TriggerType Type { get; set; }
- public object Value { get; set; }
+ public T Value { get; set; }
}
///
- /// 信号触发器类,带有消息广播功能
+ /// 信号触发器类,带有消息广播功能。
+ /// 使用枚举作为标记,创建
///
- public class ChannelFlowTrigger where TSignal : struct, Enum
+ public class FlowTrigger where TSignal : struct, Enum
{
// 使用并发字典管理每个信号对应的广播列表
- private readonly ConcurrentDictionary> _subscribers = new ConcurrentDictionary>();
+ private readonly ConcurrentDictionary> _subscribers = new ConcurrentDictionary>();
///
/// 获取或创建指定信号的 Subject(消息广播者)
///
/// 枚举信号标识符
/// 对应的 Subject
- private Subject GetOrCreateSubject(TSignal signal)
+ private Subject<(TriggerType, object)> GetOrCreateSubject(TSignal signal)
{
- return _subscribers.GetOrAdd(signal, _ => new Subject());
+ return _subscribers.GetOrAdd(signal, _ => new Subject<(TriggerType, object)>());
}
///
@@ -52,9 +55,10 @@ namespace Serein.Library.NodeFlow.Tool
/// 枚举信号标识符
/// 订阅者
/// 取消订阅的句柄
- public IDisposable Subscribe(TSignal signal, IObserver observer)
+ public IDisposable Subscribe(TSignal signal, IObserver<(TriggerType, object)> observer)
{
var subject = GetOrCreateSubject(signal);
+ // (IObserver<(TriggerType, object)>)
return subject.Subscribe(observer); // 返回取消订阅的句柄
}
@@ -63,8 +67,8 @@ namespace Serein.Library.NodeFlow.Tool
///
/// 枚举信号标识符
/// 超时时间
- /// 等待任务
- public async Task CreateChannelWithTimeoutAsync(TSignal signal, TimeSpan outTime, TResult outValue)
+ /// 等待任务,返回值为:状态(超时触发,手动触发),数据(超时触发时会使用设置好的数据)
+ public async Task<(TriggerType, TResult)> CreateTaskWithTimeoutAsync(TSignal signal, TimeSpan outTime, TResult outValue)
{
var subject = GetOrCreateSubject(signal);
var cts = new CancellationTokenSource();
@@ -77,12 +81,7 @@ namespace Serein.Library.NodeFlow.Tool
await Task.Delay(outTime, cts.Token);
if (!cts.IsCancellationRequested) // 如果还没有被取消
{
- TriggerData triggerData = new TriggerData()
- {
- Value = outValue,
- Type = TriggerType.Overtime,
- };
- subject.OnNext(triggerData); // 广播给所有订阅者
+ subject.OnNext((TriggerType.Overtime, outValue)); // 广播给所有订阅者
subject.OnCompleted(); // 通知订阅结束
}
}
@@ -96,39 +95,54 @@ namespace Serein.Library.NodeFlow.Tool
}
}, cts.Token);
- // 返回一个等待的任务
- return await WaitForSignalAsync(signal);
+ var result = await WaitSignalAsync(signal);// 返回一个可以超时触发的等待任务
+ return result;
}
+
+
+ ///
+ /// 创建等待任务,触发时通知所有订阅者
+ ///
+ /// 枚举信号标识符
+ /// 超时时间
+ /// 等待任务
+ public async Task CreateTaskAsync(TSignal signal)
+ {
+ var subject = GetOrCreateSubject(signal);
+ (_,var result) = await WaitSignalAsync(signal);
+
+ return result;// 返回一个等待的任务
+ }
+
+
///
/// 等待指定信号的触发
///
/// 枚举信号标识符
/// 等待任务
- public async Task WaitForSignalAsync(TSignal signal)
+ public async Task<(TriggerType, TResult)> WaitSignalAsync(TSignal signal)
{
- var taskCompletionSource = new TaskCompletionSource();
- var subscription = Subscribe(signal, new Observer(taskCompletionSource.SetResult));
- var result = await taskCompletionSource.Task;
+ var taskCompletionSource = new TaskCompletionSource<(TriggerType, object)>();
+ var subscription = Subscribe(signal, new Observer<(TriggerType, object)>(taskCompletionSource.SetResult));
+ (var type,var result) = await taskCompletionSource.Task;
subscription.Dispose(); // 取消订阅
- return result;
+
+ return (type, result.ToConvert());
}
+
+
///
/// 手动触发信号,并广播给所有订阅者
///
/// 枚举信号标识符
/// 是否成功触发
- public bool TriggerSignal(TSignal signal, TResult value)
+ public bool Trigger(TSignal signal, TResult value)
{
if (_subscribers.TryGetValue(signal, out var subject))
{
- TriggerData triggerData = new TriggerData()
- {
- Value = value,
- Type = TriggerType.External,
- };
- subject.OnNext(triggerData); // 广播给所有订阅者
+ subject.OnNext((TriggerType.External, value)); // 广播给所有订阅者
//subject.OnCompleted(); // 通知订阅结束
return true;
}
diff --git a/Net462DllTest/LogicControl/ParkingLogicControl.cs b/Net462DllTest/LogicControl/ParkingLogicControl.cs
index 8976855..c90fd79 100644
--- a/Net462DllTest/LogicControl/ParkingLogicControl.cs
+++ b/Net462DllTest/LogicControl/ParkingLogicControl.cs
@@ -28,42 +28,19 @@ namespace Net462DllTest.LogicControl
}
- [NodeAction(NodeType.Flipflop, "等待车位调取命令",ReturnType=typeof(string))]
- public async Task GetPparkingSpace(ParkingCommand parkingCommand = ParkingCommand.GetPparkingSpace)
+ [NodeAction(NodeType.Flipflop, "等待车位调取命令")]
+ public async Task> GetPparkingSpace(ParkingCommand parkingCommand = ParkingCommand.GetPparkingSpace)
{
- try
- {
- TriggerData triggerData = await PrakingDevice.CreateChannelWithTimeoutAsync(parkingCommand, TimeSpan.FromMinutes(120), 0);
- if (triggerData.Type == TriggerType.Overtime)
- {
- throw new FlipflopException("超时取消");
- }
- if(triggerData.Value is string spaceNum)
- {
- await Console.Out.WriteLineAsync("收到命令:调取车位,车位号"+ spaceNum);
- return new FlipflopContext(FlipflopStateType.Succeed, spaceNum);
- }
- else
- {
- throw new FlipflopException("并非车位号");
- }
-
- }
- catch (FlipflopException)
- {
- throw;
- }
- catch (Exception)
- {
- return new FlipflopContext(FlipflopStateType.Error);
- }
+ var spaceNum = await PrakingDevice.CreateTaskAsync(parkingCommand);
+ await Console.Out.WriteLineAsync("收到命令:调取车位,车位号" + spaceNum);
+ return new FlipflopContext(FlipflopStateType.Succeed, spaceNum);
}
[NodeAction(NodeType.Action, "调取指定车位")]
public void Storage(string spaceNum = "101")
{
- if (PrakingDevice.TriggerSignal(ParkingCommand.GetPparkingSpace, spaceNum))
+ if (PrakingDevice.Trigger(ParkingCommand.GetPparkingSpace, spaceNum))
{
Console.WriteLine("发送命令成功:调取车位" + spaceNum);
diff --git a/Net462DllTest/LogicControl/PlcLogicControl.cs b/Net462DllTest/LogicControl/PlcLogicControl.cs
index db48bfd..d985a72 100644
--- a/Net462DllTest/LogicControl/PlcLogicControl.cs
+++ b/Net462DllTest/LogicControl/PlcLogicControl.cs
@@ -50,27 +50,20 @@ namespace Net462DllTest.LogicControl
#region 触发器节点
- [NodeAction(NodeType.Flipflop, "等待变量更新", ReturnType = typeof(int))]
- public async Task WaitTask(PlcVarName varName = PlcVarName.ErrorCode)
+ [NodeAction(NodeType.Flipflop, "等待变量更新")]
+ public async Task> WaitTask(PlcVarName varName = PlcVarName.ErrorCode)
{
try
{
- TriggerData triggerData = await MyPlc.CreateChannelWithTimeoutAsync(varName, TimeSpan.FromMinutes(120), 0);
- if (triggerData.Type == TriggerType.Overtime)
- {
- throw new FlipflopException("超时取消");
- }
- await Console.Out.WriteLineAsync($"PLC变量触发器[{varName}]传递数据:{triggerData.Value}");
- return new FlipflopContext(FlipflopStateType.Succeed, triggerData.Value);
- }
- catch (FlipflopException)
- {
- throw;
+ var triggerData = await MyPlc.CreateTaskAsync(varName);
+
+ await Console.Out.WriteLineAsync($"PLC变量触发器[{varName}]传递数据:{triggerData}");
+ return new FlipflopContext(FlipflopStateType.Succeed, triggerData);
}
catch (Exception)
{
- return new FlipflopContext(FlipflopStateType.Error);
+ throw;
}
}
@@ -94,8 +87,8 @@ namespace Net462DllTest.LogicControl
string ip = "192.168.10.100",
int port = 102)
{
- MyPlc.Model.Set(PlcVarName.DoorVar,(Int16)1);
- MyPlc.Model.Get(PlcVarName.DoorVar);
+ //MyPlc.Model.Set(PlcVarName.DoorVar,(Int16)1);
+ //MyPlc.Model.Get(PlcVarName.DoorVar);
if (MyPlc.Client is null)
{
try
@@ -144,7 +137,7 @@ namespace Net462DllTest.LogicControl
[NodeAction(NodeType.Action, "批量读取")]
public PlcVarModelDataProxy BatchReadVar()
{
- MyPlc.BatchRefresh();
+ //MyPlc.BatchRefresh();
return plcVarModelDataProxy;
}
diff --git a/Net462DllTest/LogicControl/ViewLogicControl.cs b/Net462DllTest/LogicControl/ViewLogicControl.cs
index 164a60f..50d1844 100644
--- a/Net462DllTest/LogicControl/ViewLogicControl.cs
+++ b/Net462DllTest/LogicControl/ViewLogicControl.cs
@@ -34,25 +34,18 @@ namespace Net462DllTest.LogicControl
#region 触发器节点
- [NodeAction(NodeType.Flipflop, "等待视图命令", ReturnType = typeof(int))]
- public async Task WaitTask(CommandSignal command)
+ [NodeAction(NodeType.Flipflop, "等待视图命令")]
+ public async Task> WaitTask(CommandSignal command)
{
- try
+ (var type, var result) = await ViewManagement.CreateTaskWithTimeoutAsync(command, TimeSpan.FromHours(10), 0);
+ if (type == TriggerType.Overtime)
{
- TriggerData triggerData = await ViewManagement.CreateChannelWithTimeoutAsync(command, TimeSpan.FromHours(10), 0);
- if (triggerData.Type == TriggerType.Overtime)
- {
- return new FlipflopContext(FlipflopStateType.Cancel, triggerData.Value);
- }
- return new FlipflopContext(FlipflopStateType.Succeed, triggerData.Value);
+ return new FlipflopContext(FlipflopStateType.Cancel, result);
}
- catch (FlipflopException)
+ else
{
- throw;
- }
- catch (Exception)
- {
- return new FlipflopContext(FlipflopStateType.Error);
+
+ return new FlipflopContext(FlipflopStateType.Succeed, result);
}
}
diff --git a/Net462DllTest/Trigger/PrakingDevice.cs b/Net462DllTest/Trigger/PrakingDevice.cs
index 10420a6..6295a3b 100644
--- a/Net462DllTest/Trigger/PrakingDevice.cs
+++ b/Net462DllTest/Trigger/PrakingDevice.cs
@@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace Net462DllTest.Trigger
{
[AutoRegister]
- public class PrakingDevice : ChannelFlowTrigger
+ public class PrakingDevice : FlowTrigger
{
}
diff --git a/Net462DllTest/Trigger/SiemensPlcDevice.cs b/Net462DllTest/Trigger/SiemensPlcDevice.cs
index 07e327e..b73220d 100644
--- a/Net462DllTest/Trigger/SiemensPlcDevice.cs
+++ b/Net462DllTest/Trigger/SiemensPlcDevice.cs
@@ -24,7 +24,7 @@ namespace Net462DllTest.Trigger
[AutoRegister]
- public class SiemensPlcDevice : ChannelFlowTrigger
+ public class SiemensPlcDevice : FlowTrigger
{
public SiemensClient Client { get; set; }
public SiemensVersion Version { get; set; }
@@ -202,7 +202,7 @@ namespace Net462DllTest.Trigger
if (isNotification)
{
Console.WriteLine($"VarName: {signal}\t\tOld Data: {oldData}\tNew Data: {newData}");
- TriggerSignal(signal, newData);
+ Trigger(signal, newData);
}
diff --git a/Net462DllTest/Trigger/ViewManagement.cs b/Net462DllTest/Trigger/ViewManagement.cs
index 4fe192b..6c24936 100644
--- a/Net462DllTest/Trigger/ViewManagement.cs
+++ b/Net462DllTest/Trigger/ViewManagement.cs
@@ -15,7 +15,7 @@ namespace Net462DllTest.Trigger
/// 视图管理
///
[AutoRegister]
- public class ViewManagement : ChannelFlowTrigger
+ public class ViewManagement : FlowTrigger
{
public ViewManagement(IFlowEnvironment environment)
{
diff --git a/Net462DllTest/ViewModel/FromWorkBenchViewModel.cs b/Net462DllTest/ViewModel/FromWorkBenchViewModel.cs
index 4f60a8c..881c3c6 100644
--- a/Net462DllTest/ViewModel/FromWorkBenchViewModel.cs
+++ b/Net462DllTest/ViewModel/FromWorkBenchViewModel.cs
@@ -131,7 +131,7 @@ namespace Net462DllTest.ViewModel
});
CommandGetParkingSpace = new RelayCommand((p) =>
{
- viewManagement.TriggerSignal(SelectedSignal, SpcaeNumber);
+ viewManagement.Trigger(SelectedSignal, SpcaeNumber);
});
CommandCloseForm = new RelayCommand((p) =>
{
diff --git a/Net462DllTest/Web/FlowController.cs b/Net462DllTest/Web/FlowController.cs
index aa1dd90..6035c99 100644
--- a/Net462DllTest/Web/FlowController.cs
+++ b/Net462DllTest/Web/FlowController.cs
@@ -42,7 +42,7 @@ namespace Net462DllTest.Web
if (EnumHelper.TryConvertEnum(var,out var signal))
{
Console.WriteLine($"外部触发 {signal} 信号,信号内容 : {value} ");
- plcDevice.TriggerSignal(signal, value);// 通过 Web Api 模拟外部输入信号
+ plcDevice.Trigger(signal, value);// 通过 Web Api 模拟外部输入信号
return new { state = "succeed" };
}
else
@@ -67,7 +67,7 @@ namespace Net462DllTest.Web
if (EnumHelper.TryConvertEnum(command, out var signal))
{
Console.WriteLine($"外部触发 {signal} 信号,信号内容 : {value} ");
- viewManagement.TriggerSignal(signal, value);// 通过 Web Api 模拟外部输入信号
+ viewManagement.Trigger(signal, value);// 通过 Web Api 模拟外部输入信号
return new { state = "succeed" };
}
else
diff --git a/Net462DllTest/Web/PlcSocketService.cs b/Net462DllTest/Web/PlcSocketService.cs
index 0c5f976..5821118 100644
--- a/Net462DllTest/Web/PlcSocketService.cs
+++ b/Net462DllTest/Web/PlcSocketService.cs
@@ -16,8 +16,8 @@ using System.Threading.Tasks;
namespace Net462DllTest.Web
{
- [DynamicFlow("[PlcSocketService]")]
[AutoRegister]
+ [DynamicFlow("[PlcSocketService]")]
[AutoSocketModule(ThemeKey = "theme", DataKey = "data")]
public class PlcSocketService : ISocketHandleModule
{
@@ -42,8 +42,6 @@ namespace Net462DllTest.Web
context.Env.IOC.Register();
context.Env.IOC.Register();
-
-
}
[NodeAction(NodeType.Loading)] // Loading 初始化完成已注入依赖项,可以开始逻辑上的操作
@@ -90,17 +88,18 @@ namespace Net462DllTest.Web
}
#endregion
-
-
- [NodeAction(NodeType.Action, "等待")]
- public async Task Delay(int ms = 5000)
+ [AutoSocketHandle]
+ public async Task BatchReadVar(Func SendMsg, Func