diff --git a/Net462DllTest/Enums/FromValue.cs b/Net462DllTest/Enums/FromValue.cs deleted file mode 100644 index 2c0a3f9..0000000 --- a/Net462DllTest/Enums/FromValue.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Serein.Library; - -namespace Net462DllTest.Signal -{ - /*public enum FromValue - { - [BindValue(typeof(FromWorkBenchView))] - FromWorkBenchView, - [BindValue(typeof(TestFormView))] - TestFormView, - }*/ -} diff --git a/Net462DllTest/Enums/PlcState.cs b/Net462DllTest/Enums/PlcState.cs deleted file mode 100644 index 52a7be5..0000000 --- a/Net462DllTest/Enums/PlcState.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Net462DllTest.Enums -{ - public enum PlcState - { - /// - /// 关机 - /// - PowerOff, - /// - /// 正在运行 - /// - Runing, - /// - /// 发生异常 - /// - Error, - /// - /// 维护中 - /// - Maintenance, - } -} diff --git a/Net462DllTest/Enums/PlcVarName.cs b/Net462DllTest/Enums/PlcVarName.cs deleted file mode 100644 index 17a9ba7..0000000 --- a/Net462DllTest/Enums/PlcVarName.cs +++ /dev/null @@ -1,129 +0,0 @@ -using IoTClient.Enums; -using Net462DllTest.Signal; -using static Net462DllTest.Signal.PlcVarInfo; - -namespace Net462DllTest.Enums -{ - - - - /// - /// PLC变量信息 - /// - public enum PlcVarName - { - /// - /// 车位号 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V100", OnNotificationType.OnChanged)] - SpaceNum, - - /// - /// 上位机指令 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V102", OnNotificationType.OnChanged)] - CmdForPLC, - - /// - /// PLC当前存取车位号 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V110", OnNotificationType.OnChanged)] - DoingSpaceNum, - - /// - /// 下位机状态 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V112", OnNotificationType.OnChanged)] - PLCState, - - /// - /// 门1正常待机车位号,存车完成地面车位0 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V114", OnNotificationType.OnChanged)] - Door1CurSpaceNum, - - /// - /// 门2正常待机车位号,存车完成地面车位0 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V124", OnNotificationType.OnChanged)] - Door2CurSpaceNum, - - /// - /// 下位机运行模式 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V116", OnNotificationType.OnChanged)] - PLCRunMode, - - /// - /// 执行的门号 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V104", OnNotificationType.OnChanged)] - DoorVar, - - /// - /// 门1是否开到位 - /// - [PlcVarInfo(DataTypeEnum.Bool, "V207.0", OnNotificationType.OnChanged)] - IsDoor1OpenDone, - - /// - /// 门1是否关到位 - /// - [PlcVarInfo(DataTypeEnum.Bool, "V207.1", OnNotificationType.OnChanged)] - IsDoor1ClosedDone, - - - /// - /// 门2是否开到位 - /// - [PlcVarInfo(DataTypeEnum.Bool, "V207.3", OnNotificationType.OnChanged)] - IsDoor2OpenDone, - - /// - /// 门2是否关到位 - /// - [PlcVarInfo(DataTypeEnum.Bool, "V207.4", OnNotificationType.OnChanged)] - IsDoor2ClosedDone, - - /// - /// 通道1是否有车 - /// - [PlcVarInfo(DataTypeEnum.Bool, "V284.7", OnNotificationType.OnChanged)] - HasCarInTone1, - - /// - /// 通道2是否有车 - /// - [PlcVarInfo(DataTypeEnum.Bool, "V286.7", OnNotificationType.OnChanged)] - HasCarInTone2, - - /// - /// 下位机异常代码 - /// - [PlcVarInfo(DataTypeEnum.Int16, "V2", OnNotificationType.OnChanged)] - ErrorCode, - - /// - /// 2层以上的空板是否在待机 - /// - [PlcVarInfo(DataTypeEnum.Bool, "V200.7", OnNotificationType.OnChanged)] - IsOver2FlowStanded, - - /// - /// 1号门指示灯 - /// - [PlcVarInfo(DataTypeEnum.Bool, "Q17.0", OnNotificationType.OnChanged)] - Gate1Light, - - /// - /// 2号门指示灯 - /// - [PlcVarInfo(DataTypeEnum.Bool, "Q17.3", OnNotificationType.OnChanged)] - Gate2Light, - } - - - - - -} diff --git a/Net462DllTest/LogicControl/ParkingLogicControl.cs b/Net462DllTest/LogicControl/ParkingLogicControl.cs deleted file mode 100644 index 70b9260..0000000 --- a/Net462DllTest/LogicControl/ParkingLogicControl.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Net462DllTest.Trigger; -using Serein.Library; -using Serein.Library.Api; -using System; -using System.Threading.Tasks; - -namespace Net462DllTest.LogicControl -{ - - public enum ParkingCommand - { - GetPparkingSpace, - } - - [AutoRegister] - [DynamicFlow("[Parking]")] - public class ParkingLogicControl - { - private readonly PrakingDevice PrakingDevice; - - public ParkingLogicControl(PrakingDevice PrakingDevice) - { - this.PrakingDevice = PrakingDevice; - } - - - [NodeAction(NodeType.Flipflop, "等待车位调取命令")] - public async Task> GetPparkingSpace(ParkingCommand parkingCommand = ParkingCommand.GetPparkingSpace) - { - var result = await PrakingDevice.WaitTriggerAsync(parkingCommand); - await Console.Out.WriteLineAsync("收到命令:调取车位,车位号" + result.Value); - return new FlipflopContext(FlipflopStateType.Succeed, result.Value); - } - - - [NodeAction(NodeType.Action, "调取指定车位")] - public async Task Storage(string spaceNum = "101") - { - if (await PrakingDevice.InvokeTriggerAsync(ParkingCommand.GetPparkingSpace, spaceNum)) - { - Console.WriteLine("发送命令成功:调取车位" + spaceNum); - - } - else - { - Console.WriteLine("发送命令失败:调取车位" + spaceNum); - } - } - - - } -} diff --git a/Net462DllTest/LogicControl/PlcLogicControl.cs b/Net462DllTest/LogicControl/PlcLogicControl.cs deleted file mode 100644 index d17a0d0..0000000 --- a/Net462DllTest/LogicControl/PlcLogicControl.cs +++ /dev/null @@ -1,152 +0,0 @@ -using IoTClient.Common.Enums; -using Net462DllTest.Enums; -using Net462DllTest.Model; -using Net462DllTest.Trigger; -using Serein.Library; -using Serein.Library.Api; -using System; -using System.Threading.Tasks; - -namespace Net462DllTest.LogicControl -{ - [AutoRegister] - [DynamicFlow("[SiemensPlc]")] - public class PlcLogicControl - { - public Guid HandleGuid { get; } = new Guid(); - - private readonly SiemensPlcDevice MyPlc; - private readonly PlcVarModelDataProxy plcVarModelDataProxy; - - public PlcLogicControl(SiemensPlcDevice MyPlc, - PlcVarModelDataProxy plcVarModelDataProxy) - { - this.MyPlc = MyPlc; - this.plcVarModelDataProxy = plcVarModelDataProxy; - } - - #region 初始化 - [NodeAction(NodeType.Loading)] // Loading 初始化完成已注入依赖项,可以开始逻辑上的操作 - public void Loading(IFlowContext context) - { - - - } - - [NodeAction(NodeType.Exit)] // 流程结束时自动执行 - public void Exit(IFlowContext context) - { - MyPlc.Close(); - MyPlc.CancelAllTrigger(); - } - - #endregion - - #region 触发器节点 - - [NodeAction(NodeType.Flipflop, "等待变量更新")] - public async Task> WaitTask(PlcVarName varName = PlcVarName.ErrorCode) - { - try - { - var triggerData = await MyPlc.WaitTriggerAsync(varName); - await Console.Out.WriteLineAsync($"PLC变量触发器[{varName}]传递数据:{triggerData}"); - return new FlipflopContext(FlipflopStateType.Succeed, triggerData); - } - catch (Exception) - { - throw; - } - - } - - #endregion - - #region 动作节点 - - [NodeAction(NodeType.Action, "等待")] - public async Task Delay(int ms = 5000) - { - await Console.Out.WriteLineAsync("开始等待"); - await Task.Delay(ms); - await Console.Out.WriteLineAsync("不再等待"); - - } - - - [NodeAction(NodeType.Action, "PLC初始化")] - public SiemensPlcDevice PlcInit(SiemensVersion version = SiemensVersion.None, - string ip = "192.168.10.100", - int port = 102) - { - //MyPlc.Model.Set(PlcVarName.DoorVar,(Int16)1); - //MyPlc.Model.Get(PlcVarName.DoorVar); - if (MyPlc.Client is null) - { - try - { - MyPlc.Init(version, ip, port); - Console.WriteLine($"西门子PLC初始化成功[{version},{ip}:{port}]"); - } - catch (Exception ex) - { - Console.WriteLine($"西门子PLC[{version},{ip}:{port}]初始化异常:{ex.Message}"); - } - } - else - { - Console.WriteLine( $"西门子PLC已经初始化[{version},{ip}:{port}]"); - } - return MyPlc; - } - - [NodeAction(NodeType.Action, "设置PLC状态")] - public SiemensPlcDevice SetState(PlcState state = PlcState.PowerOff) - { - var oldState = MyPlc.State; - MyPlc.State = state; - Console.WriteLine($"PLC状态从[{oldState}]转为[{state}]"); - return MyPlc; - } - - - [NodeAction(NodeType.Action, "PLC获取变量")] - public object ReadVar(PlcVarName varName) - { - var result = MyPlc.Read(varName); - Console.WriteLine($"获取变量成功:({varName})\t result = {result}"); - return result; - } - - - [NodeAction(NodeType.Action, "PLC写入变量")] - public SiemensPlcDevice WriteVar(object value, PlcVarName varName) - { - MyPlc.Write(varName, value); // 新数据 - return MyPlc; - } - - [NodeAction(NodeType.Action, "批量读取")] - public PlcVarModelDataProxy BatchReadVar() - { - //MyPlc.BatchRefresh(); - return plcVarModelDataProxy; - } - - - [NodeAction(NodeType.Action, "开启定时刷新")] - public void OpenTimedRefresh() - { - Task.Run(async () => await MyPlc.OpenTimedRefreshAsync()); - } - - [NodeAction(NodeType.Action, "关闭定时刷新")] - public void CloseTimedRefresh() - { - MyPlc.CloseTimedRefresh(); - } - - - #endregion - } -} diff --git a/Net462DllTest/Main.cs b/Net462DllTest/Main.cs deleted file mode 100644 index 881e7a9..0000000 --- a/Net462DllTest/Main.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Serein.Library; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Net462DllTest.Properties -{ - /* - 理想的项目架构: - - 每一种功能拆分为新的项目 - - FlowEnv - LoginControl: - - - LoginControl - ↙ ↘ - (View-Interaction) (Node-Interaction) - ↓ ↕ - View ←→ ViewModel ←→ Trigger ← SingleEnum - ↓ ↓ ↖ - ↓ ↓ ↖ - Node →→→ Model → Event(OnDataChanged) - - - 视图驱动触发器,触发器驱动数据。 - 数据驱动触发器,触发器驱动视图。 - - 所以,这个结构≈事件驱动。 - - - 动态的配置事件触发的原因、过程与结果。 - - */ - - public class My - { - public void Run() - { - - } - } -} diff --git a/Net462DllTest/Model/PlcVarModel.cs b/Net462DllTest/Model/PlcVarModel.cs deleted file mode 100644 index c5a957d..0000000 --- a/Net462DllTest/Model/PlcVarModel.cs +++ /dev/null @@ -1,229 +0,0 @@ -using Net462DllTest.Enums; -using Serein.Library; -using System; - -namespace Net462DllTest.Model -{ - /// - /// PLC变量 - /// - [AutoRegister] - public class PlcVarModel - { - /// - /// 车位号 - /// - [BindValue(PlcVarName.SpaceNum)] - public Int16 SpaceNum { get; set; } - - /// - /// 上位机指令 - /// - [BindValue(PlcVarName.CmdForPLC)] - public Int16 CmdForPLC { get; set; } - - /// - /// PLC当前存取车位号 - /// - [BindValue(PlcVarName.DoingSpaceNum)] - public Int16 DoingSpaceNum { get; set; } - - /// - /// 下位机状态 - /// - [BindValue(PlcVarName.PLCState)] - public Int16 PLCState { get; set; } - - /// - /// 门1正常待机车位号,存车完成地面车位0 - /// - [BindValue(PlcVarName.Door1CurSpaceNum)] - public Int16 Door1CurSpaceNum { get; set; } - - /// - /// 门2正常待机车位号,存车完成地面车位0 - /// - [BindValue(PlcVarName.Door2CurSpaceNum)] - public Int16 Door2CurSpaceNum { get; set; } - - /// - /// 下位机运行模式 - /// - [BindValue(PlcVarName.PLCRunMode)] - public Int16 PLCRunMode { get; set; } - - /// - /// 执行的门号 - /// - [BindValue(PlcVarName.DoorVar)] - public Int16 DoorVar { get; set; } - - /// - /// 门1是否开到位 - /// - [BindValue(PlcVarName.IsDoor1OpenDone)] - public bool IsDoor1OpenDone { get; set; } - - /// - /// 门1是否关到位 - /// - [BindValue(PlcVarName.IsDoor1ClosedDone)] - public bool IsDoor1ClosedDone { get; set; } - - - /// - /// 门2是否开到位 - /// - [BindValue(PlcVarName.IsDoor2OpenDone)] - public bool IsDoor2OpenDone { get; set; } - - /// - /// 门2是否关到位 - /// - [BindValue(PlcVarName.IsDoor2ClosedDone)] - public bool IsDoor2ClosedDone { get; set; } - - /// - /// 通道1是否有车 - /// - [BindValue(PlcVarName.HasCarInTone1)] - public bool HasCarInTone1 { get; set; } - - /// - /// 通道2是否有车 - /// - [BindValue(PlcVarName.HasCarInTone2)] - public bool HasCarInTone2 { get; set; } - - /// - /// 下位机异常代码 - /// - [BindValue(PlcVarName.ErrorCode)] - public Int16 ErrorCode { get; set; } - - /// - /// 2层以上的空板是否在待机 - /// - [BindValue(PlcVarName.IsOver2FlowStanded)] - public bool IsOver2FlowStanded { get; set; } - - /// - /// 1号门指示灯 - /// - [BindValue(PlcVarName.Gate1Light)] - public bool Gate1Light { get; set; } - - /// - /// 2号门指示灯 - /// - [BindValue(PlcVarName.Gate2Light)] - public bool Gate2Light { get; set; } - } - - - - /// - /// 数据代理,防止View修改 - /// - [AutoRegister] - public class PlcVarModelDataProxy - { - private readonly PlcVarModel plcVarModel; - public PlcVarModelDataProxy(PlcVarModel plcVarModel) - { - this.plcVarModel = plcVarModel; - } - /// - /// 车位号 - /// - public Int16 SpaceNum { get => plcVarModel.SpaceNum; } - - /// - /// 上位机指令 - /// - public Int16 CmdForPLC { get => plcVarModel.CmdForPLC; } - - /// - /// PLC当前存取车位号 - /// - public Int16 DoingSpaceNum { get => plcVarModel.DoingSpaceNum; } - - /// - /// 下位机状态 - /// - public Int16 PLCState { get => plcVarModel.PLCState; } - - /// - /// 门1正常待机车位号,存车完成地面车位0 - /// - public Int16 Door1CurSpaceNum { get => plcVarModel.Door1CurSpaceNum; } - - /// - /// 门2正常待机车位号,存车完成地面车位0 - /// - public Int16 Door2CurSpaceNum { get => plcVarModel.Door2CurSpaceNum; } - - /// - /// 下位机运行模式 - /// - public Int16 PLCRunMode { get => plcVarModel.PLCRunMode; } - - /// - /// 执行的门号 - /// - public Int16 DoorVar { get => plcVarModel.DoorVar; } - - /// - /// 门1是否开到位 - /// - public bool IsDoor1OpenDone { get => plcVarModel.IsDoor1OpenDone; } - - /// - /// 门1是否关到位 - /// - public bool IsDoor1ClosedDone { get => plcVarModel.IsDoor1ClosedDone; } - - - /// - /// 门2是否开到位 - /// - public bool IsDoor2OpenDone { get => plcVarModel.IsDoor2OpenDone; } - - /// - /// 门2是否关到位 - /// - public bool IsDoor2ClosedDone { get => plcVarModel.IsDoor2ClosedDone; } - - /// - /// 通道1是否有车 - /// - public bool HasCarInTone1 { get => plcVarModel.HasCarInTone1; } - - /// - /// 通道2是否有车 - /// - public bool HasCarInTone2 { get => plcVarModel.HasCarInTone2; } - - /// - /// 下位机异常代码 - /// - public Int16 ErrorCode { get => plcVarModel.ErrorCode; } - - /// - /// 2层以上的空板是否在待机 - /// - public bool IsOver2FlowStanded { get => plcVarModel.IsOver2FlowStanded; } - - /// - /// 1号门指示灯 - /// - public bool Gate1Light { get => plcVarModel.Gate1Light; } - - /// - /// 2号门指示灯 - /// - public bool Gate2Light { get => plcVarModel.Gate2Light; } - } - - -} diff --git a/Net462DllTest/Net462DllTest.csproj b/Net462DllTest/Net462DllTest.csproj deleted file mode 100644 index 727ee92..0000000 --- a/Net462DllTest/Net462DllTest.csproj +++ /dev/null @@ -1,98 +0,0 @@ - - - - - Debug - AnyCPU - {E40EE629-1A38-4011-88E3-9AD036869987} - Library - Net462DllTest - Net462DllTest - v4.6.2 - 512 - true - true - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - - - ..\packages\IoTClient.1.0.40\lib\netstandard2.0\IoTClient.dll - - - ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll - - - - - - ..\packages\System.IO.Ports.4.6.0\lib\net461\System.IO.Ports.dll - - - ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {5e19d0f2-913a-4d1c-a6f8-1e1227baa0e3} - Serein.Library - - - - - - - - - - - \ No newline at end of file diff --git a/Net462DllTest/Signal/CommandSignal.cs b/Net462DllTest/Signal/CommandSignal.cs deleted file mode 100644 index 98d0577..0000000 --- a/Net462DllTest/Signal/CommandSignal.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Net462DllTest.Signal -{ - public enum CommandSignal - { - Command_1, - Command_2, - Command_3, - Command_4, - Command_5, - Command_6, - Command_7, - Command_8, - Command_9, - } -} diff --git a/Net462DllTest/Signal/PLCVarSignal.cs b/Net462DllTest/Signal/PLCVarSignal.cs deleted file mode 100644 index e1770fc..0000000 --- a/Net462DllTest/Signal/PLCVarSignal.cs +++ /dev/null @@ -1,96 +0,0 @@ -using IoTClient.Enums; -using Net462DllTest.Enums; -using System; -using static Net462DllTest.Signal.PlcVarInfo; - -namespace Net462DllTest.Signal -{ - - [AttributeUsage(AttributeTargets.Field)] - public class PlcVarInfoAttribute : Attribute - { - public PlcVarInfo Info { get; } - - /// - /// - /// - /// 数据类型 - /// 变量地址 - /// 通知行为类型 - /// 是否只读 - /// 是否定时刷新 - /// 刷新间隔(ms) - public PlcVarInfoAttribute(DataTypeEnum dateType, - string address, - OnNotificationType notificationType, - bool isReadOnly = false, - bool isTimingRead = true, - int interval = 1000 - ) - { - Info = new PlcVarInfo() - { - DataType = dateType, - IsReadOnly = isReadOnly, - Address = address, - Interval = interval, - IsTimingRead= isTimingRead, - NotificationType = notificationType, - }; - } - } - - public class PlcVarInfo - { - public enum OnNotificationType - { - /// - /// 刷新时通知(每次写入Model后都会触发相应的触发器) - /// - OnRefresh, - /// - /// 改变时才通知(与Model对应数据不一致时才会触发相应的触发器) - /// - OnChanged, - } - - /// - /// 变量类型 - /// - public PlcVarName Name { get; set; } - /// - /// 数据类型 - /// - public DataTypeEnum DataType { get; set; } - /// - /// 变量地址 - /// - public string Address { get; set; } - /// - /// 变量是否只读 - /// - public bool IsReadOnly { get; set; } - /// - /// 是否定时刷新 - /// - public bool IsTimingRead { get; set; } - /// - /// 刷新间隔(ms) - /// - public int Interval { get; set; } = 100; // 100ms - public OnNotificationType NotificationType { get; set; } = OnNotificationType.OnChanged; - public override string ToString() - { - if (IsTimingRead) - { - return $"数据:{Name},类型:{DataType},地址:{Address},只读:{IsReadOnly},自动刷新:{IsTimingRead},刷新间隔:{Interval}"; - } - else - { - return $"数据:{Name},类型:{DataType},地址:{Address},只读:{IsReadOnly}"; - } - } - } - - -} diff --git a/Net462DllTest/Trigger/PrakingDevice.cs b/Net462DllTest/Trigger/PrakingDevice.cs deleted file mode 100644 index a7f0701..0000000 --- a/Net462DllTest/Trigger/PrakingDevice.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Net462DllTest.LogicControl; -using Serein.Library; -using Serein.Library.Utils; - -namespace Net462DllTest.Trigger -{ - [AutoRegister] - public class PrakingDevice : TaskFlowTrigger - { - } - -} diff --git a/Net462DllTest/Trigger/SiemensPlcDevice.cs b/Net462DllTest/Trigger/SiemensPlcDevice.cs deleted file mode 100644 index 8d510e6..0000000 --- a/Net462DllTest/Trigger/SiemensPlcDevice.cs +++ /dev/null @@ -1,463 +0,0 @@ -using IoTClient; -using IoTClient.Clients.PLC; -using IoTClient.Common.Enums; -using IoTClient.Enums; -using Net462DllTest.Enums; -using Net462DllTest.Model; -using Net462DllTest.Signal; -using Net462DllTest.Utils; -using Serein.Library; -using Serein.Library.Utils; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Reflection; -using System.Threading.Tasks; - -namespace Net462DllTest.Trigger -{ - - - [AutoRegister] - public class SiemensPlcDevice : TaskFlowTrigger - { - public SiemensClient Client { get; set; } - public SiemensVersion Version { get; set; } - public string IP { get; set; } = "127.0.0.1"; - public int Port { get; set; } = 102; - public PlcState State { get; set; } = PlcState.PowerOff; - public bool IsTimedRefresh { get; set; } = false; // 是否定时刷新 - public IGSModel Model { get; } - - - private readonly object _lockObj = new object(); // 防止多次初始化读取任务 - private readonly ConcurrentBag TimedRefreshTask = new ConcurrentBag(); // 定时读取任务 - private readonly ConcurrentBag VarInfos = new ConcurrentBag(); // 所有变量信息 - private readonly ConcurrentBag OnRefreshs = new ConcurrentBag(); // 数据变更后需要通知触发器的变量信息 - private readonly ConcurrentBag OnChangeds = new ConcurrentBag(); // 读取读取后需要通知触发器的变量信息 - - public SiemensPlcDevice(PlcVarModel model) - { - this.Model = new GSModel(model); - LoadVarInfos(); - } - - /// - /// 加载变量信息 - /// - private void LoadVarInfos() - { - foreach (var property in typeof(PlcVarModel).GetProperties()) - { - var attribute = property.GetCustomAttribute(); - if (attribute?.Value is PlcVarName varName) - { - var varInfo = varName.ToVarInfo(); - VarInfos.Add(varInfo); - if (varInfo.IsTimingRead) // 是否定时刷新 - { - switch (varInfo.NotificationType) - { - case PlcVarInfo.OnNotificationType.OnRefresh: - OnRefreshs.Add(varInfo); // 变量读取时通知触发器的变量 - break; - case PlcVarInfo.OnNotificationType.OnChanged: - OnChangeds.Add(varInfo); // 变量变更时才需要通知触发器的变量 - break; - } - } - } - } - } - - public void Init(SiemensVersion version, string ip, int port) - { - Client = new SiemensClient(version, ip, port); - Version = version; - IP = ip; - Port = port; - Client.Open(); - } - - public void Close() - { - Client?.Close(); - Client = null; - } - - public void Write(PlcVarName varName, object value) - { - var varInfo = varName.ToVarInfo(); - if (this.State == PlcState.Runing) - { - if (varInfo.IsReadOnly) - { - throw new Exception($"PLC变量{varInfo}当前禁止写入"); - } - else - { - - Client.WriteVar(varInfo, value); // 尝试写入PLC - Model.Set(varName, value); - Console.WriteLine($"PLC变量{varInfo}写入数据:{value}"); - } - } - else - { - throw new Exception($"PLC处于非预期状态{this.State}"); - } - } - - public object Read(PlcVarName varName) - { - var varInfo = varName.ToVarInfo(); - var result = Client.ReadVar(varInfo);// 尝试读取数据 - Model.Set(varName, result); // 缓存读取的数据 - return result; - - } - - public void BatchRefresh() - { - foreach(var varInfo in VarInfos) - { - Read(varInfo.Name); // 无条件批量读取 - } - } - - - /// - /// 开启定时批量读取任务 - /// - /// - public async Task OpenTimedRefreshAsync() - { - if (TimedRefreshTask.IsEmpty) - { - InitTimedRefreshTask(); - } - IsTimedRefresh = true; - await Task.WhenAll(TimedRefreshTask.ToArray()); - } - - /// - /// 关闭定时任务 - /// - public void CloseTimedRefresh() => IsTimedRefresh = false; - - /// - /// 初始化定时刷新任务 - /// - public void InitTimedRefreshTask() - { - Console.WriteLine("开始初始化刷新任务"); - lock (_lockObj) - { - foreach (var varInfo in OnChangeds) - { - Console.WriteLine($"添加监视任务(OnChanged):{varInfo.Name}"); - ScheduleTask(varInfo); - } - foreach (var varInfo in OnRefreshs) - { - Console.WriteLine($"添加监视任务(OnRefresh):{varInfo.Name}"); - ScheduleTask(varInfo); - } - } - } - - /// - /// 定时读取PLC变量,并刷新Model的值 - /// - /// - private void ScheduleTask(PlcVarInfo varInfo) - { - var task = Task.Run(async () => - { - var signal = varInfo.Name; - object oldData; - object newData; - bool isNotification; - while (true) - { - await Task.Delay(varInfo.Interval); - if (!IsTimedRefresh || Client is null) break; - - oldData = Model.Get(signal); // 暂存旧数据 - newData = Read(signal); // 获取新数据 - if (varInfo.NotificationType == PlcVarInfo.OnNotificationType.OnRefresh) - { - isNotification = true; // 无条件触发通知 - } - else - { - isNotification = !oldData.Equals(newData); // 变更时才会触发通知 - } - - if (isNotification) - { - Console.WriteLine($"VarName: {signal}\t\tOld Data: {oldData}\tNew Data: {newData}"); - await InvokeTriggerAsync(signal, newData); - } - - - } - }); - TimedRefreshTask.Add(task); - } - - public override string ToString() - { - return $"西门子Plc[{this.Version}-{this.IP}:{this.Port}]"; - } - - } - - - - - /// - /// 拓展方法 - /// - public static class MyPlcExtension - { - /// - /// 缓存变量信息 - /// - private static readonly Dictionary VarInfoDict = new Dictionary(); - - /// - /// 获取变量信息 - /// - /// - /// - /// - public static PlcVarInfo ToVarInfo(this PlcVarName plcVarEnum) - { - if (VarInfoDict.ContainsKey(plcVarEnum)) - { - return VarInfoDict[plcVarEnum]; - } - var plcValue = EnumHelper.GetAttributeValue(plcVarEnum, attr => attr.Info) - ?? throw new Exception($"获取变量异常:{plcVarEnum},没有标记PlcValueAttribute"); - if (string.IsNullOrEmpty(plcValue.Address)) - { - throw new Exception($"获取变量异常:{plcVarEnum},变量地址为空"); - } - VarInfoDict.Add(plcVarEnum, plcValue); - plcValue.Name = plcVarEnum; - return plcValue; - } - - /// - /// 读取PLC - /// - public static object ReadVar(this SiemensClient client, PlcVarInfo varInfo) - { - if (client is null) - { - throw new ArgumentNullException($"PLC尚未初始化"); - } - object resultvalue; - switch (varInfo.DataType) - { - case DataTypeEnum.String: - var resultString = client.ReadString(varInfo.Address); - if (!resultString.IsSucceed) throw new Exception(resultString.Err); - resultvalue = resultString.Value; - break; - case DataTypeEnum.Bool: - var resultBool = client.ReadBoolean(varInfo.Address); - if (!resultBool.IsSucceed) throw new Exception(resultBool.Err); - resultvalue = resultBool.Value; - break; - case DataTypeEnum.Float: - var resultFloat = client.ReadFloat(varInfo.Address); - if (!resultFloat.IsSucceed) throw new Exception(resultFloat.Err); - resultvalue = resultFloat.Value; - break; - case DataTypeEnum.Double: - var resultDouble = client.ReadDouble(varInfo.Address); - if (!resultDouble.IsSucceed) throw new Exception(resultDouble.Err); - resultvalue = resultDouble.Value; - break; - case DataTypeEnum.Byte: - var resultByte = client.ReadByte(varInfo.Address); - if (!resultByte.IsSucceed) throw new Exception(resultByte.Err); - resultvalue = resultByte.Value; - break; - case DataTypeEnum.Int16: - var resultInt16 = client.ReadInt16(varInfo.Address); - if (!resultInt16.IsSucceed) throw new Exception(resultInt16.Err); - resultvalue = resultInt16.Value; - break; - case DataTypeEnum.UInt16: - var resultUint16 = client.ReadUInt16(varInfo.Address); - if (!resultUint16.IsSucceed) throw new Exception(resultUint16.Err); - resultvalue = resultUint16.Value; - break; - case DataTypeEnum.Int32: - var resultInt32 = client.ReadInt32(varInfo.Address); - if (!resultInt32.IsSucceed) throw new Exception(resultInt32.Err); - resultvalue = resultInt32.Value; - break; - case DataTypeEnum.UInt32: - var resultUInt32 = client.ReadUInt32(varInfo.Address); - if (!resultUInt32.IsSucceed) throw new Exception(resultUInt32.Err); - resultvalue = resultUInt32.Value; - break; - case DataTypeEnum.Int64: - var resultInt64 = client.ReadInt64(varInfo.Address); - if (!resultInt64.IsSucceed) throw new Exception(resultInt64.Err); - resultvalue = resultInt64.Value; - break; - case DataTypeEnum.UInt64: - var resultUInt64 = client.ReadUInt64(varInfo.Address); - if (!resultUInt64.IsSucceed) throw new Exception(resultUInt64.Err); - resultvalue = resultUInt64.Value; - break; - default: - throw new NotImplementedException($"变量为指定数据类型,或是非预期的数据类型{varInfo}"); - } - return resultvalue; - } - /// - /// 转换数据类型,写入PLC - /// - public static object WriteVar(this SiemensClient client, PlcVarInfo varInfo, object value) - { - if (client is null) - { - throw new ArgumentNullException($"PLC尚未初始化"); - } - DataTypeEnum dataType = varInfo.DataType; - object convertValue; - Result result; - switch (dataType) - { - case DataTypeEnum.String: - var @string = value.ToString(); - convertValue = @string; - result = client.Write(varInfo.Address, @string); - break; - case DataTypeEnum.Bool: - var @bool = bool.Parse(value.ToString()); - convertValue = @bool; - result = client.Write(varInfo.Address, @bool); - break; - case DataTypeEnum.Float: - var @float = float.Parse(value.ToString()); - convertValue = @float; - result = client.Write(varInfo.Address, @float); - break; - case DataTypeEnum.Double: - var @double = double.Parse(value.ToString()); - convertValue = @double; - result = client.Write(varInfo.Address, @double); - break; - case DataTypeEnum.Byte: - var @byte = byte.Parse(value.ToString()); - convertValue = @byte; - result = client.Write(varInfo.Address, @byte); - break; - case DataTypeEnum.Int16: - var @short = short.Parse(value.ToString()); - convertValue = @short; - result = client.Write(varInfo.Address, @short); - break; - case DataTypeEnum.UInt16: - var @ushort = ushort.Parse(value.ToString()); - convertValue = @ushort; - result = client.Write(varInfo.Address, @ushort); - break; - case DataTypeEnum.Int32: - var @int = int.Parse(value.ToString()); - convertValue = @int; - result = client.Write(varInfo.Address, @int); - break; - case DataTypeEnum.UInt32: - var @uint = uint.Parse(value.ToString()); - convertValue = @uint; - result = client.Write(varInfo.Address, @uint); - break; - case DataTypeEnum.Int64: - var @long = long.Parse(value.ToString()); - convertValue = @long; - result = client.Write(varInfo.Address, @long); - break; - case DataTypeEnum.UInt64: - var @ulong = ulong.Parse(value.ToString()); - convertValue = @ulong; - result = client.Write(varInfo.Address, @ulong); - break; - default: - throw new NotImplementedException($"变量为指定数据类型,或是非预期的数据类型{varInfo}"); - } - - if (result.IsSucceed) - { - return convertValue; - } - else - { - throw new Exception(result.Err); - } - } - - - - - /// - /// 类型转换 - /// - /// - /// - /// - //public static Type ToDataType(this DataTypeEnum dataType) - //{ - // Type plcDataType; - // switch (dataType) - // { - // case DataTypeEnum.String: - // plcDataType = typeof(string); - // break; - // case DataTypeEnum.Bool: - // plcDataType = typeof(bool); - // break; - // case DataTypeEnum.Float: - // plcDataType = typeof(float); - // break; - // case DataTypeEnum.Double: - // plcDataType = typeof(double); - // break; - // case DataTypeEnum.Byte: - // plcDataType = typeof(byte); - // break; - // case DataTypeEnum.Int16: - // plcDataType = typeof(short); - // break; - // case DataTypeEnum.UInt16: - // plcDataType = typeof(ushort); - // break; - // case DataTypeEnum.Int32: - // plcDataType = typeof(int); - // break; - // case DataTypeEnum.UInt32: - // plcDataType = typeof(uint); - // break; - // case DataTypeEnum.Int64: - // plcDataType = typeof(long); - // break; - // case DataTypeEnum.UInt64: - // plcDataType = typeof(ulong); - // break; - // default: - // throw new NotImplementedException(); - // } - // return plcDataType; - //} - - } - - -} diff --git a/Net462DllTest/Trigger/ViewManagement.cs b/Net462DllTest/Trigger/ViewManagement.cs deleted file mode 100644 index 5238d7d..0000000 --- a/Net462DllTest/Trigger/ViewManagement.cs +++ /dev/null @@ -1,84 +0,0 @@ -using Net462DllTest.Signal; -using Serein.Library; -using Serein.Library.Api; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Threading; -using System.Windows.Forms; -using System.Windows.Threading; -using Serein.Library.Utils; - -namespace Net462DllTest.Trigger -{ - /// - /// 视图管理 - /// - [AutoRegister] - public class ViewManagement : TaskFlowTrigger - { - private readonly UIContextOperation uiContextOperation; - public ViewManagement(UIContextOperation uiContextOperation) - { - this.uiContextOperation = uiContextOperation; - } - public int Id = new Random().Next(1, 10000); - private readonly List
forms = new List(); - /// - /// 打开窗口 - /// - /// 要打开的窗口类型 - /// 是否置顶 - public void OpenView(Form form, bool isTop) - { - //Application.Current.Dispatcher. - forms.Add(form); - - uiContextOperation.Invoke(() => { - form.TopMost = isTop; - form.Show(); - }); - - - - //environment.IOC.Run(uiContext => - //{ - // uiContext?.Post(state => { - - // },null); - //}); - - //var uiContext = SynchronizationContext.Current; - //Task.Run(() => - //{ - // uiContext.Post(_ => - // { - - // }, null); - //}); - - } - - - - public void CloseView(Type formType) - { - var remoteForms = forms.Where(f => f.GetType() == formType).ToArray(); - - Dispatcher.CurrentDispatcher.Invoke(() => - { - foreach (Form f in remoteForms) - { - f.Close(); - f.Dispose(); - this.forms.Remove(f); - } - }); - - } - - - } - -} diff --git a/Net462DllTest/Utils/GSModel.cs b/Net462DllTest/Utils/GSModel.cs deleted file mode 100644 index 31a26af..0000000 --- a/Net462DllTest/Utils/GSModel.cs +++ /dev/null @@ -1,157 +0,0 @@ -using Serein.Library; -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Reflection.Emit; - -namespace Net462DllTest.Utils -{ - public interface IGSModel - { - //TModel Value { get; set; } - void Set(TKey tEnum, object value); - object Get(TKey tEnum); - - } - - - /// - /// 通过 Emit 创建 set/get 委托 - /// - public class GSModel : IGSModel - where TKey : struct, Enum - where TModel : class - { - private TModel Value; - - public GSModel(TModel Model) - { - this.Value = Model; - } - // 缓存创建好的setter和getter委托 - private readonly Dictionary> _setterCache = new Dictionary>(); - private readonly Dictionary> _getterCache = new Dictionary>(); - - public void Set(TKey tEnum, object value) - { - if (!_setterCache.TryGetValue(tEnum, out var setter)) - { - PropertyInfo property = GetPropertyByEnum(tEnum); - if (property == null) - { - _setterCache[tEnum] = (s, o) => throw new ArgumentException($"没有对应的Model属性{{{tEnum}"); - } - else - { - // 创建并缓存setter委托 - setter = CreateSetter(property); - _setterCache[tEnum] = setter; - } - } - - // 使用缓存的setter委托设置值 - setter(Value, value); - } - - public object Get(TKey tEnum) - { - if (!_getterCache.TryGetValue(tEnum, out var getter)) - { - PropertyInfo property = GetPropertyByEnum(tEnum); - if (property == null) - { - _setterCache[tEnum] = (s, o) => throw new ArgumentException($"没有对应的Model属性{tEnum}"); - } - else - { - // 创建并缓存getter委托 - getter = CreateGetter(property); - _getterCache[tEnum] = getter; - } - - } - - // 使用缓存的getter委托获取值 - return getter(Value); - } - - private PropertyInfo GetPropertyByEnum(TKey tEnum) - { - foreach (var property in typeof(TModel).GetProperties()) - { - var attribute = property.GetCustomAttribute(); - if (attribute?.Value?.GetType()?.IsEnum == true) - { - if (attribute.Value is TKey @enum && @enum.Equals(tEnum)) - { - return property; - } - } - - } - return null; - } - - - - - - - // 动态创建调用Setter方法 - private Action CreateSetter(PropertyInfo property) - { - var method = new DynamicMethod("Set" + property.Name, null, new[] { typeof(TModel), typeof(object) }, true); - var il = method.GetILGenerator(); - - il.Emit(OpCodes.Ldarg_0); // 加载实例(PlcVarValue) - il.Emit(OpCodes.Ldarg_1); // 加载值(object) - - if (property.PropertyType.IsValueType) - { - il.Emit(OpCodes.Unbox_Any, property.PropertyType); // 解箱并转换为值类型 - } - else - { - il.Emit(OpCodes.Castclass, property.PropertyType); // 引用类型转换 - } - - il.Emit(OpCodes.Callvirt, property.GetSetMethod()); // 调用属性的Setter方法 - il.Emit(OpCodes.Ret); // 返回 - - - - return (Action)method.CreateDelegate(typeof(Action)); - } - - /// - /// 动态创建调用Getter方法 - /// - /// - /// - private Func CreateGetter(PropertyInfo property) - { - var method = new DynamicMethod("Get" + property.Name, typeof(object), new[] { typeof(TModel) }, true); - var il = method.GetILGenerator(); - - il.Emit(OpCodes.Ldarg_0); // 加载实例(PlcVarValue) - il.Emit(OpCodes.Callvirt, property.GetGetMethod()); // 调用属性的Getter方法 - - if (property.PropertyType.IsValueType) - { - il.Emit(OpCodes.Box, property.PropertyType); // 值类型需要装箱 - } - - il.Emit(OpCodes.Ret); // 返回 - - return (Func)method.CreateDelegate(typeof(Func)); - } - - - - - - - - - } -} diff --git a/Net462DllTest/Utils/RelayCommand.cs b/Net462DllTest/Utils/RelayCommand.cs deleted file mode 100644 index 3ae40cf..0000000 --- a/Net462DllTest/Utils/RelayCommand.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Input; - -namespace Net462DllTest.Utils -{ - /// - /// 用于窗体View与ViewModel进行交互 - /// - public class RelayCommand : ICommand - { - private readonly Action _execute; - private readonly Func _canExecute; - - public RelayCommand(Action execute, Func canExecute = null) - { - _execute = execute; - _canExecute = canExecute; - } - - public event EventHandler CanExecuteChanged; - - public bool CanExecute(object parameter = null) - { - return _canExecute == null || _canExecute(parameter); - } - - public void Execute(object parameter = null) - { - _execute(parameter); - } - - public void RaiseCanExecuteChanged() - { - CanExecuteChanged?.Invoke(this, EventArgs.Empty); - } - } -} diff --git a/Net462DllTest/Web/FlowController.cs b/Net462DllTest/Web/FlowController.cs deleted file mode 100644 index d550c6a..0000000 --- a/Net462DllTest/Web/FlowController.cs +++ /dev/null @@ -1,80 +0,0 @@ - -using Net462DllTest.Enums; -using Net462DllTest.Signal; -using Net462DllTest.Trigger; -using Serein.Library; -using Serein.Library.Utils; -using Serein.Library.Web; -using System; - -namespace Net462DllTest.Web -{ - [WebApiController] - public class FlowController : ControllerBase - { - private readonly SiemensPlcDevice plcDevice; - private readonly ViewManagement viewManagement; - - public FlowController(SiemensPlcDevice plcDevice, ViewManagement viewManagement) - { - this.plcDevice = plcDevice; - this.viewManagement = viewManagement; - } - - /* - * 类型 :POST - * url : http://127.0.0.1:8089/flow/plcop?var= - * url : http://127.0.0.1:8089/flow/plcop?var=SpaceNum - * body :[JSON] - * - * { - * "value":0, - * } - */ - [WebApi(ApiType.POST)] - public dynamic PlcOp([Url] string var, int value) - { - if (EnumHelper.TryConvertEnum(var, out var signal)) - { - SereinEnv.WriteLine(InfoType.INFO, $"外部触发 {signal} 信号,信号内容 : {value} "); - _ = plcDevice.InvokeTriggerAsync(signal, value);// 通过 Web Api 模拟外部输入信号 - return new { state = "succeed" }; - } - else - { - return new { state = "fail" }; - } - - } - /* - * 类型 :POST - * url : http://127.0.0.1:8089/flow/trigger?command= - * url : http://127.0.0.1:8089/flow/trigger?command=Command_1 - * body :[JSON] - * - * { - * "value":0, - * } - */ - [WebApi(ApiType.POST)] - public dynamic Trigger([Url] string command, int value) - { - if (EnumHelper.TryConvertEnum(command, out var signal)) - { - SereinEnv.WriteLine(InfoType.INFO, $"外部触发 {signal} 信号,信号内容 : {value} "); - _ = viewManagement.InvokeTriggerAsync(signal, value);// 通过 Web Api 模拟外部输入信号 - return new { state = "succeed" }; - } - else - { - return new { state = "fail" }; - } - - } - } - - - - - -} diff --git a/Net462DllTest/Web/PlcSocketService.cs b/Net462DllTest/Web/PlcSocketService.cs deleted file mode 100644 index 6da6743..0000000 --- a/Net462DllTest/Web/PlcSocketService.cs +++ /dev/null @@ -1,166 +0,0 @@ -using IoTClient.Common.Enums; -using Net462DllTest.Enums; -using Net462DllTest.Model; -using Net462DllTest.Trigger; -using Serein.Library; -using Serein.Library.Api; -using Serein.Library.Network.WebSocketCommunication; -using Serein.Library.Web; -using System; -using System.Threading.Tasks; - -namespace Net462DllTest.Web -{ - - [AutoRegister] - [DynamicFlow("[PlcSocketService]")] - [AutoSocketModule(ThemeKey = "theme", DataKey = "data")] - public class PlcSocketService : ISocketHandleModule - { - public Guid HandleGuid { get; } = new Guid(); - - private readonly SiemensPlcDevice MyPlc; - private readonly PlcVarModelDataProxy plcVarModelDataProxy; - - public PlcSocketService(SiemensPlcDevice MyPlc, - PlcVarModelDataProxy plcVarModelDataProxy) - { - this.MyPlc = MyPlc; - this.plcVarModelDataProxy = plcVarModelDataProxy; - } - - #region 初始化、初始化完成以及退出的事件 - [NodeAction(NodeType.Init)] - public void Init(IFlowContext context) - { - var ioc = context.Env.FlowControl.IOC; - ioc.Register(); - ioc.Register(); - - ioc.Register(); - ioc.Register(); - } - - [NodeAction(NodeType.Loading)] // Loading 初始化完成已注入依赖项,可以开始逻辑上的操作 - public void Loading(IFlowContext context) - { - var ioc = context.Env.FlowControl.IOC; - // 注册控制器 - ioc.Run((router, apiServer) => { - router.AddHandle(typeof(FlowController)); - apiServer.Start("http://*:8089/"); // 开启 Web Api 服务 - }); - - ioc.Run(async (socketServer) => { - socketServer.MsgHandleHelper.AddModule(this, (ex, recover) => - { - recover(new - { - ex = ex.Message, - storehouseInfo = ex.StackTrace - }); - - }); - await socketServer.StartAsync("http://localhost:5005/"); // 开启 Web Socket 监听 - }); - ioc.Run(async client => { - await client.ConnectAsync("ws://localhost:5005/"); // 连接到服务器 - }); - } - - [NodeAction(NodeType.Exit)] // 流程结束时自动执行 - public void Exit(IFlowContext context) - { - var ioc = context.Env.FlowControl.IOC; - ioc.Run((apiServer) => - { - apiServer?.Stop(); // 关闭 Web 服务 - - }); - ioc.Run((socketServer) => - { - socketServer.MsgHandleHelper.RemoveModule(this); - socketServer?.Stop(); // 关闭 Web 服务 - }); - MyPlc.Close(); - MyPlc.CancelAllTrigger(); - } - - #endregion - - - [AutoSocketHandle] - public async Task BatchReadVar(Func SendMsg, Func SendObj) - { - await SendMsg("开始刷新数据"); - //MyPlc.BatchRefresh(); - await Task.Delay(1000); - await SendMsg("刷新完成"); - await SendObj(plcVarModelDataProxy); - await SendMsg("发送完成"); - } - - - [AutoSocketHandle] - public object ReadVar(PlcVarName varName) - { - var result = MyPlc.Read(varName); - Console.WriteLine($"获取变量成功:({varName})\t result = {result}"); - 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", - int port = 102) - { - if (MyPlc.Client is null) - { - try - { - MyPlc.Init(version, ip, port); - Console.WriteLine($"西门子PLC初始化成功[{version},{ip}:{port}]"); - } - catch (Exception ex) - { - Console.WriteLine($"西门子PLC[{version},{ip}:{port}]初始化异常:{ex.Message}"); - } - } - else - { - Console.WriteLine($"西门子PLC已经初始化[{version},{ip}:{port}]"); - } - return MyPlc; - } - - [AutoSocketHandle(IsReturnValue = false)] - public SiemensPlcDevice SetState(PlcState state = PlcState.PowerOff) - { - var oldState = MyPlc.State; - MyPlc.State = state; - Console.WriteLine($"PLC状态从[{oldState}]转为[{state}]"); - return MyPlc; - } - - - - public void OpenTimedRefresh() - { - Task.Run(async () => await MyPlc.OpenTimedRefreshAsync()); - } - - public void CloseTimedRefresh() - { - MyPlc.CloseTimedRefresh(); - } - - } -} diff --git a/Net462DllTest/app.config b/Net462DllTest/app.config deleted file mode 100644 index 0ad3798..0000000 --- a/Net462DllTest/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/Net462DllTest/packages.config b/Net462DllTest/packages.config deleted file mode 100644 index 25f6dd1..0000000 --- a/Net462DllTest/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file