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.

175 lines
7.7 KiB
C#

1 year ago
using Admin.Core.IService;
using Admin.Core.Model;
1 year ago
using Aucma.Core.HwPLc;
1 year ago
using log4net;
/// <summary>
/// 灌注数据采集
/// </summary>
namespace Aucma.Core.Tasks
{
public class Job_PerfusionTask
1 year ago
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(Job_PerfusionTask));
1 year ago
protected readonly IBaseOrderInfoServices _baseOrderInfoServices;
protected readonly IPerfusionDeviceStatusServices _perfusionDeviceStatusServices;
protected readonly IPerfusionAlarmServices _perfusionAlarmServices;
protected readonly IPerfusionRecordServices _perfusionRecordServices;
public Job_PerfusionTask(IPerfusionDeviceStatusServices perfusionDeviceStatusServices, IPerfusionAlarmServices perfusionAlarmServices,
1 year ago
IPerfusionRecordServices perfusionRecordServices)
{
_perfusionDeviceStatusServices = perfusionDeviceStatusServices;
_perfusionAlarmServices = perfusionAlarmServices;
_perfusionRecordServices = perfusionRecordServices;
}
public async Task Execute()
{
await SaveDbRun();
await DeviceStatusRun();
}
#region 检测设备状态
private async Task DeviceStatusRun()
{
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc"));
if (obj.plc.IsConnected)
{
var status = obj.plc.ReadInt32("DB55.46.0");//设备状态;1运行、2停机、3故障
//更新灌注设备状态
var deviceStatus = await _perfusionDeviceStatusServices.FirstAsync();
deviceStatus.PerfusionStatus = status;
await _perfusionDeviceStatusServices.UpdateAsync(deviceStatus);
}
else
{
log.Error("灌注PLC连接异常");
}
}
#endregion
#region 保存灌注数据
public async Task SaveDbRun()
{
string alarmName = string.Empty;
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc"));
if (obj.plc.IsConnected)
{
var endSignal = obj.plc.ReadInt16("DB55.44.0");//任务结束信号存盘
/*
* 8
* 4
* */
if (endSignal == 8)
{
try
{
var barCode = obj.plc.ReadString("DB55.20.0");//箱体条码
var perfusionRecord = await _perfusionRecordServices.FirstAsync(d=>d.PerfusionBoxCode.Equals(barCode));
if (perfusionRecord == null) return;
var refrigerantTypeLeft = obj.plc.ReadString("DB55.58.0");//冷媒类型——左侧冷媒型号
var refrigerantTypeRight = obj.plc.ReadString("DB55.68.0");//冷媒类型——右侧冷媒型号
var setVolume = obj.plc.ReadDouble("DB55.78.0");//设定灌注量
var actualVolume = obj.plc.ReadDouble("DB55.0.0");//实际灌注量
var pressureR = obj.plc.ReadDouble("DB55.8.0");//灌注压力——灌注压力_R
var pressureL = obj.plc.ReadDouble("DB55.50.0");//灌注压力——灌注压力_L
var duration = obj.plc.ReadInt16("DB55.12.0");//灌注时长
var system = obj.plc.ReadInt32("DB55.82.0");//0,右系统 1左系统
Perfusion_Record record = new Perfusion_Record();
record.PerfusionBoxCode = barCode;
record.PerfusionRefrigerantTypeLeft = refrigerantTypeLeft;
record.PerfusionRefrigerantTypeRight = refrigerantTypeRight;
record.PerfusionSetVolume = setVolume.ToString();
record.PerfusionActualVolume = actualVolume.ToString();
record.PerfusionR = pressureR.ToString();
record.PerfusionL = pressureL.ToString();
record.PerfusionDuration = duration.ToString();
record.PerfusionSystem = system.ToString();
var r = await _perfusionRecordServices.AddAsync(record);
if (r > 0)
{
//数据采集完成设为2
obj.plc.WriteInt32("DB55.44.0", 2);//应答字:1数据采集2存盘成功
}
else
{
log.Error($"存盘数据失败,箱体码[{barCode}]");
}
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
/*
*2:
*4
*8
*16
*32
*64
*128
*256
* */
if (endSignal == 4)
{
try
{
var barCode = obj.plc.ReadString("DB55.20.0");//箱体条码
var perfusionAlarm = await _perfusionAlarmServices.FirstAsync(d => d.PerfusionBoxcode.Equals(barCode));
if (perfusionAlarm != null) return;
var alarm = obj.plc.ReadInt32("DB55.48.0");
//保存到异常任务表中,通知返修检测
switch (alarm)
{
case 0:
alarmName = "充注枪真空不合格";
break;
case 4:
alarmName = "充注故障";
break;
case 8:
alarmName = "充注时真空度超限定";
break;
case 16:
alarmName = "回升检测不合格";
break;
case 32:
alarmName = "工件真空不合格";
break;
case 64:
alarmName = "平衡缸接近开关异常";
break;
case 128:
alarmName = "增压超时";
break;
case 256:
alarmName = "风压不足";
break;
default:
break;
}
Perfusion_Alarm alarm1 = new Perfusion_Alarm();
alarm1.PerfusionBoxcode = barCode;
1 year ago
alarm1.PerfusionStatus = (short)alarm;
1 year ago
alarm1.PerfusionAlarm = alarmName;
alarm1.PerfusionCompleted = "1";//异常取消
await _perfusionAlarmServices.AddAsync(alarm1);
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
}
}
#endregion
}
}