liuhr 2 years ago
commit 2a5d9997b7

Binary file not shown.

@ -1,12 +0,0 @@
using PVDEMCS.Common.DI;
using PVDEMCS.Services;
namespace PVDEMCS.Common.Devices
{
public interface IDeviceConfiguration : IDependency
{
}
}

@ -1,50 +0,0 @@
using PVDEMCS.Services;
using System.Threading;
namespace PVDEMCS.Common.Devices.Impl
{
public class DeviceConfiguration : IDeviceConfiguration
{
private IDeviceService deviceService;
private List<DeviceMonitor> monitors = new List<DeviceMonitor>();
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<bool> task = deviceMonitor.StartAsync();
}
}
}
private void DeviceMonitor_PointChnage(object sender, Services.Models.DevicePoint e)
{
}
private void DeviceMonitor_ErrorMessage(object sender, string e)
{
}
}
}

@ -1,9 +1,11 @@
using AngleSharp.Dom;
using Masuit.Tools;
using Masuit.Tools.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using PVDEMCS.Common;
using PVDEMCS.Common.Constant;
using PVDEMCS.Devices;
using PVDEMCS.Services;
using PVDEMCS.Services.Models;
using SharpCompress.Common;
@ -19,10 +21,12 @@ namespace PVDEMCS.Controllers
public class DeviceController : Controller
{
private IDeviceService _deviceService;
private IDeviceRun _deviceRun;
public DeviceController(IDeviceService deviceService)
public DeviceController(IDeviceService deviceService, IDeviceRun deviceRun)
{
_deviceService = deviceService;
_deviceRun = deviceRun;
}
#region PLC控制器
@ -38,22 +42,44 @@ namespace PVDEMCS.Controllers
public Result<PagedList<DeviceInfo>> GetDevicePageList(string deviceCode, string deviceName, bool? activated, int page, int size = 20)
{
var result = _deviceService.GetDevicePageList(deviceCode, deviceName, activated, page, size);
if (result.IsSuccess)
{
GetDeviceIsConnected(result.Content.Data);
}
return result;
}
/// <summary>
/// 获取PLC控制器列表
/// </summary>
/// <param name="deviceCode">控制器编号</param>
/// <param name="deviceName">控制器名称</param>
/// <returns></returns>
/// <param name="activated">是否启用</param>
/// /// <returns></returns>
[HttpGet]
public Result<List<DeviceInfo>> GetDeviceInfoList(string deviceCode, string deviceName, bool? activated = false)
{
var result = _deviceService.GetDeviceInfoList(deviceCode, deviceName, activated);
if (result.IsSuccess)
{
GetDeviceIsConnected(result.Content);
}
return result;
}
[NonAction]
private void GetDeviceIsConnected(List<DeviceInfo> list)
{
if (list.IsNullOrEmpty() &&!_deviceRun.GetDeviceIsConnected.IsNullOrEmpty())
{
foreach (var item in list)
{
item.isConnected = _deviceRun.GetDeviceIsConnected[item.DeviceCode];
}
}
}
/// <summary>
/// 获取PLC控制器明细
/// </summary>
@ -121,6 +147,10 @@ namespace PVDEMCS.Controllers
public Result<PagedList<DevicePoint>> GetDevicePointPageList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated, int page, int size = 20)
{
var result = _deviceService.GetDevicePointPageList(deviceName, deviceCode, equipmentName, equipmentCode, equipmentType, pointCode, pointName, activated, page, size);
if (result.IsSuccess)
{
GetPointValue(result.Content.Data);
}
return result;
}
@ -139,9 +169,23 @@ namespace PVDEMCS.Controllers
public Result<List<DevicePoint>> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated)
{
var result = _deviceService.GetDevicePointList(deviceName, deviceCode, equipmentName, equipmentCode, equipmentType, pointCode, pointName, activated);
GetPointValue(result.Content);
return result;
}
[NonAction]
private void GetPointValue(List<DevicePoint> list)
{
var points = _deviceRun.GetDevicePoints;
if (!list.IsNullOrEmpty() && !points.IsNullOrEmpty())
{
foreach (var item in list)
{
item.ObjectValue = points.Where(f => f.PointCode == item.PointCode).Select(f => f.ObjectValue).FirstOrDefault();
}
}
}
/// <summary>
/// 获取PLC控制器点位明细
/// </summary>
@ -172,7 +216,7 @@ namespace PVDEMCS.Controllers
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
public Result UpdateDevicePoint(DevicePoint entity)
public Result UpdateDevicePoint(DevicePoint entity)
{
var result = _deviceService.UpdateDevicePoint(entity);
return result;
@ -184,7 +228,7 @@ namespace PVDEMCS.Controllers
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
public Result DeleteDevicePoint(string id)
public Result DeleteDevicePoint(string id)
{
var result = _deviceService.DeleteDevicePoint(id);
return result;

@ -1,9 +1,12 @@
using Masuit.Tools.Models;
using Masuit.Tools;
using Masuit.Tools.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using PVDEMCS.Common;
using PVDEMCS.Common.Constant;
using PVDEMCS.Devices;
using PVDEMCS.Services;
using PVDEMCS.Services.Impl;
using PVDEMCS.Services.Models;
using System;
@ -18,7 +21,8 @@ namespace PVDEMCS.Controllers
{
private IEquipmentService _equipmentService;
public EquipmentController(IEquipmentService equipmentService)
public EquipmentController(IEquipmentService equipmentService)
{
this._equipmentService = equipmentService;
}
@ -33,9 +37,10 @@ namespace PVDEMCS.Controllers
/// <param name="size">页大小</param>
/// <returns></returns>
[HttpGet]
public Result<PagedList<EquipmentInfo>> GetEquipmentPageList(string equipmentName, string equipmentCode, string equipmentType, bool? activated, int page, int size)
public Result<PagedList<EquipmentInfo>> GetEquipmentPageList(string equipmentName, string equipmentCode, string equipmentType, bool? activated, int page, int size = 20)
{
var result = this._equipmentService.GetEquipmentPageList(equipmentName,equipmentCode,equipmentType,activated,page,size);
var result = this._equipmentService.GetEquipmentPageList(equipmentName, equipmentCode, equipmentType, activated, page, size);
return result;
}
@ -49,9 +54,11 @@ namespace PVDEMCS.Controllers
public Result<List<EquipmentInfo>> GetEquipmentList(string equipmentName, string equipmentCode, string equipmentType, bool? activated)
{
var result = this._equipmentService.GetEquipmentList(equipmentName, equipmentCode, equipmentType, activated);
return result;
}
/// <summary>
/// 获取设备明显
/// </summary>

@ -17,9 +17,13 @@ namespace PVDEMCS.Controllers
public class EquipmentRecordController : Controller
{
private IEquipmentRecordService _equipmentRecordService;
public EquipmentRecordController(IEquipmentRecordService equipmentRecordService)
private IDeviceService _deviceService;
public EquipmentRecordController(IEquipmentRecordService equipmentRecordService, IDeviceService deviceService)
{
this._equipmentRecordService = equipmentRecordService;
this._deviceService = deviceService;
}
#region 设备状态记录
@ -36,9 +40,9 @@ namespace PVDEMCS.Controllers
/// <param name="size">页大小</param>
/// <returns></returns>
[HttpGet]
public Result<PagedList<EquipmentRecord>> GetEquipmentRecordPageList(string equipmentName, string equipmentCode, string equipmentType, DateTime begTime, DateTime endTime, int page, int size)
public Result<PagedList<EquipmentRecord>> GetEquipmentRecordPageList(string equipmentName, string equipmentCode, string equipmentType, DateTime begTime, DateTime endTime, int page, int size = 20)
{
var result= _equipmentRecordService.GetEquipmentRecordPageList(equipmentName, equipmentCode, equipmentType, begTime, endTime, page, size);
var result = _equipmentRecordService.GetEquipmentRecordPageList(equipmentName, equipmentCode, equipmentType, begTime, endTime, page, size);
return result;
}
@ -91,7 +95,7 @@ namespace PVDEMCS.Controllers
#region 设备记录统计
/// <summary>
/// 获取设备状态记录统计分页列表
/// 获取设备状态记录统计(日)分页列表
/// </summary>
/// <param name="equipmentName">设备名称</param>
/// <param name="equipmentCode">设备编号</param>
@ -101,14 +105,14 @@ namespace PVDEMCS.Controllers
/// <param name="page">当前页</param>
/// <param name="size">页大小</param>
[HttpGet]
public Result<PagedList<EquipmentRecordTotal>> GetEquipmentRecordDayTotalPageList(string equipmentName, string equipmentCode, string equipmentType, DateTime begTime, DateTime endTime, int page, int size)
public Result<PagedList<EquipmentRecordTotal>> GetEquipmentRecordDayTotalPageList(string equipmentName, string equipmentCode, string equipmentType, DateTime begTime, DateTime endTime, int page, int size = 20)
{
var result = _equipmentRecordService.GetEquipmentRecordDayTotalPageList(equipmentName,equipmentCode,equipmentType,begTime,endTime,page,size);
var result = _equipmentRecordService.GetEquipmentRecordDayTotalPageList(equipmentName, equipmentCode, equipmentType, begTime, endTime, page, size);
return result;
}
/// <summary>
/// 获取设备状态记录统计列表
/// 获取设备状态记录统计(日)列表
/// </summary>
/// <param name="equipmentName">设备名称</param>
/// <param name="equipmentCode">设备编号</param>
@ -122,6 +126,18 @@ namespace PVDEMCS.Controllers
return result;
}
/// <summary>
/// 获取设备总览
/// </summary>
/// <returns></returns>
[HttpGet]
public Result<List<EquipmentStateView>> GetEquipmentStateView()
{
var points = _deviceService.GetDevicePointList(activated: true);
return null;
}
#endregion
}
}

@ -17,7 +17,7 @@ namespace PVDEMCS.Controllers
public class SysConfigController : Controller
{
private ISysConfigService _sysConfigService;
public SysConfigController(ISysConfigService sysConfigService)
public SysConfigController(ISysConfigService sysConfigService)
{
this._sysConfigService = sysConfigService;
}
@ -30,9 +30,9 @@ namespace PVDEMCS.Controllers
/// <param name="size">页大小</param>
/// <returns></returns>
[HttpGet]
public Result<PagedList<SysConfig>> GetSysConfigPageList(string configName, string configKey, int page, int size)
public Result<PagedList<SysConfig>> GetSysConfigPageList(string configName, string configKey, int page, int size = 20)
{
var result = this._sysConfigService.GetSysConfigPageList(configName,configKey,page,size);
var result = this._sysConfigService.GetSysConfigPageList(configName, configKey, page, size);
return result;
}

@ -1,4 +1,4 @@
namespace PVDEMCS.Common.Devices
namespace PVDEMCS.Devices
{
public sealed class DeviceProtocol
{

@ -0,0 +1,34 @@
using PVDEMCS.Common.DI;
using PVDEMCS.Services;
using PVDEMCS.Services.Models;
using System.Threading;
namespace PVDEMCS.Devices
{
/// <summary>
/// 设备运行
/// </summary>
public interface IDeviceRun : IDependency
{
/// <summary>
/// 获取所有点位信息
/// </summary>
List<DevicePoint> GetDevicePoints { get; }
/// <summary>
/// 获取控制器连接状态
/// </summary>
Dictionary<string, bool> GetDeviceIsConnected { get; }
/// <summary>
/// 开始运行
/// </summary>
void Run();
/// <summary>
/// 停止运行
/// </summary>
void Stop();
}
}

@ -8,13 +8,14 @@ using System.Text;
using System.Threading.Tasks;
using HslCommunication.Profinet.Siemens;
using PVDEMCS.Common.DI;
using PVDEMCS.Common;
namespace PVDEMCS.Common.Devices
namespace PVDEMCS.Devices
{
/// <summary>
/// PLC通信接口
/// </summary>
public interface IPLCCommunicationService
public interface IPLCCommunicationService
{
/// <summary>
/// 是否已连接
@ -108,14 +109,14 @@ namespace PVDEMCS.Common.Devices
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Result Write(string address, Int16 value);
Result Write(string address, short value);
/// <summary>
/// 写入Int32值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Result Write(string address, Int32 value);
Result Write(string address, int value);
/// <summary>
/// 写入float值
@ -226,14 +227,14 @@ namespace PVDEMCS.Common.Devices
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<Result> WriteAsync(string address, Int16 value);
Task<Result> WriteAsync(string address, short value);
/// <summary>
/// 写入Int32值
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
Task<Result> WriteAsync(string address, Int32 value);
Task<Result> WriteAsync(string address, int value);
/// <summary>
/// 写入float值

@ -1,10 +1,15 @@
using Masuit.Tools;
using PVDEMCS.Common;
using PVDEMCS.Devices;
using PVDEMCS.Services.Models;
using System.Security.Cryptography;
namespace PVDEMCS.Common.Devices.Impl
namespace PVDEMCS.Devices.Impl
{
public class DeviceMonitor
/// <summary>
/// 控制器点位监控
/// </summary>
public class DeviceMonitor
{
private DeviceInfo deviceInfo;
private IPLCCommunicationService plcCommunicationService;
@ -14,10 +19,9 @@ namespace PVDEMCS.Common.Devices.Impl
public DeviceMonitor(DeviceInfo deviceInfo)
{
this.deviceInfo = deviceInfo;
this.devicePoints = new List<DevicePoint>();
devicePoints = new List<DevicePoint>();
PointMonitor();
}
/// <summary>
/// PLC 点位改变触发
/// </summary>
@ -28,6 +32,17 @@ namespace PVDEMCS.Common.Devices.Impl
/// </summary>
public event EventHandler<string> ErrorMessage;
/// <summary>
/// 控制器编号
/// </summary>
public string DeviceCode
{
get
{
return deviceInfo.DeviceCode;
}
}
/// <summary>
/// 间隔时间
/// </summary>
@ -39,6 +54,26 @@ namespace PVDEMCS.Common.Devices.Impl
return plcCommunicationService;
}
}
/// <summary>
/// 连接状态
/// </summary>
public bool isConnected
{
get
{
return plcCommunicationService.isConnected;
}
}
/// <summary>
/// 监控是否运行
/// </summary>
public bool IsRun
{
get { return IsRun; }
}
/// <summary>
/// 当前点位集合
/// </summary>
@ -55,8 +90,8 @@ namespace PVDEMCS.Common.Devices.Impl
/// </summary>
public void Init(string address, int port = 0)
{
this.deviceInfo.Host = address;
this.deviceInfo.Port = port;
deviceInfo.Host = address;
deviceInfo.Port = port;
}
/// <summary>
@ -75,7 +110,7 @@ namespace PVDEMCS.Common.Devices.Impl
/// <param name="points"></param>
public void Load(params DevicePoint[] points)
{
if (points.IsNullOrEmpty())
if (points.IsNullOrEmpty())
{
throw new ArgumentException($"{nameof(points)}: 不能为空!");
}
@ -101,11 +136,11 @@ namespace PVDEMCS.Common.Devices.Impl
{
if (plcCommunicationService == null)
{
plcCommunicationService = new S7CommunicationService(this.deviceInfo.Protocol);
plcCommunicationService = new S7CommunicationService(deviceInfo.Protocol);
}
if (!plcCommunicationService.isConnected)
{
var result = await plcCommunicationService.ConnectionAsync(this.deviceInfo.Host, this.deviceInfo.Port);
var result = await plcCommunicationService.ConnectionAsync(deviceInfo.Host, deviceInfo.Port);
if (!result.IsSuccess)
{
ErrorMessage?.Invoke(this, "开始PLC连接失败" + result.Message);
@ -167,42 +202,42 @@ namespace PVDEMCS.Common.Devices.Impl
var type = point.DataType;
var plcService = plcCommunicationService;
//Boolean
if (type.Equals(typeof(Boolean)))
if (type.Equals(typeof(bool)))
{
var result = await plcService.ReadBoolAsync(point.Address);
GetReturnValue(point, result);
return;
}
//Byte
if (type.Equals(typeof(Byte)))
if (type.Equals(typeof(byte)))
{
var result = await plcService.ReadByteAsync(point.Address);
GetReturnValue(point, result);
return;
}
//Byte
if (type.Equals(typeof(Byte)))
if (type.Equals(typeof(byte)))
{
var result = await plcService.ReadByteAsync(point.Address);
GetReturnValue(point, result);
return;
}
//Int16
if (type.Equals(typeof(Int16)))
if (type.Equals(typeof(short)))
{
var result = await plcService.ReadInt16Async(point.Address);
GetReturnValue(point, result);
return;
}
//Int32
if (type.Equals(typeof(Int32)))
if (type.Equals(typeof(int)))
{
var result = await plcService.ReadInt32Async(point.Address);
GetReturnValue(point, result);
return;
}
//Int64
if (type.Equals(typeof(Int64)))
if (type.Equals(typeof(long)))
{
var result = await plcService.ReadLongAsync(point.Address);
GetReturnValue(point, result);
@ -216,7 +251,7 @@ namespace PVDEMCS.Common.Devices.Impl
return;
}
//double
if (type.Equals(typeof(Double)))
if (type.Equals(typeof(double)))
{
var result = await plcService.ReadDoubleAsync(point.Address);
GetReturnValue(point, result);

@ -0,0 +1,181 @@
using AngleSharp.Css.Dom;
using Masuit.Tools;
using PVDEMCS.Common.Constant;
using PVDEMCS.Devices;
using PVDEMCS.Services;
using PVDEMCS.Services.Models;
using System.Threading;
namespace PVDEMCS.Devices.Impl
{
/// <summary>
/// 设备运行
/// </summary>
public class DeviceRun : IDeviceRun
{
private IDeviceService deviceService;
private IEquipmentRecordService equipmentRecordService;
private List<DeviceMonitor> monitors = new List<DeviceMonitor>();
private object lockObj = new object();
private object lockObj1 = new object();
public DeviceRun(IDeviceService deviceService, IEquipmentRecordService equipmentRecordService)
{
this.deviceService = deviceService;
this.equipmentRecordService = equipmentRecordService;
TaskRun();
}
/// <summary>
/// 获取所有点位信息
/// </summary>
public List<DevicePoint> GetDevicePoints
{
get
{
return monitors.SelectMany(f => f.Points).ToList();
}
}
/// <summary>
/// 获取控制器连接状态
/// </summary>
public Dictionary<string, bool> GetDeviceIsConnected
{
get
{
return monitors.ToDictionary(f => f.DeviceCode, f => f.isConnected);
}
}
/// <summary>
/// 开始运行
/// </summary>
public void Run()
{
Stop();
monitors.Clear();
var result = 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<bool> task = deviceMonitor.StartAsync();
}
}
}
/// <summary>
/// 停止运行
/// </summary>
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() &&
!startStop.ObjectValue.IsNullOrEmpty() &&
!fault.ObjectValue.IsNullOrEmpty())
{
var state = EquipmentState.Run;
if (fault.GetValue<bool>())
{
state = EquipmentState.Alarm;
}
else if (!startStop.GetValue<bool>())
{
state = EquipmentState.Stop;
}
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);
}
}
}

@ -13,8 +13,10 @@ using HslCommunication;
using HslCommunication.Profinet.Siemens;
using HslCommunication.Reflection;
using PVDEMCS.Common.Tools;
using PVDEMCS.Devices;
using PVDEMCS.Common;
namespace PVDEMCS.Common.Devices.Impl
namespace PVDEMCS.Devices.Impl
{
/// <summary>
/// PLC通信服务 SiemensS7 smart200 实现
@ -30,7 +32,8 @@ namespace PVDEMCS.Common.Devices.Impl
public S7CommunicationService(string deviceProtocol)
{
switch (deviceProtocol) {
switch (deviceProtocol)
{
case DeviceProtocol.S7_400:
siemensS7Net = new SiemensS7Net(SiemensPLCS.S400);
break;
@ -49,7 +52,7 @@ namespace PVDEMCS.Common.Devices.Impl
case DeviceProtocol.S7_200Smart:
siemensS7Net = new SiemensS7Net(SiemensPLCS.S200Smart);
break;
default :
default:
throw new ArgumentException($"DeviceProtocol 参数不正确,没有{deviceProtocol}协议");
}
siemensS7Net.ConnectTimeOut = 3000;
@ -213,7 +216,7 @@ namespace PVDEMCS.Common.Devices.Impl
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public Result Write(string address, Int16 value)
public Result Write(string address, short value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
@ -225,7 +228,7 @@ namespace PVDEMCS.Common.Devices.Impl
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public Result Write(string address, Int32 value)
public Result Write(string address, int value)
{
var operateResult = siemensS7Net.Write(address, value);
var result = ConvertResult(operateResult);
@ -428,7 +431,7 @@ namespace PVDEMCS.Common.Devices.Impl
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<Result> WriteAsync(string address, Int16 value)
public async Task<Result> WriteAsync(string address, short value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);
@ -440,7 +443,7 @@ namespace PVDEMCS.Common.Devices.Impl
/// </summary>
/// <param name="address">写入地址</param>
/// <param name="value"></param>
public async Task<Result> WriteAsync(string address, Int32 value)
public async Task<Result> WriteAsync(string address, int value)
{
var operateResult = await siemensS7Net.WriteAsync(address, value);
var result = ConvertResult(operateResult);

@ -1,8 +1,8 @@
using Masuit.Tools;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using PVDEMCS.Common.Devices;
using PVDEMCS.Common.DI;
using PVDEMCS.Devices;
using System.Configuration;
using System.Reflection;
@ -52,8 +52,10 @@ app.MapControllers();
app.Lifetime.ApplicationStarted.Register(() =>
{
var deviceConfiguration = app.Services.GetService<IDeviceConfiguration>();
//deviceConfiguration
var deviceRun = app.Services.GetService<IDeviceRun>();
deviceRun.Run();
});
app.Run();

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using PVDEMCS.Common;
using PVDEMCS.Common.Tools;
using PVDEMCS.Devices;
using PVDEMCS.Services.Models;
using PVDEMCS.Services.Repositories;
using PVDEMCS.Services.Repositories.Entities;
@ -20,6 +21,7 @@ namespace PVDEMCS.Services.Impl
public DeviceService(IDeviceRepository deviceRepository)
{
this._deviceRepository = deviceRepository;
}
#region PLC控制器

@ -8,6 +8,8 @@ using PVDEMCS.Common.Constant;
using PVDEMCS.Common.Tools;
using PVDEMCS.Services.Repositories.Entities;
using PVDEMCS.Services.Repositories.Impl;
using PVDEMCS.Devices;
using Masuit.Tools;
namespace PVDEMCS.Services.Impl
{
@ -16,11 +18,13 @@ namespace PVDEMCS.Services.Impl
*/
internal class EquipmentService : IEquipmentService
{
private readonly EquipmentRepository _equipmentRepository;
private readonly IEquipmentRepository _equipmentRepository;
private readonly IDeviceRun _deviceRun;
public EquipmentService(EquipmentRepository equipmentRepository)
public EquipmentService(IEquipmentRepository equipmentRepository, IDeviceRun deviceRun)
{
this._equipmentRepository = equipmentRepository;
this._deviceRun = deviceRun;
}
/// <summary>
@ -36,6 +40,10 @@ namespace PVDEMCS.Services.Impl
public Result<PagedList<EquipmentInfo>> GetEquipmentPageList(string equipmentName, string equipmentCode, string equipmentType, bool? activated, int page, int size)
{
var result = this._equipmentRepository.GetEquipmentPageList(equipmentName, equipmentCode, equipmentType, activated, page, size);
if (result.IsSuccess)
{
GetEquipmentState(result.Content.Data);
}
return result;
}
@ -48,9 +56,50 @@ namespace PVDEMCS.Services.Impl
public Result<List<EquipmentInfo>> GetEquipmentList(string equipmentName, string equipmentCode, string equipmentType, bool? activated)
{
var result = this._equipmentRepository.GetEquipmentList(equipmentName, equipmentCode, equipmentType, activated);
if (result.IsSuccess)
{
GetEquipmentState(result.Content);
}
return result;
}
/// <summary>
/// 获取设备状态
/// </summary>
/// <param name="equipmentInfos"></param>
private void GetEquipmentState(List<EquipmentInfo> equipmentInfos)
{
var points = _deviceRun.GetDevicePoints;
if (!equipmentInfos.IsNullOrEmpty() && !points.IsNullOrEmpty())
{
foreach (var equipmentInfo in equipmentInfos)
{
var list = points.Where(f => f.EquipmentId == equipmentInfo.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() &&
!startStop.ObjectValue.IsNullOrEmpty() &&
!fault.ObjectValue.IsNullOrEmpty())
{
var state = EquipmentState.Run;
if (fault.GetValue<bool>())
{
state = EquipmentState.Alarm;
}
else if (!startStop.GetValue<bool>())
{
state = EquipmentState.Stop;
}
equipmentInfo.State = state;
}
}
}
}
}
/// <summary>
/// 获取设备明显
/// </summary>

@ -47,4 +47,9 @@ public partial class DeviceInfo
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 设备连接状态
/// </summary>
public Boolean isConnected { get; set; }
}

@ -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
/// </summary>
public string EquipmentType { get; set; }
/// <summary>
/// 点位所属动作启动停止start_stop故障fault
/// </summary>
public string ActionType { get; set; }
/// <summary>
/// 点位编号
/// </summary>
@ -79,4 +86,13 @@ public partial class DevicePoint
public Object ObjectValue { get; set; }
public T GetValue<T>()
{
if (ObjectValue is T)
{
return (T)ObjectValue;
}
return default;
}
}

@ -0,0 +1,28 @@
namespace PVDEMCS.Services.Models
{
/// <summary>
/// 设备状态总览
/// </summary>
public class EquipmentStateView
{
/// <summary>
/// 设备类型ALL(所有),IonbondBalzersCemecon
/// </summary>
public string EquipmentType { get; set; }
/// <summary>
/// 运行数量
/// </summary>
public int Run { get; set; }
/// <summary>
/// 待机数量
/// </summary>
public int Stop { get; set; }
/// <summary>
/// 报警数量
/// </summary>
public int Alarm { get; set; }
}
}

@ -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())

@ -110,11 +110,6 @@ namespace PVDEMCS.Services.Repositories.Impl
/// <returns></returns>
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
@ -397,6 +392,9 @@ namespace PVDEMCS.Services.Repositories.Impl
return query;
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
343174067cd832fbade3d0f003640c7839b8168f
3e345de9ad93be7a11cd4479e87ec2ba29d50159

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save