mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-08 17:06:35 +08:00
重写了触发器底层逻辑
This commit is contained in:
@@ -28,42 +28,19 @@ namespace Net462DllTest.LogicControl
|
||||
}
|
||||
|
||||
|
||||
[NodeAction(NodeType.Flipflop, "等待车位调取命令",ReturnType=typeof(string))]
|
||||
public async Task<IFlipflopContext> GetPparkingSpace(ParkingCommand parkingCommand = ParkingCommand.GetPparkingSpace)
|
||||
[NodeAction(NodeType.Flipflop, "等待车位调取命令")]
|
||||
public async Task<IFlipflopContext<string>> 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<string>(parkingCommand);
|
||||
await Console.Out.WriteLineAsync("收到命令:调取车位,车位号" + spaceNum);
|
||||
return new FlipflopContext<string>(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);
|
||||
|
||||
|
||||
@@ -50,27 +50,20 @@ namespace Net462DllTest.LogicControl
|
||||
|
||||
#region 触发器节点
|
||||
|
||||
[NodeAction(NodeType.Flipflop, "等待变量更新", ReturnType = typeof(int))]
|
||||
public async Task<IFlipflopContext> WaitTask(PlcVarName varName = PlcVarName.ErrorCode)
|
||||
[NodeAction(NodeType.Flipflop, "等待变量更新")]
|
||||
public async Task<IFlipflopContext<dynamic>> 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<dynamic>(varName);
|
||||
|
||||
await Console.Out.WriteLineAsync($"PLC变量触发器[{varName}]传递数据:{triggerData}");
|
||||
return new FlipflopContext<dynamic>(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,25 +34,18 @@ namespace Net462DllTest.LogicControl
|
||||
|
||||
#region 触发器节点
|
||||
|
||||
[NodeAction(NodeType.Flipflop, "等待视图命令", ReturnType = typeof(int))]
|
||||
public async Task<IFlipflopContext> WaitTask(CommandSignal command)
|
||||
[NodeAction(NodeType.Flipflop, "等待视图命令")]
|
||||
public async Task<IFlipflopContext<int>> 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<int>(FlipflopStateType.Cancel, result);
|
||||
}
|
||||
catch (FlipflopException)
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new FlipflopContext(FlipflopStateType.Error);
|
||||
|
||||
return new FlipflopContext<int>(FlipflopStateType.Succeed, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Threading.Tasks;
|
||||
namespace Net462DllTest.Trigger
|
||||
{
|
||||
[AutoRegister]
|
||||
public class PrakingDevice : ChannelFlowTrigger<ParkingCommand>
|
||||
public class PrakingDevice : FlowTrigger<ParkingCommand>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Net462DllTest.Trigger
|
||||
|
||||
|
||||
[AutoRegister]
|
||||
public class SiemensPlcDevice : ChannelFlowTrigger<PlcVarName>
|
||||
public class SiemensPlcDevice : FlowTrigger<PlcVarName>
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Net462DllTest.Trigger
|
||||
/// 视图管理
|
||||
/// </summary>
|
||||
[AutoRegister]
|
||||
public class ViewManagement : ChannelFlowTrigger<CommandSignal>
|
||||
public class ViewManagement : FlowTrigger<CommandSignal>
|
||||
{
|
||||
public ViewManagement(IFlowEnvironment environment)
|
||||
{
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Net462DllTest.ViewModel
|
||||
});
|
||||
CommandGetParkingSpace = new RelayCommand((p) =>
|
||||
{
|
||||
viewManagement.TriggerSignal(SelectedSignal, SpcaeNumber);
|
||||
viewManagement.Trigger(SelectedSignal, SpcaeNumber);
|
||||
});
|
||||
CommandCloseForm = new RelayCommand((p) =>
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Net462DllTest.Web
|
||||
if (EnumHelper.TryConvertEnum<PlcVarName>(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<CommandSignal>(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
|
||||
|
||||
@@ -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<IRouter, Router>();
|
||||
context.Env.IOC.Register<WebApiServer>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
[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<string, Task> SendMsg, Func<object, Task> SendObj)
|
||||
{
|
||||
await Console.Out.WriteLineAsync("开始等待");
|
||||
await Task.Delay(ms);
|
||||
await Console.Out.WriteLineAsync("不再等待");
|
||||
|
||||
await SendMsg("开始刷新数据");
|
||||
//MyPlc.BatchRefresh();
|
||||
await Task.Delay(1000);
|
||||
await SendMsg("刷新完成");
|
||||
await SendObj(plcVarModelDataProxy);
|
||||
await SendMsg("发送完成");
|
||||
}
|
||||
|
||||
|
||||
[AutoSocketHandle]
|
||||
public object ReadVar(PlcVarName varName)
|
||||
{
|
||||
@@ -109,6 +108,14 @@ namespace Net462DllTest.Web
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[AutoSocketHandle(IsReturnValue = false)]
|
||||
public SiemensPlcDevice WriteVar(object value, PlcVarName varName)
|
||||
{
|
||||
MyPlc.Write(varName, value); // 新数据
|
||||
return MyPlc;
|
||||
}
|
||||
[AutoSocketHandle(IsReturnValue = false)]
|
||||
public SiemensPlcDevice PlcInit(SiemensVersion version = SiemensVersion.None,
|
||||
string ip = "192.168.10.100",
|
||||
@@ -142,24 +149,8 @@ namespace Net462DllTest.Web
|
||||
return MyPlc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[AutoSocketHandle(IsReturnValue = false)]
|
||||
public SiemensPlcDevice WriteVar(object value, PlcVarName varName)
|
||||
{
|
||||
MyPlc.Write(varName, value); // 新数据
|
||||
return MyPlc;
|
||||
}
|
||||
|
||||
[AutoSocketHandle]
|
||||
public PlcVarModelDataProxy BatchReadVar(Func<string,Task> send)
|
||||
{
|
||||
send("开始读取");
|
||||
MyPlc.BatchRefresh();
|
||||
send("读取完成");
|
||||
return plcVarModelDataProxy;
|
||||
}
|
||||
|
||||
|
||||
public void OpenTimedRefresh()
|
||||
{
|
||||
Task.Run(async () => await MyPlc.OpenTimedRefreshAsync());
|
||||
|
||||
Reference in New Issue
Block a user