diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/1703dfbf-8d01-4953-9ffd-cbdb2c74d3a4.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/1703dfbf-8d01-4953-9ffd-cbdb2c74d3a4.vsidx new file mode 100644 index 0000000..33c99c0 Binary files /dev/null and b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/1703dfbf-8d01-4953-9ffd-cbdb2c74d3a4.vsidx differ diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/1b9b7666-498a-470f-ae0b-069dc88728d1.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/1b9b7666-498a-470f-ae0b-069dc88728d1.vsidx deleted file mode 100644 index f30a378..0000000 Binary files a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/1b9b7666-498a-470f-ae0b-069dc88728d1.vsidx and /dev/null differ diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/4c8a62b7-1955-456f-ab0d-bbd71aa1dc88.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/4c8a62b7-1955-456f-ab0d-bbd71aa1dc88.vsidx new file mode 100644 index 0000000..4736153 Binary files /dev/null and b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/4c8a62b7-1955-456f-ab0d-bbd71aa1dc88.vsidx differ diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/7c7f44d6-1d85-4451-873e-2c4dd21a5c9f.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/7c7f44d6-1d85-4451-873e-2c4dd21a5c9f.vsidx new file mode 100644 index 0000000..6ce266e Binary files /dev/null and b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/7c7f44d6-1d85-4451-873e-2c4dd21a5c9f.vsidx differ diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/7cf1e42f-a411-422c-90cb-90c8fa59b2d6.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/7cf1e42f-a411-422c-90cb-90c8fa59b2d6.vsidx deleted file mode 100644 index e46d9b4..0000000 Binary files a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/7cf1e42f-a411-422c-90cb-90c8fa59b2d6.vsidx and /dev/null differ diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/8cb64b6c-060f-4449-beb6-15489e6bf7bc.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/8cb64b6c-060f-4449-beb6-15489e6bf7bc.vsidx deleted file mode 100644 index ed2f218..0000000 Binary files a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/8cb64b6c-060f-4449-beb6-15489e6bf7bc.vsidx and /dev/null differ diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/29ccd813-ab10-4dbc-96e2-4e38de2c2356.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/b5a19ed7-50d5-488c-8ece-d32417f62322.vsidx similarity index 74% rename from PVDEMCS/.vs/PVDEMCS/FileContentIndex/29ccd813-ab10-4dbc-96e2-4e38de2c2356.vsidx rename to PVDEMCS/.vs/PVDEMCS/FileContentIndex/b5a19ed7-50d5-488c-8ece-d32417f62322.vsidx index ac626ce..5272b8b 100644 Binary files a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/29ccd813-ab10-4dbc-96e2-4e38de2c2356.vsidx and b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/b5a19ed7-50d5-488c-8ece-d32417f62322.vsidx differ diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/c6e2453f-dbaa-4f90-9907-a3e4ccef1ed8.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/c6e2453f-dbaa-4f90-9907-a3e4ccef1ed8.vsidx new file mode 100644 index 0000000..ea519b0 Binary files /dev/null and b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/c6e2453f-dbaa-4f90-9907-a3e4ccef1ed8.vsidx differ diff --git a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/d135ed4d-7f1c-42cf-9352-2a3ad653a271.vsidx b/PVDEMCS/.vs/PVDEMCS/FileContentIndex/d135ed4d-7f1c-42cf-9352-2a3ad653a271.vsidx deleted file mode 100644 index 43183cf..0000000 Binary files a/PVDEMCS/.vs/PVDEMCS/FileContentIndex/d135ed4d-7f1c-42cf-9352-2a3ad653a271.vsidx and /dev/null differ diff --git a/PVDEMCS/.vs/PVDEMCS/v17/.suo b/PVDEMCS/.vs/PVDEMCS/v17/.suo index 5bc093d..7357aec 100644 Binary files a/PVDEMCS/.vs/PVDEMCS/v17/.suo and b/PVDEMCS/.vs/PVDEMCS/v17/.suo differ diff --git a/PVDEMCS/PVDEMCS/Common/Devices/IDeviceConfiguration.cs b/PVDEMCS/PVDEMCS/Common/Devices/IDeviceConfiguration.cs deleted file mode 100644 index c6eacb1..0000000 --- a/PVDEMCS/PVDEMCS/Common/Devices/IDeviceConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -using PVDEMCS.Common.DI; -using PVDEMCS.Services; - -namespace PVDEMCS.Common.Devices -{ - public interface IDeviceConfiguration : IDependency - { - - } - - -} diff --git a/PVDEMCS/PVDEMCS/Common/Devices/IDeviceRun.cs b/PVDEMCS/PVDEMCS/Common/Devices/IDeviceRun.cs new file mode 100644 index 0000000..c9b22c2 --- /dev/null +++ b/PVDEMCS/PVDEMCS/Common/Devices/IDeviceRun.cs @@ -0,0 +1,21 @@ +using PVDEMCS.Common.DI; +using PVDEMCS.Services; + +namespace PVDEMCS.Common.Devices +{ + /// + /// 设备运行 + /// + public interface IDeviceRun : IDependency + { + /// + /// 开始运行 + /// + void Run(); + + /// + /// 停止运行 + /// + void Stop(); + } +} diff --git a/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceConfiguration.cs b/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceConfiguration.cs deleted file mode 100644 index 6257b95..0000000 --- a/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceConfiguration.cs +++ /dev/null @@ -1,50 +0,0 @@ -using PVDEMCS.Services; -using System.Threading; - -namespace PVDEMCS.Common.Devices.Impl -{ - public class DeviceConfiguration : IDeviceConfiguration - { - private IDeviceService deviceService; - - private List monitors = new List(); - - public DeviceConfiguration(IDeviceService device) - { - this.deviceService = device; - } - - public void Load() - { - monitors.Clear(); - var result = this.deviceService.GetDeviceInfoList("", "", true); - if (result.IsSuccess) - { - var devices = result.Content; - foreach (var device in devices) - { - var deviceMonitor = new DeviceMonitor(device); - var devicePoints = deviceService.GetDevicePointList(device.DeviceName); - if (devicePoints.IsSuccess && devicePoints.Content.Count>0) - { - deviceMonitor.Load(devicePoints.Content.ToArray()); - } - deviceMonitor.ErrorMessage += DeviceMonitor_ErrorMessage; - deviceMonitor.PointChnage += DeviceMonitor_PointChnage; - monitors.Add(deviceMonitor); - Task task = deviceMonitor.StartAsync(); - } - } - } - - private void DeviceMonitor_PointChnage(object sender, Services.Models.DevicePoint e) - { - - } - - private void DeviceMonitor_ErrorMessage(object sender, string e) - { - - } - } -} diff --git a/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceMonitor.cs b/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceMonitor.cs index e88b8a9..e66ec0b 100644 --- a/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceMonitor.cs +++ b/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceMonitor.cs @@ -39,6 +39,26 @@ namespace PVDEMCS.Common.Devices.Impl return plcCommunicationService; } } + + /// + /// 连接状态 + /// + public Boolean isConnected + { + get + { + return plcCommunicationService.isConnected; + } + } + + /// + /// 监控是否运行 + /// + public Boolean IsRun + { + get { return IsRun; } + } + /// /// 当前点位集合 /// diff --git a/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceRun.cs b/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceRun.cs new file mode 100644 index 0000000..70e6a06 --- /dev/null +++ b/PVDEMCS/PVDEMCS/Common/Devices/Impl/DeviceRun.cs @@ -0,0 +1,155 @@ +using AngleSharp.Css.Dom; +using Masuit.Tools; +using PVDEMCS.Common.Constant; +using PVDEMCS.Services; +using PVDEMCS.Services.Models; +using System.Threading; + +namespace PVDEMCS.Common.Devices.Impl +{ + /// + /// 设备运行 + /// + public class DeviceRun : IDeviceRun + { + private IDeviceService deviceService; + private IEquipmentRecordService equipmentRecordService; + private List monitors = new List(); + private object lockObj = new object(); + private object lockObj1 = new object(); + + public DeviceRun(IDeviceService deviceService, IEquipmentRecordService equipmentRecordService) + { + this.deviceService = deviceService; + this.equipmentRecordService = equipmentRecordService; + TaskRun(); + } + + /// + /// 开始运行 + /// + public void Run() + { + Stop(); + + monitors.Clear(); + + var result = this.deviceService.GetDeviceInfoList("", "", true); + if (result.IsSuccess) + { + var devices = result.Content; + foreach (var device in devices) + { + var deviceMonitor = new DeviceMonitor(device); + var devicePoints = deviceService.GetDevicePointList(device.DeviceName); + if (devicePoints.IsSuccess && devicePoints.Content.Count > 0) + { + deviceMonitor.Load(devicePoints.Content.ToArray()); + } + deviceMonitor.ErrorMessage += DeviceMonitor_ErrorMessage; + deviceMonitor.PointChnage += DeviceMonitor_PointChnage; ; + monitors.Add(deviceMonitor); + Task task = deviceMonitor.StartAsync(); + } + } + } + + + /// + /// 停止运行 + /// + public void Stop() + { + foreach (var item in monitors) + { + var task = item.StartAsync(); + } + } + + private void TaskRun() + { + Task.Run(() => + { + while (true) + { + lock (lockObj) + { + RunEquipmentRecord(); + + Thread.Sleep(1000); + } + } + }); + + + Task.Run(() => + { + while (true) + { + lock (lockObj1) + { + RunEquipmentRecordTotal(); + + Thread.Sleep(1000 * 60); + } + } + }); + } + + //记录设备数据 + private void RunEquipmentRecord() + { + foreach (var monitor in monitors) + { + if (!monitor.IsRun) + { + continue; + } + var points = monitor.Points; + if (!points.IsNullOrEmpty()) + { + continue; + } + + var equipmentIds = points.Select(f => f.EquipmentId).Distinct(); + foreach (var id in equipmentIds) + { + var list = points.Where(f => f.EquipmentId == id).ToList(); + if (list.Count >= 2) + { + var startStop = list.Where(f => f.ActionType == ActionType.StartStop).FirstOrDefault(); + var fault = list.Where(f => f.ActionType == ActionType.Fault).FirstOrDefault(); + if (!startStop.IsNullOrEmpty() && !fault.IsNullOrEmpty()) + { + var state = EquipmentState.Run; + if (fault.GetValue()) + { + state = EquipmentState.Alarm; + } + else if (!startStop.GetValue()) + { + state = EquipmentState.Stop; + } + this.equipmentRecordService.AddUpdateEquipmentRecord(id, state, DateTime.Now); + } + } + } + } + } + + //记录设备数据统计 + private void RunEquipmentRecordTotal() + { + equipmentRecordService.RunEquipmentRecordTotal(DateTime.Now); + } + + private void DeviceMonitor_PointChnage(object sender, DevicePoint e) + { + } + + private void DeviceMonitor_ErrorMessage(object sender, string e) + { + Console.WriteLine(e); + } + } +} diff --git a/PVDEMCS/PVDEMCS/Program.cs b/PVDEMCS/PVDEMCS/Program.cs index 1458d54..c62db98 100644 --- a/PVDEMCS/PVDEMCS/Program.cs +++ b/PVDEMCS/PVDEMCS/Program.cs @@ -52,8 +52,10 @@ app.MapControllers(); app.Lifetime.ApplicationStarted.Register(() => { - var deviceConfiguration = app.Services.GetService(); - //deviceConfiguration + var deviceRun = app.Services.GetService(); + + deviceRun.Run(); + }); app.Run(); diff --git a/PVDEMCS/PVDEMCS/Services/Models/DevicePoint.cs b/PVDEMCS/PVDEMCS/Services/Models/DevicePoint.cs index f919639..d423d0a 100644 --- a/PVDEMCS/PVDEMCS/Services/Models/DevicePoint.cs +++ b/PVDEMCS/PVDEMCS/Services/Models/DevicePoint.cs @@ -2,6 +2,8 @@ #nullable disable using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; namespace PVDEMCS.Services.Models; @@ -47,6 +49,11 @@ public partial class DevicePoint /// public string EquipmentType { get; set; } + /// + /// 点位所属动作,启动停止:start_stop;故障:fault + /// + public string ActionType { get; set; } + /// /// 点位编号 /// @@ -79,4 +86,13 @@ public partial class DevicePoint public Object ObjectValue { get; set; } + public T GetValue() + { + if (ObjectValue is T) + { + return (T)ObjectValue; + } + return default; + } + } \ No newline at end of file diff --git a/PVDEMCS/PVDEMCS/Services/Repositories/Impl/DeviceRepository.cs b/PVDEMCS/PVDEMCS/Services/Repositories/Impl/DeviceRepository.cs index 908525a..f894ace 100644 --- a/PVDEMCS/PVDEMCS/Services/Repositories/Impl/DeviceRepository.cs +++ b/PVDEMCS/PVDEMCS/Services/Repositories/Impl/DeviceRepository.cs @@ -279,6 +279,7 @@ namespace PVDEMCS.Services.Repositories.Impl PointName = point.PointName, Address = point.Address, DataType = point.DataType, + ActionType = point.ActionType, Remark = point.Remark, }; if (!deviceName.IsNullOrEmpty()) diff --git a/PVDEMCS/PVDEMCS/Services/Repositories/Impl/EquipmentRecordRepository.cs b/PVDEMCS/PVDEMCS/Services/Repositories/Impl/EquipmentRecordRepository.cs index 7138598..795c3e6 100644 --- a/PVDEMCS/PVDEMCS/Services/Repositories/Impl/EquipmentRecordRepository.cs +++ b/PVDEMCS/PVDEMCS/Services/Repositories/Impl/EquipmentRecordRepository.cs @@ -110,11 +110,6 @@ namespace PVDEMCS.Services.Repositories.Impl /// public Result AddUpdateEquipmentRecord(string equipmentId, string state, DateTime dateTime) { - if (!EquipmentState.HaveState(state)) - { - return new Result($"【{state}】状态不正确!"); - } - using (var context = new EFContext()) { var entity = context.EquipmentRecords.Where(f => f.EquipmentId == equipmentId).OrderByDescending(f => f.StartTime).FirstOrDefault(); @@ -162,7 +157,7 @@ namespace PVDEMCS.Services.Repositories.Impl var result = new Result(); using (var context = new EFContext()) { - var query = context.EquipmentRecords.Where(f => f.StartTime >= begDate && f.StartTime <= endDate); + var query = context.EquipmentRecords.Where(f => f.StartTime >= begDate && f.StartTime <= endDate).ToList(); //获取状态统计时间 var total = query.GroupBy(f => new { f.EquipmentId, f.State }) .Select(f => new TotalRecord diff --git a/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.dll b/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.dll index c735b2a..93e2c53 100644 Binary files a/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.dll and b/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.dll differ diff --git a/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.pdb b/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.pdb index 72e25f0..2ef9e88 100644 Binary files a/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.pdb and b/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.pdb differ diff --git a/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.xml b/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.xml index cc84393..96b83e6 100644 --- a/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.xml +++ b/PVDEMCS/PVDEMCS/bin/Debug/net6.0/PVDEMCS.xml @@ -59,6 +59,21 @@ 报警 + + + 设备运行 + + + + + 开始运行 + + + + + 停止运行 + + PLC 点位改变触发 @@ -74,6 +89,16 @@ 间隔时间 + + + 连接状态 + + + + + 监控是否运行 + + 当前点位集合 @@ -118,6 +143,21 @@ + + + 设备运行 + + + + + 开始运行 + + + + + 停止运行 + + PLC通信服务 SiemensS7 smart200 实现 @@ -1515,6 +1555,11 @@ 设备类型:Ionbond,Balzers,Cemecon + + + 点位所属动作,启动停止:start_stop;故障:fault + + 点位编号 diff --git a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.csproj.CoreCompileInputs.cache b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.csproj.CoreCompileInputs.cache index 2562c5e..06779d0 100644 --- a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.csproj.CoreCompileInputs.cache +++ b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -343174067cd832fbade3d0f003640c7839b8168f +78dedf078fa663772dbe506cad079b136782b2c8 diff --git a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.dll b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.dll index c735b2a..93e2c53 100644 Binary files a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.dll and b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.dll differ diff --git a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.pdb b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.pdb index 72e25f0..2ef9e88 100644 Binary files a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.pdb and b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.pdb differ diff --git a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.xml b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.xml index cc84393..96b83e6 100644 --- a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.xml +++ b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/PVDEMCS.xml @@ -59,6 +59,21 @@ 报警 + + + 设备运行 + + + + + 开始运行 + + + + + 停止运行 + + PLC 点位改变触发 @@ -74,6 +89,16 @@ 间隔时间 + + + 连接状态 + + + + + 监控是否运行 + + 当前点位集合 @@ -118,6 +143,21 @@ + + + 设备运行 + + + + + 开始运行 + + + + + 停止运行 + + PLC通信服务 SiemensS7 smart200 实现 @@ -1515,6 +1555,11 @@ 设备类型:Ionbond,Balzers,Cemecon + + + 点位所属动作,启动停止:start_stop;故障:fault + + 点位编号 diff --git a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/ref/PVDEMCS.dll b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/ref/PVDEMCS.dll index 17df09a..6db3591 100644 Binary files a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/ref/PVDEMCS.dll and b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/ref/PVDEMCS.dll differ diff --git a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/refint/PVDEMCS.dll b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/refint/PVDEMCS.dll index 17df09a..6db3591 100644 Binary files a/PVDEMCS/PVDEMCS/obj/Debug/net6.0/refint/PVDEMCS.dll and b/PVDEMCS/PVDEMCS/obj/Debug/net6.0/refint/PVDEMCS.dll differ