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.
185 lines
7.2 KiB
C#
185 lines
7.2 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|