You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.8 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Admin.Core.IService.IService_New;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2024 WenJY 保留所有权利。
* CLR版本4.0.30319.42000
* 机器名称LAPTOP-E0N2L34V
* 命名空间Aucma.Core.DataCollector.Factory
* 唯一标识81c294d4-c4ab-4504-b193-9a5d013383d3
*
* 创建者WenJY
* 电子邮箱wenjy@mesnac.com
* 创建时间2024-03-28 11:57:37
* 版本V1.0.0
* 描述:
*
*--------------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace Aucma.Core.DataCollector.Factory
{
public class LinerPreassembleFactory : DataCollectorFactory
{
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("LinerPreassemble"));
public LinerPreassembleFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices) : base(deviceParamServices, deviceAlarmInfoServices, deviceElectricityServices)
{
}
public override void CollectDeviceAlarmInfo(out List<Record_DeviceAlarmInfo> deviceAlarmInfos)
{
while (true)
{
try
{
if (_plc != null)
{
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}采集内胆预装设备报警信息");
var plc = _plc.plc;
var deviceParams = base._deviceParamServices.Query(x => x.DeviceCode == "E00024");
if (deviceParams != null)
{
deviceAlarmInfos = new List<Record_DeviceAlarmInfo>();
string batchId = System.Guid.NewGuid().ToString("N");
foreach (var item in deviceParams)
{
base.ReadParamValueByPlc(plc, item.ParamAddress, item.ParamType, out int paramValue);
if (paramValue != 0)
{
deviceAlarmInfos.Add(new Record_DeviceAlarmInfo()
{
BatchId = batchId,
DeviceCode = item.DeviceCode,
DeviceType = "1",
ParamCode = item.ParamCode,
ParamValue = paramValue.ToString(),
AlarmInfo = item.ParamName,
AlarmTime = DateTime.Now,
CreadtedTime = DateTime.Now,
});
}
}
if (deviceAlarmInfos.Count > 0)
{
base._deviceAlarmInfoServices.AddAsync(deviceAlarmInfos);
}
}
Task.Delay(base.AlarmReadTimer).Wait();
}
else
{
Task.Delay(base.AlarmReadTimer).Wait();
_plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("LinerPreassemble"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集内胆预装设备报警信息异常:{ex.Message}");
}
}
}
public override void CollectDeviceElectricity(out List<Record_DeviceElectricity> deviceElectricitys)
{
while (true)
{
try
{
if (_plc != null)
{
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}采集内胆预装设备用电数据");
var plc = _plc.plc;
deviceElectricitys = new List<Record_DeviceElectricity>();
// 地面内胆预装主柜
string[] ground = new string[] { "D7602", "D7604", "D7606", "D7608", "D7610", "D7612", "D7630", "D7634", "D7638", "D7642" };
Record_DeviceElectricity _deviceElectricity_ground = new Record_DeviceElectricity()
{
MonitorId = "E00024_0001"
};
base.ReadDeviceElectricity(ground, plc, ref _deviceElectricity_ground);
if(_deviceElectricity_ground != null)
{
deviceElectricitys.Add(_deviceElectricity_ground);
}
//平台内胆预装远程
string[] platform = new string[] { "D7652", "D7664", "D7666", "D7668", "D7660", "D7662", "D7680", "D7684", "D7688", "D7692" };
Record_DeviceElectricity _deviceElectricity_platform = new Record_DeviceElectricity()
{
MonitorId = "E00024_0002"
};
base.ReadDeviceElectricity(platform, plc, ref _deviceElectricity_platform);
if (_deviceElectricity_platform != null)
{
deviceElectricitys.Add(_deviceElectricity_platform);
}
if(deviceElectricitys.Count > 0)
{
var result = base._deviceElectricityServices.AddAsync(deviceElectricitys);
}
else
{
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}采集内胆预装设备用电数据失败,数据为空");
}
Task.Delay(base.EleReadTimer).Wait();
}
else
{
Task.Delay(base.EleReadTimer).Wait();
_plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("LinerPreassemble"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集内胆预装用电数据采集异常:{ex.Message}");
}
}
}
}
}