|
|
|
@ -5,6 +5,8 @@ using Admin.Core.Model;
|
|
|
|
|
using Admin.Core.Model.Model_New;
|
|
|
|
|
|
|
|
|
|
using Aucma.Core.HwPLc;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using StackExchange.Profiling.Internal;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
@ -26,8 +28,8 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
|
|
|
|
|
private Perfusion_Record record = new Perfusion_Record();
|
|
|
|
|
private Perfusion_Record temprRecord;
|
|
|
|
|
private Perfusion_Record record ;
|
|
|
|
|
private Perfusion_Record temprRecord ;
|
|
|
|
|
|
|
|
|
|
private Perfusion_DeviceStatus perfusion_DeviceStatus = new Perfusion_DeviceStatus();
|
|
|
|
|
private Perfusion_Alarm perfusion_Alarm = new Perfusion_Alarm();
|
|
|
|
@ -48,12 +50,12 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc"));
|
|
|
|
|
if (obj != null && obj.plc.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
//采集数据
|
|
|
|
|
ReadEquipSystem(obj,record, perfusion_DeviceStatus, perfusion_Alarm);
|
|
|
|
|
record = ReadEquipSystem(obj,record, perfusion_DeviceStatus, perfusion_Alarm);
|
|
|
|
|
//更新设备状态
|
|
|
|
|
Perfusion_DeviceStatus device = _perfusionDeviceStatusServices.FirstAsync().Result;
|
|
|
|
|
if (device == null)
|
|
|
|
@ -62,11 +64,16 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_perfusionDeviceStatusServices.UpdateAsync(perfusion_DeviceStatus);
|
|
|
|
|
device.PerfusionStatus = perfusion_DeviceStatus.PerfusionStatus;
|
|
|
|
|
var rsult = _perfusionDeviceStatusServices.UpdateAsync(device).Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//// 更新报警信息
|
|
|
|
|
_perfusionAlarmServices.AddAsync(perfusion_Alarm);
|
|
|
|
|
if (perfusion_Alarm.PerfusionStatus > 0)
|
|
|
|
|
{
|
|
|
|
|
int a = _perfusionAlarmServices.AddAsync(perfusion_Alarm).Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Perfusion_Alarm alarmRecord = _perfusionAlarmServices.FirstAsync(x=>x.PerfusionBoxcode==perfusion_Alarm.PerfusionBoxcode).Result;
|
|
|
|
|
//if (alarmRecord == null)
|
|
|
|
|
//{
|
|
|
|
@ -81,9 +88,10 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
{
|
|
|
|
|
Perfusion_Record lastRecord = _perfusionRecordServices.Query(d => d.PerfusionBoxCode.Equals(record.PerfusionBoxCode)).FirstOrDefault();
|
|
|
|
|
// 数据库没有数据
|
|
|
|
|
if (lastRecord == null)
|
|
|
|
|
if (lastRecord == null && !string.IsNullOrEmpty(record.PerfusionBoxCode))
|
|
|
|
|
{
|
|
|
|
|
_= _perfusionRecordServices.AddAsync(record).Result;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -91,6 +99,7 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
else if(temprRecord.PerfusionBoxCode!=record.PerfusionBoxCode || (temprRecord.PerfusionBoxCode == record.PerfusionBoxCode && temprRecord.PerfusionResult!=record.PerfusionResult) )
|
|
|
|
|
{
|
|
|
|
|
_ = _perfusionRecordServices.AddAsync(record).Result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -104,6 +113,7 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
{
|
|
|
|
|
temprRecord = record;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
@ -113,42 +123,43 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
/// 采集灌注参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
static void ReadEquipSystem(Aucma.Core.HwPLc.PlcModel obj, Perfusion_Record record, Perfusion_DeviceStatus deviceStatus, Perfusion_Alarm alarmInfo)
|
|
|
|
|
static Perfusion_Record ReadEquipSystem(Aucma.Core.HwPLc.PlcModel obj, Perfusion_Record record, Perfusion_DeviceStatus deviceStatus, Perfusion_Alarm alarmInfo)
|
|
|
|
|
{
|
|
|
|
|
byte[] info = obj.plc.Read("DB55.0", 54);
|
|
|
|
|
if (info == null) return;
|
|
|
|
|
record = new Perfusion_Record();
|
|
|
|
|
byte[] info = obj.plc.Read("DB55.0", 84);
|
|
|
|
|
if (info == null) return null;
|
|
|
|
|
#region 灌注记录赋值
|
|
|
|
|
record.PerfusionActualVolume=byteToDouble(info.Skip(0).Take(8).ToArray()).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionActualVolume = byteToDouble(info.Skip(0).Take(8).ToArray()).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionR = byteToFloat(info.Skip(8).Take(4).ToArray()).ToString().ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionL = byteToFloat(info.Skip(50).Take(4).ToArray()).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionL = byteToFloat(info.Skip(54).Take(4).ToArray()).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionDuration = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
|
|
|
|
|
record.Yield = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionBoxCode = asciiEncoding.GetString(info.Skip(20).Take(24).ToArray()).Trim('\n').Replace("\0", "");
|
|
|
|
|
// record.PerfusionRefrigerantTypeLeft = asciiEncoding.GetString(info.Skip(58).Take(7).ToArray()).Trim('\n').Replace("\0", "");
|
|
|
|
|
// record.PerfusionRefrigerantTypeRight = asciiEncoding.GetString(info.Skip(68).Take(7).ToArray()).Trim('\n').Replace("\0", "");
|
|
|
|
|
// record.PerfusionSetVolume = byteToFloat(info.Skip(78).Take(4).ToArray()).ToString().Replace("\0", "");
|
|
|
|
|
// record.PerfusionSystem =short.Parse(StringChange.bytesToHexStr(info.Skip(82).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionBoxCode = asciiEncoding.GetString(info.Skip(22).Take(24).ToArray()).Trim('\n').Replace("\0", "");
|
|
|
|
|
record.PerfusionRefrigerantTypeLeft = asciiEncoding.GetString(info.Skip(58).Take(7).ToArray()).Trim('\n').Replace("\0", "");
|
|
|
|
|
record.PerfusionRefrigerantTypeRight = asciiEncoding.GetString(info.Skip(68).Take(7).ToArray()).Trim('\n').Replace("\0", "");
|
|
|
|
|
record.PerfusionSetVolume = byteToFloat(info.Skip(78).Take(4).ToArray()).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionSystem = short.Parse(StringChange.bytesToHexStr(info.Skip(82).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
|
|
|
|
|
///灌注完成状态字
|
|
|
|
|
record.PerfusionFinishStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(42).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionResult = short.Parse(StringChange.bytesToHexStr(info.Skip(44).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
|
|
|
|
|
record.PerfusionFinishStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(46).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString().Replace("\0", "");
|
|
|
|
|
record.PerfusionResult = short.Parse(StringChange.bytesToHexStr(info.Skip(48).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
|
|
|
|
|
record.CreatedBy = "equip";
|
|
|
|
|
record.CreatedTime = DateTime.Now;
|
|
|
|
|
record.UpdatedBy = "equip";
|
|
|
|
|
record.UpdatedTime = DateTime.Now;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("灌注记录:" + record.ToJson());
|
|
|
|
|
#region 设备状态赋值
|
|
|
|
|
deviceStatus.PerfusionDevicetype = "灌注";
|
|
|
|
|
deviceStatus.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(46).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);
|
|
|
|
|
deviceStatus.CreatedBy = "equip";
|
|
|
|
|
deviceStatus.CreatedTime = DateTime.Now;
|
|
|
|
|
deviceStatus.UpdatedBy = "equip";
|
|
|
|
|
deviceStatus.UpdatedTime = DateTime.Now;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("设备状态:" + deviceStatus.ToJson());
|
|
|
|
|
#region 设备报警赋值
|
|
|
|
|
alarmInfo.PerfusionBoxcode = record.PerfusionBoxCode;
|
|
|
|
|
alarmInfo.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(48).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);
|
|
|
|
|
alarmInfo.PerfusionAlarm = AlarmTrans(alarmInfo.PerfusionStatus);
|
|
|
|
|
alarmInfo.PerfusionCompleted = "1";
|
|
|
|
|
alarmInfo.CreatedBy = "equip";
|
|
|
|
@ -156,6 +167,9 @@ namespace Aucma.Core.Tasks.Business
|
|
|
|
|
alarmInfo.UpdatedBy = "equip";
|
|
|
|
|
alarmInfo.UpdatedTime = DateTime.Now;
|
|
|
|
|
#endregion
|
|
|
|
|
Console.WriteLine("报警信息:" + alarmInfo.ToJson());
|
|
|
|
|
Console.WriteLine("\n");
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
static string AlarmTrans(short code)
|
|
|
|
|
{
|
|
|
|
|