|
|
@ -12,23 +12,14 @@ namespace Aucma.Core.DataCollector.Factory
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class PalletizFactory : DataCollectorFactory
|
|
|
|
public class PalletizFactory : DataCollectorFactory
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("Test"));
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly log4net.ILog _logger = LogManager.GetLogger(typeof(PalletizFactory));
|
|
|
|
public PalletizFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices) : base(deviceParamServices, deviceAlarmInfoServices, deviceElectricityServices)
|
|
|
|
private readonly IBaseDeviceParamServices _deviceParamServices;
|
|
|
|
|
|
|
|
private readonly IRecordDeviceAlarmInfoServices _deviceAlarmInfoServices;
|
|
|
|
|
|
|
|
private readonly IRecordDeviceElectricityServices _deviceElectricityServices;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PalletizFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_deviceParamServices = deviceParamServices;
|
|
|
|
|
|
|
|
_deviceAlarmInfoServices = deviceAlarmInfoServices;
|
|
|
|
|
|
|
|
_deviceElectricityServices = deviceElectricityServices;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private PlcModel _plc = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("Test"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 采集设备报警信息
|
|
|
|
/// 采集成品分垛设备报警信息
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="deviceAlarmInfos"></param>
|
|
|
|
/// <param name="deviceAlarmInfos"></param>
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
@ -41,10 +32,10 @@ namespace Aucma.Core.DataCollector.Factory
|
|
|
|
|
|
|
|
|
|
|
|
if (_plc != null)
|
|
|
|
if (_plc != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}采集设备报警信息");
|
|
|
|
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}采集成品分垛设备报警信息");
|
|
|
|
var plc = _plc.plc;
|
|
|
|
var plc = _plc.plc;
|
|
|
|
|
|
|
|
|
|
|
|
var deviceParams = _deviceParamServices.Query(x => x.DeviceCode == "E00002");
|
|
|
|
var deviceParams = base._deviceParamServices.Query(x => x.DeviceCode == "E00002");
|
|
|
|
|
|
|
|
|
|
|
|
if (deviceParams != null)
|
|
|
|
if (deviceParams != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -52,9 +43,9 @@ namespace Aucma.Core.DataCollector.Factory
|
|
|
|
string batchId = System.Guid.NewGuid().ToString("N");
|
|
|
|
string batchId = System.Guid.NewGuid().ToString("N");
|
|
|
|
foreach (var item in deviceParams)
|
|
|
|
foreach (var item in deviceParams)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ReadParamValueByPlc(plc, item.ParamAddress, item.ParamType, out string paramValue);
|
|
|
|
base.ReadParamValueByPlc(plc, item.ParamAddress, item.ParamType, out int paramValue);
|
|
|
|
|
|
|
|
|
|
|
|
if (paramValue != "0")
|
|
|
|
if (paramValue != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
deviceAlarmInfos.Add(new Record_DeviceAlarmInfo()
|
|
|
|
deviceAlarmInfos.Add(new Record_DeviceAlarmInfo()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -62,7 +53,7 @@ namespace Aucma.Core.DataCollector.Factory
|
|
|
|
DeviceCode = item.DeviceCode,
|
|
|
|
DeviceCode = item.DeviceCode,
|
|
|
|
DeviceType = "1",
|
|
|
|
DeviceType = "1",
|
|
|
|
ParamCode = item.ParamCode,
|
|
|
|
ParamCode = item.ParamCode,
|
|
|
|
ParamValue = paramValue as string,
|
|
|
|
ParamValue = paramValue.ToString(),
|
|
|
|
AlarmInfo = item.ParamName,
|
|
|
|
AlarmInfo = item.ParamName,
|
|
|
|
AlarmTime = DateTime.Now,
|
|
|
|
AlarmTime = DateTime.Now,
|
|
|
|
CreadtedTime = DateTime.Now,
|
|
|
|
CreadtedTime = DateTime.Now,
|
|
|
@ -72,7 +63,7 @@ namespace Aucma.Core.DataCollector.Factory
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (deviceAlarmInfos.Count > 0)
|
|
|
|
if (deviceAlarmInfos.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_deviceAlarmInfoServices.AddAsync(deviceAlarmInfos);
|
|
|
|
base._deviceAlarmInfoServices.AddAsync(deviceAlarmInfos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Task.Delay(1000 * 5).Wait();
|
|
|
|
Task.Delay(1000 * 5).Wait();
|
|
|
@ -85,7 +76,7 @@ namespace Aucma.Core.DataCollector.Factory
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
catch(Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Error($"成品分垛设备报警信息采集异常:{ex.Message}");
|
|
|
|
base._logger.Error($"采集成品分垛设备报警信息异常:{ex.Message}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -150,7 +141,7 @@ namespace Aucma.Core.DataCollector.Factory
|
|
|
|
|
|
|
|
|
|
|
|
if(deviceElectricity.Zxyg > 0)
|
|
|
|
if(deviceElectricity.Zxyg > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = _deviceElectricityServices.AddAsync(deviceElectricity);
|
|
|
|
var result = base._deviceElectricityServices.AddAsync(deviceElectricity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Task.Delay(1000 * 5).Wait();
|
|
|
|
Task.Delay(1000 * 5).Wait();
|
|
|
@ -164,45 +155,11 @@ namespace Aucma.Core.DataCollector.Factory
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
catch(Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Error($"成品分垛设备用电数据采集异常:{ex.Message}");
|
|
|
|
base._logger.Error($"成品分垛设备用电数据采集异常:{ex.Message}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 读取PLC数据
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="_plc"></param>
|
|
|
|
|
|
|
|
/// <param name="addr"></param>
|
|
|
|
|
|
|
|
/// <param name="dataType"></param>
|
|
|
|
|
|
|
|
/// <param name="paramValue"></param>
|
|
|
|
|
|
|
|
private void ReadParamValueByPlc(IPlc _plc,string addr,string dataType,out string 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 = result.ToString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 用电数据解析
|
|
|
|
/// 用电数据解析
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|