日常提交

main
xiaoguo 2 years ago
parent 24efb46642
commit e83aa7aab0

Binary file not shown.

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using PVDEMCS.Common;
using PVDEMCS.Common.Constant;
using PVDEMCS.Common.Devices;
using PVDEMCS.Devices;
using PVDEMCS.Services;
using PVDEMCS.Services.Models;
using SharpCompress.Common;
@ -55,19 +55,23 @@ namespace PVDEMCS.Controllers
/// </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);
GetDeviceIsConnected(result.Content);
if (result.IsSuccess)
{
GetDeviceIsConnected(result.Content);
}
return result;
}
[NonAction]
private void GetDeviceIsConnected(List<DeviceInfo> list)
{
if (!list.IsNullOrEmpty() && !_deviceRun.GetDeviceIsConnected.IsNullOrEmpty())
if (list.IsNullOrEmpty() &&!_deviceRun.GetDeviceIsConnected.IsNullOrEmpty())
{
foreach (var item in list)
{

@ -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,6 +21,7 @@ namespace PVDEMCS.Controllers
{
private IEquipmentService _equipmentService;
public EquipmentController(IEquipmentService equipmentService)
{
this._equipmentService = equipmentService;
@ -36,6 +40,7 @@ namespace PVDEMCS.Controllers
public Result<PagedList<EquipmentInfo>> GetEquipmentPageList(string equipmentName, string equipmentCode, string equipmentType, bool? activated, int page, int 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 设备状态记录
@ -91,7 +95,7 @@ namespace PVDEMCS.Controllers
#region 设备记录统计
/// <summary>
/// 获取设备状态记录统计分页列表
/// 获取设备状态记录统计(日)分页列表
/// </summary>
/// <param name="equipmentName">设备名称</param>
/// <param name="equipmentCode">设备编号</param>
@ -108,7 +112,7 @@ namespace PVDEMCS.Controllers
}
/// <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
}
}

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

@ -3,7 +3,7 @@ using PVDEMCS.Services;
using PVDEMCS.Services.Models;
using System.Threading;
namespace PVDEMCS.Common.Devices
namespace PVDEMCS.Devices
{
/// <summary>
/// 设备运行

@ -8,8 +8,9 @@ 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通信接口
@ -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,9 +1,15 @@
using Masuit.Tools;
using PVDEMCS.Common;
using PVDEMCS.Common.Devices.Impl;
using PVDEMCS.Devices;
using PVDEMCS.Services.Models;
using System.Security.Cryptography;
namespace PVDEMCS.Common.Devices.Impl
namespace PVDEMCS.Devices.Impl
{
/// <summary>
/// 控制器点位监控
/// </summary>
public class DeviceMonitor
{
private DeviceInfo deviceInfo;
@ -14,7 +20,7 @@ namespace PVDEMCS.Common.Devices.Impl
public DeviceMonitor(DeviceInfo deviceInfo)
{
this.deviceInfo = deviceInfo;
this.devicePoints = new List<DevicePoint>();
devicePoints = new List<DevicePoint>();
PointMonitor();
}
/// <summary>
@ -53,7 +59,7 @@ namespace PVDEMCS.Common.Devices.Impl
/// <summary>
/// 连接状态
/// </summary>
public Boolean isConnected
public bool isConnected
{
get
{
@ -64,7 +70,7 @@ namespace PVDEMCS.Common.Devices.Impl
/// <summary>
/// 监控是否运行
/// </summary>
public Boolean IsRun
public bool IsRun
{
get { return IsRun; }
}
@ -85,8 +91,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>
@ -131,11 +137,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);
@ -197,42 +203,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);
@ -246,7 +252,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);

@ -1,11 +1,12 @@
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.Common.Devices.Impl
namespace PVDEMCS.Devices.Impl
{
/// <summary>
/// 设备运行
@ -39,11 +40,11 @@ namespace PVDEMCS.Common.Devices.Impl
/// <summary>
/// 获取控制器连接状态
/// </summary>
public Dictionary<string,bool> GetDeviceIsConnected
public Dictionary<string, bool> GetDeviceIsConnected
{
get
{
return monitors.ToDictionary(f=>f.DeviceCode,f=>f.isConnected);
return monitors.ToDictionary(f => f.DeviceCode, f => f.isConnected);
}
}
@ -56,7 +57,7 @@ namespace PVDEMCS.Common.Devices.Impl
monitors.Clear();
var result = this.deviceService.GetDeviceInfoList("", "", true);
var result = deviceService.GetDeviceInfoList("", "", true);
if (result.IsSuccess)
{
var devices = result.Content;
@ -140,9 +141,13 @@ namespace PVDEMCS.Common.Devices.Impl
{
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())
if (!startStop.IsNullOrEmpty() &&
!fault.IsNullOrEmpty() &&
!startStop.ObjectValue.IsNullOrEmpty() &&
!fault.ObjectValue.IsNullOrEmpty())
{
var state = EquipmentState.Run;
if (fault.GetValue<bool>())
{
state = EquipmentState.Alarm;
@ -151,7 +156,7 @@ namespace PVDEMCS.Common.Devices.Impl
{
state = EquipmentState.Stop;
}
this.equipmentRecordService.AddUpdateEquipmentRecord(id, state, DateTime.Now);
equipmentRecordService.AddUpdateEquipmentRecord(id, state, DateTime.Now);
}
}
}

@ -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;

@ -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
{
@ -17,10 +19,12 @@ namespace PVDEMCS.Services.Impl
internal class EquipmentService : IEquipmentService
{
private readonly EquipmentRepository _equipmentRepository;
private readonly IDeviceRun _deviceRun;
public EquipmentService(EquipmentRepository equipmentRepository)
public EquipmentService(EquipmentRepository 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>

@ -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; }
}
}

@ -392,6 +392,9 @@ namespace PVDEMCS.Services.Repositories.Impl
return query;
}
#endregion
}
}

@ -1 +1 @@
78dedf078fa663772dbe506cad079b136782b2c8
48b48bf3defe4d9734e7cdb6fde8131a1931ad8b

Loading…
Cancel
Save