change-灌注修改

dev
liuwf 11 months ago
parent 5c0b58f0a8
commit 6d1c92f39c

@ -22,14 +22,14 @@ namespace Aucma.Core.Tasks.Business
public class PerfusionCollection public class PerfusionCollection
{ {
Semaphore semaphore = new Semaphore(1, 1); Semaphore semaphore = new Semaphore(1, 1);
protected readonly IPerfusionRecordServices? _perfusionRecordServices ; protected readonly IPerfusionRecordServices? _perfusionRecordServices;
protected readonly IPerfusionAlarmServices ?_perfusionAlarmServices; protected readonly IPerfusionAlarmServices? _perfusionAlarmServices;
protected readonly IPerfusionDeviceStatusServices? _perfusionDeviceStatusServices; protected readonly IPerfusionDeviceStatusServices? _perfusionDeviceStatusServices;
private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
private Perfusion_Record record ; private Perfusion_Record record;
private Perfusion_Record temprRecord ; private Perfusion_Record temprRecord;
private Perfusion_DeviceStatus perfusion_DeviceStatus = new Perfusion_DeviceStatus(); private Perfusion_DeviceStatus perfusion_DeviceStatus = new Perfusion_DeviceStatus();
private Perfusion_Alarm perfusion_Alarm = new Perfusion_Alarm(); private Perfusion_Alarm perfusion_Alarm = new Perfusion_Alarm();
@ -45,18 +45,25 @@ namespace Aucma.Core.Tasks.Business
public void startCollect() public void startCollect()
{ {
Task.Run(() => Task.Run(() =>
{
Thread.Sleep(3000);
Console.WriteLine("灌注数据采集服务开启");
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc"));
if (obj != null)
{ {
while (true) while (true)
{ {
try try
{ {
Thread.Sleep(2000);
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc"));
if (obj != null && obj.plc.IsConnected)
{
//采集数据 //采集数据
record = ReadEquipSystem(obj,record, perfusion_DeviceStatus, perfusion_Alarm); record = ReadEquipSystem(obj, record, perfusion_DeviceStatus, perfusion_Alarm);
//更新设备状态 if (string.IsNullOrEmpty(record.PerfusionBoxCode)) continue;
if (temprRecord == null)
{
temprRecord = _perfusionRecordServices.Query(d => d.PerfusionBoxCode.Equals(record.PerfusionBoxCode)).FirstOrDefault();
}
#region 更新设备状态
Perfusion_DeviceStatus device = _perfusionDeviceStatusServices.FirstAsync().Result; Perfusion_DeviceStatus device = _perfusionDeviceStatusServices.FirstAsync().Result;
if (device == null) if (device == null)
{ {
@ -67,51 +74,40 @@ namespace Aucma.Core.Tasks.Business
device.PerfusionStatus = perfusion_DeviceStatus.PerfusionStatus; device.PerfusionStatus = perfusion_DeviceStatus.PerfusionStatus;
var rsult = _perfusionDeviceStatusServices.UpdateAsync(device).Result; var rsult = _perfusionDeviceStatusServices.UpdateAsync(device).Result;
} }
#endregion
//// 更新报警信息 #region 更新报警信息
if (perfusion_Alarm.PerfusionStatus > 0) if (perfusion_Alarm.PerfusionStatus > 0)
{ {
int a = _perfusionAlarmServices.AddAsync(perfusion_Alarm).Result; int a = _perfusionAlarmServices.AddAsync(perfusion_Alarm).Result;
} }
#endregion
//Perfusion_Alarm alarmRecord = _perfusionAlarmServices.FirstAsync(x=>x.PerfusionBoxcode==perfusion_Alarm.PerfusionBoxcode).Result;
//if (alarmRecord == null)
//{
//}
//充注结束 //充注结束
if (record.PerfusionFinishStatus == "1") if (record.PerfusionFinishStatus == "1")
{ {
//缓存没数据查数据库 // 箱体码和上次不一样,或者箱体码一样但是充铸结果不一样
if(temprRecord == null) if (temprRecord == null || temprRecord.PerfusionBoxCode != record.PerfusionBoxCode || (temprRecord.PerfusionBoxCode == record.PerfusionBoxCode && temprRecord.PerfusionResult != record.PerfusionResult))
{ {
Perfusion_Record lastRecord = _perfusionRecordServices.Query(d => d.PerfusionBoxCode.Equals(record.PerfusionBoxCode)).FirstOrDefault(); int result = _perfusionRecordServices.AddAsync(record).Result;
// 数据库没有数据 if (result > 0)
if (lastRecord == null && !string.IsNullOrEmpty(record.PerfusionBoxCode))
{ {
_= _perfusionRecordServices.AddAsync(record).Result; Console.WriteLine(record.ToJson());
temprRecord = record;
return;
}
} }
// 箱体码和上次不一样,或者箱体码一样但是充铸结果不一样
else if(temprRecord.PerfusionBoxCode!=record.PerfusionBoxCode || (temprRecord.PerfusionBoxCode == record.PerfusionBoxCode && temprRecord.PerfusionResult!=record.PerfusionResult) )
{
_ = _perfusionRecordServices.AddAsync(record).Result;
} }
} }
}
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex); Console.WriteLine(ex);
} }
finally
{ Thread.Sleep(2000);
temprRecord = record;
} }
} }
@ -147,7 +143,7 @@ namespace Aucma.Core.Tasks.Business
record.UpdatedBy = "equip"; record.UpdatedBy = "equip";
record.UpdatedTime = DateTime.Now; record.UpdatedTime = DateTime.Now;
#endregion #endregion
Console.WriteLine("灌注记录:" + record.ToJson()); // Console.WriteLine("灌注记录:" + record.ToJson());
#region 设备状态赋值 #region 设备状态赋值
deviceStatus.PerfusionDevicetype = "灌注"; deviceStatus.PerfusionDevicetype = "灌注";
deviceStatus.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(50).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); deviceStatus.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(50).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
@ -156,7 +152,7 @@ namespace Aucma.Core.Tasks.Business
deviceStatus.UpdatedBy = "equip"; deviceStatus.UpdatedBy = "equip";
deviceStatus.UpdatedTime = DateTime.Now; deviceStatus.UpdatedTime = DateTime.Now;
#endregion #endregion
Console.WriteLine("设备状态:" + deviceStatus.ToJson()); // Console.WriteLine("设备状态:" + deviceStatus.ToJson());
#region 设备报警赋值 #region 设备报警赋值
alarmInfo.PerfusionBoxcode = record.PerfusionBoxCode; alarmInfo.PerfusionBoxcode = record.PerfusionBoxCode;
alarmInfo.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(52).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); alarmInfo.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(52).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
@ -167,8 +163,8 @@ namespace Aucma.Core.Tasks.Business
alarmInfo.UpdatedBy = "equip"; alarmInfo.UpdatedBy = "equip";
alarmInfo.UpdatedTime = DateTime.Now; alarmInfo.UpdatedTime = DateTime.Now;
#endregion #endregion
Console.WriteLine("报警信息:" + alarmInfo.ToJson()); // Console.WriteLine("报警信息:" + alarmInfo.ToJson());
Console.WriteLine("\n"); // Console.WriteLine("\n");
return record; return record;
} }
static string AlarmTrans(short code) static string AlarmTrans(short code)
@ -176,6 +172,7 @@ namespace Aucma.Core.Tasks.Business
string result = ""; string result = "";
switch (code) switch (code)
{ {
case 2: result = "充注枪真空不合格"; break; case 2: result = "充注枪真空不合格"; break;
case 4: result = "充注故障"; break; case 4: result = "充注故障"; break;
case 8: result = "充注时真空度超限定"; break; case 8: result = "充注时真空度超限定"; break;

Loading…
Cancel
Save