附加数据采集类库

main
liulb@mesnac.com 10 months ago
parent 83d7689a2d
commit 65208b872f

File diff suppressed because it is too large Load Diff

@ -8,7 +8,10 @@
<ItemGroup>
<ProjectReference Include="..\Admin.Core.IService\Admin.Core.IService.csproj" />
<ProjectReference Include="..\Admin.Core.Model\Admin.Core.Model.csproj" />
<ProjectReference Include="..\Admin.Core.Service\Admin.Core.Service.csproj" />
<ProjectReference Include="..\Aucma.Core.HwPLc\Aucma.Core.HwPLc.csproj" />
<ProjectReference Include="..\Aucma.Core.PLc\Aucma.Core.PLc.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,152 @@
using Admin.Core.IService.IService_New;
using Admin.Core.Model.Model_New;
using Aucma.Core.DataCollector.Factory;
using Aucma.Core.HwPLc;
using log4net;
using NPOI.SS.Formula.Functions;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.DataCollector
{
/// <summary>
/// 设备数据采集
/// </summary>
public abstract class DataCollectorFactory
{
public readonly log4net.ILog _logger = LogManager.GetLogger(typeof(DataCollectorFactory));
public readonly IBaseDeviceParamServices _deviceParamServices;
public readonly IRecordDeviceAlarmInfoServices _deviceAlarmInfoServices;
public readonly IRecordDeviceElectricityServices _deviceElectricityServices;
public int AlarmReadTimer = (1000 * 5);
public int EleReadTimer = (1000 * 60 * 5);
public DataCollectorFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices)
{
_deviceParamServices = deviceParamServices;
_deviceAlarmInfoServices = deviceAlarmInfoServices;
_deviceElectricityServices = deviceElectricityServices;
}
/// <summary>
/// 采集设备报警信息
/// </summary>
/// <param name="deviceAlarmInfos"></param>
public abstract void CollectDeviceAlarmInfo(out List<Record_DeviceAlarmInfo> deviceAlarmInfos);
/// <summary>
/// 采集设备用电
/// </summary>
/// <param name="deviceElectricity"></param>
public abstract void CollectDeviceElectricity(out List<Record_DeviceElectricity> deviceElectricitys);
/// <summary>
/// 根据PLC地址读取设备用电
/// </summary>
/// <param name="address"></param>
/// <param name="plc"></param>
/// <param name="deviceElectricity"></param>
public void ReadDeviceElectricity(string[] address,IPlc plc,ref Record_DeviceElectricity deviceElectricity)
{
var ground = plc.ReadRandomInt32(address);
if (ground != null)
{
if (ground.Length >= 10)
{
var info = ParseAndReverseByteArray(ground, 0, address.Length * 2);
if(info != null)
{
if(info.Length >= 10)
{
//deviceElectricity.Glys = ground[0];
deviceElectricity.Va = (decimal)info[0]/100;
deviceElectricity.Vb = (decimal)info[1]/100;
deviceElectricity.Vc = (decimal)info[2]/100;
deviceElectricity.Ia = (decimal)info[6]/100;
deviceElectricity.Ib = (decimal)info[7]/100;
deviceElectricity.Ic = (decimal)info[8]/100;
deviceElectricity.Zxyg = (decimal)info[9]/100;
deviceElectricity.CollectType = 0;
deviceElectricity.CollectTime = DateTime.Now;
deviceElectricity.RecordTime = DateTime.Now;
}
}
}
}
else
{
deviceElectricity = null;
}
}
/// <summary>
/// 读取PLC数据
/// </summary>
/// <param name="_plc"></param>
/// <param name="addr"></param>
/// <param name="dataType"></param>
/// <param name="paramValue"></param>
public void ReadParamValueByPlc(IPlc _plc, string addr, string dataType, out int paramValue)
{
object result = null;
switch (dataType)
{
case "int":
result = _plc.ReadInt16(addr);
break;
case "float":
result = _plc.ReadFloat(addr);
break;
case "bool":
result = _plc.ReadBool(addr);
break;
default:
result = _plc.ReadInt16(addr);
break;
}
if (result == null)
{
result = "0";
}
paramValue = Convert.ToInt32(result);
}
/// <summary>
/// 电表数据解析
/// </summary>
/// <param name="data"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
private int[] ParseAndReverseByteArray(byte[] data, int startIndex, int length)
{
if (data == null || data.Length < startIndex + length)
{
throw new ArgumentException("Invalid data or startIndex/length parameter.");
}
int[] resultArray = new int[length / 2];
for (int i = 0; i < resultArray.Length; i++)
{
byte[] subset = new byte[2];
Array.Copy(data, startIndex + (i * 2), subset, 0, 2);
Array.Reverse(subset);
string hexString = BitConverter.ToString(subset).Replace("-", "");
resultArray[i] = Convert.ToInt32(hexString, 16);
}
return resultArray;
}
}
}

@ -0,0 +1,116 @@
using Admin.Core.Common;
using Admin.Core.IService.IService_New;
using Aucma.Core.DataCollector.Factory;
using log4net;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Org.BouncyCastle.Crypto.Tls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.DataCollector
{
public static class DataCollectorSetup
{
public static readonly log4net.ILog _logger = LogManager.GetLogger(typeof(DataCollectorSetup));
public static IApplicationBuilder UseDataCollectorExtensions(this IApplicationBuilder app)
{
if (app == null) throw new ArgumentNullException(nameof(app));
var stationCode = Appsettings.app("StationInfo", "StationCode");
var _deviceParamServices = app.ApplicationServices.GetService<IBaseDeviceParamServices>();
var _deviceAlarmInfoServices = app.ApplicationServices.GetService<IRecordDeviceAlarmInfoServices>();
var _deviceElectricityServices = app.ApplicationServices.GetService< IRecordDeviceElectricityServices>();
if (!string.IsNullOrEmpty(stationCode))
{
try
{
if (stationCode == "1002") //箱壳、内胆,包含预装线、集存库
{
Task.Run(() =>
{
DataCollectorFactory collector = new ShellStoreFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
Task.Run(() =>
{
DataCollectorFactory collector = new LinerStoreFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
}
else if (stationCode == "1005")//泡前库、发泡线、发泡机、泡后库
{
Task.Run(() =>
{
DataCollectorFactory collector = new BoxFoamFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
}
else if (stationCode == "1010")//成品分垛
{
//Task.Run(() =>
//{
// DataCollectorFactory collector = new PalletizFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
// Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
//});
Task.Run(() =>
{
DataCollectorFactory collector = new ShellStoreFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
Task.Run(() =>
{
DataCollectorFactory collector = new LinerStoreFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
Task.Run(() =>
{
DataCollectorFactory collector = new ShellPreassembleFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
Task.Run(() =>
{
DataCollectorFactory collector = new LinerPreassembleFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
Task.Run(() =>
{
DataCollectorFactory collector = new FoamBackFactory(_deviceParamServices, _deviceAlarmInfoServices, _deviceElectricityServices);
Parallel.Invoke(() => collector.CollectDeviceAlarmInfo(out var alarmInfos), () => collector.CollectDeviceElectricity(out var electricity));
});
}
}catch(Exception ex)
{
_logger.Error($"UseDataCollectorExtensions逻辑执行异常:{ex.Message}");
}
}
else
{
new InvalidOperationException($"设备数据采集逻辑初始化失败:未获取到工位编号");
}
return app;
}
}
}

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* Aucma.Core.DataCollector.Factory
* a4c93b2e-0cca-4fc8-be63-7f560c451cd9
*
* WenJY
* wenjy@mesnac.com
* 2024-03-28 11:16:52
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace Aucma.Core.DataCollector.Factory
{
/// <summary>
/// 泡前数据采集
/// </summary>
public class BeforeFoamFactory
{
}
}

@ -0,0 +1,91 @@
using Admin.Core.IService.IService_New;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.DataCollector.Factory
{
/// <summary>
/// 箱体发泡数据采集
/// </summary>
public class BoxFoamFactory : DataCollectorFactory
{
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("Test"));
public BoxFoamFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices) : base(deviceParamServices, deviceAlarmInfoServices, deviceElectricityServices)
{
}
/// <summary>
/// 采集泡前库、发泡线、发泡机、泡后库设备报警信息
/// </summary>
/// <param name="deviceAlarmInfos"></param>
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 == "E00009");
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("Test"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集泡前库、发泡线、发泡机、泡后库设备报警信息:{ex.Message}");
}
}
}
public override void CollectDeviceElectricity(out List<Record_DeviceElectricity> deviceElectricitys)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,186 @@
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
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* Aucma.Core.DataCollector.Factory
* d14bf35f-5d0b-4d74-a9a8-f7781f5c12cd
*
* WenJY
* wenjy@mesnac.com
* 2024-03-28 11:15:55
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace Aucma.Core.DataCollector.Factory
{
/// <summary>
/// 泡后数据采集
/// </summary>
public class FoamBackFactory : DataCollectorFactory
{
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("FoamBack"));
public FoamBackFactory(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 == "E00009");
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("FoamBack"));
}
}
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>();
//泡后集存库(10柜-主柜)
string[] address_10 = new string[] { "D7602", "D7604", "D7606", "D7608", "D7610", "D7612", "D7630", "D7634", "D7638", "D7642" };
Record_DeviceElectricity _deviceElectricity_10 = new Record_DeviceElectricity()
{
MonitorId = "E00009_0001"
};
base.ReadDeviceElectricity(address_10, plc, ref _deviceElectricity_10);
if(_deviceElectricity_10 != null)
{
deviceElectricitys.Add(_deviceElectricity_10);
}
//泡后集存库(09柜-分柜)IP10.10.92.40
string[] address_09 = new string[] { "D7652", "D7664", "D7666", "D7668", "D7660", "D7662", "D7680", "D7684", "D7688", "D7692" };
Record_DeviceElectricity _deviceElectricity_09 = new Record_DeviceElectricity()
{
MonitorId = "E00009_0002"
};
base.ReadDeviceElectricity(address_09, plc, ref _deviceElectricity_09);
if (_deviceElectricity_09 != null)
{
deviceElectricitys.Add(_deviceElectricity_09);
}
//泡后集存库(12柜-分柜)
string[] address_12 = new string[] { "D7752", "D7764", "D7766", "D7768", "D7760", "D7762", "D7780", "D7784", "D7788", "D7792" };
Record_DeviceElectricity _deviceElectricity_12 = new Record_DeviceElectricity()
{
MonitorId = "E00009_0003"
};
base.ReadDeviceElectricity(address_12, plc, ref _deviceElectricity_12);
if (_deviceElectricity_12 != null)
{
deviceElectricitys.Add(_deviceElectricity_12);
}
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("FoamBack"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集泡后库设备用电数据采集异常:{ex.Message}");
}
}
}
}
}

@ -0,0 +1,167 @@
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
* CLR4.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}");
}
}
}
}
}

@ -0,0 +1,138 @@
using Admin.Core.IService.IService_New;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.DataCollector.Factory
{
/// <summary>
/// 内胆预装、内胆库数据采集
/// </summary>
public class LinerStoreFactory : DataCollectorFactory
{
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("LinerStore"));
public LinerStoreFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices) : base(deviceParamServices, deviceAlarmInfoServices, deviceElectricityServices)
{
}
/// <summary>
/// 采集内胆库设备报警信息
/// </summary>
/// <param name="deviceAlarmInfos"></param>
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 == "E00032");
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("LinerStore"));
}
}
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[] address = new string[] { "D7602", "D7604", "D7606", "D7608", "D7610", "D7612", "D7630", "D7634", "D7638", "D7642" };
Record_DeviceElectricity _deviceElectricity_address = new Record_DeviceElectricity()
{
MonitorId = "E00032_0001"
};
base.ReadDeviceElectricity(address, plc, ref _deviceElectricity_address);
if( _deviceElectricity_address != null)
{
deviceElectricitys.Add(_deviceElectricity_address);
}
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("LinerStore"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集内胆库设备用电数据采集异常:{ex.Message}");
}
}
}
}
}

@ -0,0 +1,184 @@
using Admin.Core.Common.Helper;
using Admin.Core.IService.IService_New;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using log4net;
using System.Globalization;
namespace Aucma.Core.DataCollector.Factory
{
/// <summary>
/// 分垛入库数据采集
/// </summary>
public class PalletizFactory : DataCollectorFactory
{
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("Palletiz"));
public PalletizFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices) : base(deviceParamServices, deviceAlarmInfoServices, deviceElectricityServices)
{
}
/// <summary>
/// 采集成品分垛设备报警信息
/// </summary>
/// <param name="deviceAlarmInfos"></param>
/// <exception cref="NotImplementedException"></exception>
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 == "E00002");
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("Palletiz"));
}
}
catch(Exception ex)
{
base._logger.Error($"采集成品分垛设备报警信息异常:{ex.Message}");
}
}
}
/// <summary>
/// 采集设备用电信息
/// </summary>
/// <param name="deviceElectricity"></param>
/// <exception cref="NotImplementedException"></exception>
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 = "E0003"
};
base.ReadDeviceElectricity(ground, plc, ref _deviceElectricity_ground);
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 = "E0004"
};
base.ReadDeviceElectricity(platform, plc, ref _deviceElectricity_platform);
deviceElectricitys.Add(_deviceElectricity_platform);
var result = base._deviceElectricityServices.AddAsync(deviceElectricitys);
Task.Delay(base.EleReadTimer).Wait();
}
else
{
Task.Delay(base.EleReadTimer).Wait();
_plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("Palletiz"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集成品分垛设备用电数据采集异常:{ex.Message}");
}
}
}
public byte[] array(byte[] data)
{
if (data == null) return null;
for (int i = 0; i < data.Length; i += 2)
{
byte temp = data[i];
data[i] = data[i + 1];
data[i + 1] = temp;
}
return data;
}
/// <summary>
/// 用电数据解析
/// </summary>
/// <param name="data"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
private int[] ParseAndReverseByteArray(byte[] data, int startIndex, int length)
{
if (data == null || data.Length < startIndex + length)
{
throw new ArgumentException("Invalid data or startIndex/length parameter.");
}
int[] resultArray = new int[length / 2];
for (int i = 0; i < resultArray.Length; i++)
{
byte[] subset = new byte[2];
Array.Copy(data, startIndex + (i * 2), subset, 0, 2);
Array.Reverse(subset);
string hexString = BitConverter.ToString(subset).Replace("-", "");
resultArray[i] = Convert.ToInt32(hexString, 16);
}
return resultArray;
}
}
}

@ -0,0 +1,166 @@
using Admin.Core.IService.IService_New;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* Aucma.Core.DataCollector.Factory
* f88ccab0-cc8a-4d6f-8be8-1a0dbc687b9e
*
* WenJY
* wenjy@mesnac.com
* 2024-03-28 11:53:14
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace Aucma.Core.DataCollector.Factory
{
/// <summary>
/// 箱壳预装数据采集
/// </summary>
public class ShellPreassembleFactory : DataCollectorFactory
{
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("ShellPreassemble"));
public ShellPreassembleFactory(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 == "E00019");
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("ShellPreassemble"));
}
}
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 = "E00019_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 = "E00019_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("ShellPreassemble"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集箱壳库设备用电数据采集异常:{ex.Message}");
}
}
}
}
}

@ -0,0 +1,158 @@
using Admin.Core.IService.IService_New;
using Admin.Core.Model.Model_New;
using Aucma.Core.HwPLc;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.DataCollector.Factory
{
/// <summary>
/// 箱壳库数据采集
/// </summary>
public class ShellStoreFactory : DataCollectorFactory
{
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("ShellStore"));
public ShellStoreFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices) : base(deviceParamServices, deviceAlarmInfoServices, deviceElectricityServices)
{
}
/// <summary>
/// 采集箱壳库设备报警信息
/// </summary>
/// <param name="deviceAlarmInfos"></param>
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 == "E00031");
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("ShellStore"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集箱壳库设备报警信息异常:{ex.Message}");
}
}
}
/// <summary>
/// 采集箱壳库设备用电
/// </summary>
/// <param name="deviceElectricitys"></param>
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[] mainCabinet = new string[] { "D7602", "D7604", "D7606", "D7608", "D7610", "D7612", "D7630", "D7634", "D7638", "D7642" };
Record_DeviceElectricity _deviceElectricity_mainCabinet = new Record_DeviceElectricity()
{
MonitorId = "E00031_0001"
};
base.ReadDeviceElectricity(mainCabinet, plc, ref _deviceElectricity_mainCabinet);
if(_deviceElectricity_mainCabinet != null)
{
deviceElectricitys.Add(_deviceElectricity_mainCabinet);
}
//箱壳远程柜
string[] rangeCabinet = new string[] { "D7652", "D7664", "D7666", "D7668", "D7660", "D7662", "D7680", "D7684", "D7688", "D7692" };
Record_DeviceElectricity _deviceElectricity_rangeCabinet = new Record_DeviceElectricity()
{
MonitorId = "E00031_0002"
};
base.ReadDeviceElectricity(rangeCabinet, plc, ref _deviceElectricity_rangeCabinet);
if(_deviceElectricity_rangeCabinet != null)
{
deviceElectricitys.Add(_deviceElectricity_rangeCabinet);
}
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("ShellStore"));
}
}
catch (Exception ex)
{
base._logger.Error($"采集箱壳库设备用电数据采集异常:{ex.Message}");
}
}
}
}
}

File diff suppressed because it is too large Load Diff

@ -1,19 +0,0 @@

namespace Aucma.Core.SheetMetalTasks
{
public interface IAucamSheetMetalTaskService
{
/// <summary>
/// 钣金计划任务
/// </summary>
Task SheetMetalTasks();
Task SendSidePanelPlan();
Task SendBackPanelPlan();
Task ExecUpdateComplatePlan();
Task ExecProcessTheEndTask();
}
}

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.SheetMetalTasks.Models
{
/// <summary>
/// 前后板料仓型号
/// </summary>
public class Bin
{
/// <summary>
/// 料仓Id
/// </summary>
public string? ProductId { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool Status { get; set; }
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save