1.控制器查询获取连接状态

2.点位查询获取点位内容
main
xiaoguo 2 years ago
parent 009b6ec85e
commit 24efb46642

Binary file not shown.

@ -1,5 +1,7 @@
using PVDEMCS.Common.DI;
using PVDEMCS.Services;
using PVDEMCS.Services.Models;
using System.Threading;
namespace PVDEMCS.Common.Devices
{
@ -8,6 +10,17 @@ namespace PVDEMCS.Common.Devices
/// </summary>
public interface IDeviceRun : IDependency
{
/// <summary>
/// 获取所有点位信息
/// </summary>
List<DevicePoint> GetDevicePoints { get; }
/// <summary>
/// 获取控制器连接状态
/// </summary>
Dictionary<string, bool> GetDeviceIsConnected { get; }
/// <summary>
/// 开始运行
/// </summary>

@ -4,7 +4,7 @@ using System.Security.Cryptography;
namespace PVDEMCS.Common.Devices.Impl
{
public class DeviceMonitor
public class DeviceMonitor
{
private DeviceInfo deviceInfo;
private IPLCCommunicationService plcCommunicationService;
@ -17,7 +17,6 @@ namespace PVDEMCS.Common.Devices.Impl
this.devicePoints = new List<DevicePoint>();
PointMonitor();
}
/// <summary>
/// PLC 点位改变触发
/// </summary>
@ -28,6 +27,17 @@ namespace PVDEMCS.Common.Devices.Impl
/// </summary>
public event EventHandler<string> ErrorMessage;
/// <summary>
/// 控制器编号
/// </summary>
public string DeviceCode
{
get
{
return deviceInfo.DeviceCode;
}
}
/// <summary>
/// 间隔时间
/// </summary>
@ -54,7 +64,7 @@ namespace PVDEMCS.Common.Devices.Impl
/// <summary>
/// 监控是否运行
/// </summary>
public Boolean IsRun
public Boolean IsRun
{
get { return IsRun; }
}
@ -95,7 +105,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)}: 不能为空!");
}

@ -25,6 +25,28 @@ namespace PVDEMCS.Common.Devices.Impl
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>
@ -54,7 +76,6 @@ namespace PVDEMCS.Common.Devices.Impl
}
}
/// <summary>
/// 停止运行
/// </summary>

@ -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.Common.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,9 +42,14 @@ 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>
@ -51,9 +60,22 @@ namespace PVDEMCS.Controllers
public Result<List<DeviceInfo>> GetDeviceInfoList(string deviceCode, string deviceName, bool? activated = false)
{
var result = _deviceService.GetDeviceInfoList(deviceCode, deviceName, activated);
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 +143,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 +165,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 +212,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 +224,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;

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

@ -64,6 +64,16 @@
设备运行
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.IDeviceRun.GetDevicePoints">
<summary>
获取所有点位信息
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.IDeviceRun.GetDeviceIsConnected">
<summary>
获取控制器连接状态
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceRun.Run">
<summary>
开始运行
@ -84,6 +94,11 @@
获取错误相信
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.Impl.DeviceMonitor.DeviceCode">
<summary>
控制器编号
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.Impl.DeviceMonitor.Interval">
<summary>
间隔时间
@ -148,6 +163,16 @@
设备运行
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.Impl.DeviceRun.GetDevicePoints">
<summary>
获取所有点位信息
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.Impl.DeviceRun.GetDeviceIsConnected">
<summary>
获取控制器连接状态
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.Impl.DeviceRun.Run">
<summary>
开始运行
@ -1515,6 +1540,11 @@
备注
</summary>
</member>
<member name="P:PVDEMCS.Services.Models.DeviceInfo.isConnected">
<summary>
设备连接状态
</summary>
</member>
<member name="T:PVDEMCS.Services.Models.DevicePoint">
<summary>
PLC点位

@ -64,6 +64,16 @@
设备运行
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.IDeviceRun.GetDevicePoints">
<summary>
获取所有点位信息
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.IDeviceRun.GetDeviceIsConnected">
<summary>
获取控制器连接状态
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceRun.Run">
<summary>
开始运行
@ -84,6 +94,11 @@
获取错误相信
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.Impl.DeviceMonitor.DeviceCode">
<summary>
控制器编号
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.Impl.DeviceMonitor.Interval">
<summary>
间隔时间
@ -148,6 +163,16 @@
设备运行
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.Impl.DeviceRun.GetDevicePoints">
<summary>
获取所有点位信息
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.Impl.DeviceRun.GetDeviceIsConnected">
<summary>
获取控制器连接状态
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.Impl.DeviceRun.Run">
<summary>
开始运行
@ -1515,6 +1540,11 @@
备注
</summary>
</member>
<member name="P:PVDEMCS.Services.Models.DeviceInfo.isConnected">
<summary>
设备连接状态
</summary>
</member>
<member name="T:PVDEMCS.Services.Models.DevicePoint">
<summary>
PLC点位

Loading…
Cancel
Save