|
|
|
@ -45,18 +45,25 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
public void startCollect()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
Console.WriteLine("灌注数据采集服务开启");
|
|
|
|
|
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc"));
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
//更新设备状态
|
|
|
|
|
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;
|
|
|
|
|
if (device == null)
|
|
|
|
|
{
|
|
|
|
@ -67,51 +74,40 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
device.PerfusionStatus = perfusion_DeviceStatus.PerfusionStatus;
|
|
|
|
|
var rsult = _perfusionDeviceStatusServices.UpdateAsync(device).Result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//// 更新报警信息
|
|
|
|
|
#region 更新报警信息
|
|
|
|
|
if (perfusion_Alarm.PerfusionStatus > 0)
|
|
|
|
|
{
|
|
|
|
|
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(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();
|
|
|
|
|
// 数据库没有数据
|
|
|
|
|
if (lastRecord == null && !string.IsNullOrEmpty(record.PerfusionBoxCode))
|
|
|
|
|
int result = _perfusionRecordServices.AddAsync(record).Result;
|
|
|
|
|
if (result > 0)
|
|
|
|
|
{
|
|
|
|
|
_= _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)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(ex);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
temprRecord = record;
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -147,7 +143,7 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
record.UpdatedBy = "equip";
|
|
|
|
|
record.UpdatedTime = DateTime.Now;
|
|
|
|
|
#endregion
|
|
|
|
|
Console.WriteLine("灌注记录:" + record.ToJson());
|
|
|
|
|
// Console.WriteLine("灌注记录:" + record.ToJson());
|
|
|
|
|
#region 设备状态赋值
|
|
|
|
|
deviceStatus.PerfusionDevicetype = "灌注";
|
|
|
|
|
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.UpdatedTime = DateTime.Now;
|
|
|
|
|
#endregion
|
|
|
|
|
Console.WriteLine("设备状态:" + deviceStatus.ToJson());
|
|
|
|
|
// Console.WriteLine("设备状态:" + deviceStatus.ToJson());
|
|
|
|
|
#region 设备报警赋值
|
|
|
|
|
alarmInfo.PerfusionBoxcode = record.PerfusionBoxCode;
|
|
|
|
|
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.UpdatedTime = DateTime.Now;
|
|
|
|
|
#endregion
|
|
|
|
|
Console.WriteLine("报警信息:" + alarmInfo.ToJson());
|
|
|
|
|
Console.WriteLine("\n");
|
|
|
|
|
// Console.WriteLine("报警信息:" + alarmInfo.ToJson());
|
|
|
|
|
// Console.WriteLine("\n");
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
static string AlarmTrans(short code)
|
|
|
|
@ -176,6 +172,7 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
string result = "";
|
|
|
|
|
switch (code)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
case 2: result = "充注枪真空不合格"; break;
|
|
|
|
|
case 4: result = "充注故障"; break;
|
|
|
|
|
case 8: result = "充注时真空度超限定"; break;
|
|
|
|
|