|
@@ -80,6 +80,31 @@ namespace TeamAAS_VP.Core
|
|
|
Timer yieldtimer;
|
|
Timer yieldtimer;
|
|
|
private DateTime StartTime = DateTime.Now;
|
|
private DateTime StartTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
+ // Pressure collection
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 压力采集信号控制CTS
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private CancellationTokenSource[] _pressureCts = new CancellationTokenSource[10];
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 压力采集超时CTS
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private CancellationTokenSource[] _pressureTimeoutCts = new CancellationTokenSource[10];
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 压力采集CTS
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private CancellationTokenSource[] _pressureLinkedCts = new CancellationTokenSource[10];
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 压力数据集合
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private List<(DateTime Timestamp, float Value)>[] _pressureSamples = new List<(DateTime, float)>[10];
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 采样间隔毫秒
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private int _pressureSampleIntervalMs = 50; //采样间隔毫秒
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 超时自动停止秒数
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private int _pressureMaxDurationSeconds = 30; //超时自动停止秒数
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 属性
|
|
#region 属性
|
|
@@ -160,6 +185,15 @@ namespace TeamAAS_VP.Core
|
|
|
|
|
|
|
|
public Dictionary<string, object> BackupObject { get; set; } = new Dictionary<string, object>();
|
|
public Dictionary<string, object> BackupObject { get; set; } = new Dictionary<string, object>();
|
|
|
|
|
|
|
|
|
|
+ private double _CTtime;
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// ct
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public double CTtime
|
|
|
|
|
+ {
|
|
|
|
|
+ get { return _CTtime; }
|
|
|
|
|
+ set { SetProperty(ref _CTtime, value); }
|
|
|
|
|
+ }
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 命令
|
|
#region 命令
|
|
@@ -1064,6 +1098,7 @@ namespace TeamAAS_VP.Core
|
|
|
Int16 _LastRequestPosition = 0;
|
|
Int16 _LastRequestPosition = 0;
|
|
|
Int16 _LastPickINC = 0;
|
|
Int16 _LastPickINC = 0;
|
|
|
Int16[] _LastMesCheck = new Int16[10];
|
|
Int16[] _LastMesCheck = new Int16[10];
|
|
|
|
|
+ DateTime[] _LastMesCheckTime = new DateTime[10];
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// PLC命令触发时
|
|
/// PLC命令触发时
|
|
@@ -1157,8 +1192,8 @@ namespace TeamAAS_VP.Core
|
|
|
float toolX = (float)(visionResult.X - currentPosition.X);
|
|
float toolX = (float)(visionResult.X - currentPosition.X);
|
|
|
float toolY = (float)(visionResult.Y - currentPosition.Y);
|
|
float toolY = (float)(visionResult.Y - currentPosition.Y);
|
|
|
|
|
|
|
|
- DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolX, (float)visionResult.U);
|
|
|
|
|
- DownTool = new PointF(toolX, toolX);
|
|
|
|
|
|
|
+ DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolY, (float)visionResult.U);
|
|
|
|
|
+ DownTool = new PointF(toolX, toolY);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -1201,8 +1236,9 @@ namespace TeamAAS_VP.Core
|
|
|
float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
|
|
float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
|
|
|
float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
|
|
float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
|
|
|
_FixedUpCameraAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
|
|
_FixedUpCameraAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
|
|
|
- DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolX, (float)_FixedUpCameraAngle);
|
|
|
|
|
- DownTool = new PointF(toolX, toolX);
|
|
|
|
|
|
|
+ DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolY, (float)_FixedUpCameraAngle);
|
|
|
|
|
+ DownTool = new PointF(toolX, toolY);
|
|
|
|
|
+ SendTaskMessage($"固定向上相机拍照Tool: {DownTool.X:F3},{DownTool.Y:F3},{_FixedUpCameraAngle:F3}", MessageLevel.Info);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -1292,8 +1328,8 @@ namespace TeamAAS_VP.Core
|
|
|
float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
|
|
float toolX = (float)(visionResults[0].X + visionResults[1].X) / 2;
|
|
|
float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
|
|
float toolY = (float)(visionResults[0].Y + visionResults[1].Y) / 2;
|
|
|
_FixedUpCameraAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
|
|
_FixedUpCameraAngle = Common.CalculateAngleBetweenPointsDegrees(new PointF((float)visionResults[0].X, (float)visionResults[0].Y), new PointF((float)visionResults[1].X, (float)visionResults[1].Y));
|
|
|
- DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolX, (float)_FixedUpCameraAngle);
|
|
|
|
|
- DownTool = new PointF(toolX, toolX);
|
|
|
|
|
|
|
+ DowmCameraResults[cameraIndex] = new OpenCvSharp.Point3f(toolX, toolY, (float)_FixedUpCameraAngle);
|
|
|
|
|
+ DownTool = new PointF(toolX, toolY);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_DownCameraStatus.Address, (Int16)1);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -1474,7 +1510,7 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
{
|
|
|
float tool1X = (float)(visionResults[0].X - visionResults[0].X);
|
|
float tool1X = (float)(visionResults[0].X - visionResults[0].X);
|
|
|
float tool1Y = (float)(visionResults[0].Y - visionResults[0].Y);
|
|
float tool1Y = (float)(visionResults[0].Y - visionResults[0].Y);
|
|
|
- float tool2X = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
|
|
|
|
+ float tool2X = (float)(visionResults[1].X - visionResults[1].X);
|
|
|
float tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
float tool2Y = (float)(visionResults[1].Y - visionResults[1].Y);
|
|
|
float toolX = (tool1X + tool2X) / 2;
|
|
float toolX = (tool1X + tool2X) / 2;
|
|
|
float toolY = (tool1Y + tool2Y) / 2;
|
|
float toolY = (tool1Y + tool2Y) / 2;
|
|
@@ -1523,6 +1559,8 @@ namespace TeamAAS_VP.Core
|
|
|
Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPutNum.Address);
|
|
Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_UpCameraPutNum.Address);
|
|
|
SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
|
|
SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
|
|
|
|
|
|
|
|
|
|
+ //视觉流程ID
|
|
|
|
|
+ Guid procedureId = currentProduct.MoveDownCamera1LockPhotoProcedureId;
|
|
|
|
|
|
|
|
// 获取机器人当前坐标
|
|
// 获取机器人当前坐标
|
|
|
var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
@@ -1539,14 +1577,22 @@ namespace TeamAAS_VP.Core
|
|
|
//如果上相机2的流程id为空,则表示只有一个上相机
|
|
//如果上相机2的流程id为空,则表示只有一个上相机
|
|
|
if (currentProduct.MoveDownCamera2LockPhotoProcedureId == Guid.Empty)
|
|
if (currentProduct.MoveDownCamera2LockPhotoProcedureId == Guid.Empty)
|
|
|
{
|
|
{
|
|
|
- //获取移动向下相机1的流程
|
|
|
|
|
- var process = _productService.GetCurrentProductProcedureModelById(currentProduct.MoveDownCamera1LockPhotoProcedureId);
|
|
|
|
|
|
|
+ //获取锁付拍照的点位
|
|
|
|
|
+ var pos = currentProduct.ScrewCameraPoints.FirstOrDefault(p => p.Number == cameraIndex);
|
|
|
|
|
+ if (pos != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ procedureId = pos.VisionProcessID;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取移动向下相机的流程
|
|
|
|
|
+ var process = _productService.GetCurrentProductProcedureModelById(procedureId);
|
|
|
if (process == null)
|
|
if (process == null)
|
|
|
{
|
|
{
|
|
|
- SendTaskMessage($"移动向下相机1视觉流程,流程ID:{currentProduct.MoveDownCamera1LockPhotoProcedureId}", MessageLevel.Alarm);
|
|
|
|
|
|
|
+ SendTaskMessage($"未找到移动向下相机组装拍照对应的视觉流程流程ID:{procedureId}", MessageLevel.Alarm);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)2);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// 执行视觉任务
|
|
// 执行视觉任务
|
|
|
var _cts = new CancellationTokenSource();
|
|
var _cts = new CancellationTokenSource();
|
|
|
var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(process, null, new double[] { currentPosition.X, currentPosition.Y, currentPosition.U }, _cts.Token);
|
|
@@ -1558,6 +1604,7 @@ namespace TeamAAS_VP.Core
|
|
|
if (visionResult.IsSucceed)
|
|
if (visionResult.IsSucceed)
|
|
|
{
|
|
{
|
|
|
UpCameraPutResults[cameraIndex] = new OpenCvSharp.Point3f((float)visionResult.X, (float)visionResult.Y, (float)visionResult.U);
|
|
UpCameraPutResults[cameraIndex] = new OpenCvSharp.Point3f((float)visionResult.X, (float)visionResult.Y, (float)visionResult.U);
|
|
|
|
|
+ SendTaskMessage($"移动向下相机拍照[{cameraIndex}]结果: {UpCameraPutResults[cameraIndex].X:F3},{UpCameraPutResults[cameraIndex].Y:F3},{UpCameraPutResults[cameraIndex].Z:F3}", MessageLevel.Info);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)1);
|
|
await plc.WriteNodeAsync(addressConfig.Out_UpCameraPutStatus.Address, (Int16)1);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -1760,6 +1807,10 @@ namespace TeamAAS_VP.Core
|
|
|
//位置编号
|
|
//位置编号
|
|
|
Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
|
|
Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
|
|
|
SendTaskMessage($"编号:{positionIndex}", MessageLevel.Info);
|
|
SendTaskMessage($"编号:{positionIndex}", MessageLevel.Info);
|
|
|
|
|
+
|
|
|
|
|
+ var code = plc.ReadNode<string>(string.Format(addressConfig.In_Code.Address, positionIndex));
|
|
|
|
|
+ // 开始采集压力值
|
|
|
|
|
+ StartPressureCollection(currentProduct.Name, code, positionIndex);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -1789,48 +1840,51 @@ namespace TeamAAS_VP.Core
|
|
|
Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
|
|
Int16 positionIndex = plc.ReadNode<Int16>(addressConfig.In_ProductNum.Address);
|
|
|
SendTaskMessage($"编号:{positionIndex}", MessageLevel.Info);
|
|
SendTaskMessage($"编号:{positionIndex}", MessageLevel.Info);
|
|
|
//获取当前锁付点
|
|
//获取当前锁付点
|
|
|
- var screwPoint = currentProduct.ScrewPoints.FirstOrDefault(p => p.Number == positionIndex);
|
|
|
|
|
- //获取当前的机器人点位
|
|
|
|
|
- var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
|
|
|
- var currentPosition = robot.GetRobotPos();
|
|
|
|
|
- //读取压力值
|
|
|
|
|
- float pressure = plc.ReadNode<float>(addressConfig.In_PressureValue.Address);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- await Task.Delay(60);
|
|
|
|
|
- //获取电批结果
|
|
|
|
|
- bool isSucced = ScrewDriver.GetData();
|
|
|
|
|
- LockResult lockResult = new LockResult();
|
|
|
|
|
- lockResult.ScrewdriverGetDataSucceed = isSucced;
|
|
|
|
|
- lockResult.Number = positionIndex;
|
|
|
|
|
- lockResult.LockPassed = ScrewDriver.Success;
|
|
|
|
|
- lockResult.ProductNumber = _productService.CurrentProductCode;
|
|
|
|
|
- lockResult.LockTurns = (float)ScrewDriver.Truns;
|
|
|
|
|
- lockResult.LockTorque = (float)ScrewDriver.TorqueValue;
|
|
|
|
|
- lockResult.LockDuration = (float)ScrewDriver.FinalTime;
|
|
|
|
|
- lockResult.ScrewdriverProgramNumber = ScrewDriver.ProgramNumber;
|
|
|
|
|
- lockResult.ResultDetails = ScrewDriver.ErrorInfo;
|
|
|
|
|
- lockResult.Pressure = pressure;
|
|
|
|
|
- lockResult.TargetTorque = ScrewDriver.TargetTorque;
|
|
|
|
|
- lockResult.TargetTurnsUpperLimit = ScrewDriver.TargetTurnsUpperLimit;
|
|
|
|
|
- lockResult.TargetTurnsLowerLimit = ScrewDriver.TargetTurnsLowerLimit;
|
|
|
|
|
- lockResult.TargetLockSpeed = ScrewDriver.TargetLockSpeed;
|
|
|
|
|
- lockResult.StartPositionX = currentPosition.X;
|
|
|
|
|
- lockResult.StartPositionY = currentPosition.Y;
|
|
|
|
|
- lockResult.StartPositionZ = screwPoint.Z_Position_Start;
|
|
|
|
|
- lockResult.EndPositionZ = currentPosition.Z;
|
|
|
|
|
- lockResult.LockDescentSpeed = screwPoint.Z_Velocity_Stop;
|
|
|
|
|
- lockResult.FeederNumber = screwPoint != null ? screwPoint.Feeder : 0;
|
|
|
|
|
- lockResult.NozzleNumber = "";
|
|
|
|
|
- lockResult.OperatorName = _systemDatabaseService.GetCurrentUser().UserName;
|
|
|
|
|
- lockResult.ProductImagePath = "";
|
|
|
|
|
- lockResult.WaveDatas = ScrewDriver.WaveDatas;
|
|
|
|
|
- App.Current.Dispatcher.Invoke(() =>
|
|
|
|
|
- {
|
|
|
|
|
- _eventAggregator.GetEvent<LockFinishNotification>().Publish(lockResult);
|
|
|
|
|
- });
|
|
|
|
|
- await _systemDatabaseService.RecordLockResultAsync(lockResult);
|
|
|
|
|
|
|
+ //var screwPoint = currentProduct.ScrewPoints.FirstOrDefault(p => p.Number == positionIndex);
|
|
|
|
|
+ ////获取当前的机器人点位
|
|
|
|
|
+ //var robot = _robotService.GetAllRobots().FirstOrDefault();
|
|
|
|
|
+ //var currentPosition = robot.GetRobotPos();
|
|
|
|
|
+ ////读取压力值
|
|
|
|
|
+ //float pressure = plc.ReadNode<float>(addressConfig.In_PressureValue.Address);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //await Task.Delay(60);
|
|
|
|
|
+ ////获取电批结果
|
|
|
|
|
+ //bool isSucced = ScrewDriver.GetData();
|
|
|
|
|
+ //LockResult lockResult = new LockResult();
|
|
|
|
|
+ //lockResult.ScrewdriverGetDataSucceed = isSucced;
|
|
|
|
|
+ //lockResult.Number = positionIndex;
|
|
|
|
|
+ //lockResult.LockPassed = ScrewDriver.Success;
|
|
|
|
|
+ //lockResult.ProductNumber = _productService.CurrentProductCode;
|
|
|
|
|
+ //lockResult.LockTurns = (float)ScrewDriver.Truns;
|
|
|
|
|
+ //lockResult.LockTorque = (float)ScrewDriver.TorqueValue;
|
|
|
|
|
+ //lockResult.LockDuration = (float)ScrewDriver.FinalTime;
|
|
|
|
|
+ //lockResult.ScrewdriverProgramNumber = ScrewDriver.ProgramNumber;
|
|
|
|
|
+ //lockResult.ResultDetails = ScrewDriver.ErrorInfo;
|
|
|
|
|
+ //lockResult.Pressure = pressure;
|
|
|
|
|
+ //lockResult.TargetTorque = ScrewDriver.TargetTorque;
|
|
|
|
|
+ //lockResult.TargetTurnsUpperLimit = ScrewDriver.TargetTurnsUpperLimit;
|
|
|
|
|
+ //lockResult.TargetTurnsLowerLimit = ScrewDriver.TargetTurnsLowerLimit;
|
|
|
|
|
+ //lockResult.TargetLockSpeed = ScrewDriver.TargetLockSpeed;
|
|
|
|
|
+ //lockResult.StartPositionX = currentPosition.X;
|
|
|
|
|
+ //lockResult.StartPositionY = currentPosition.Y;
|
|
|
|
|
+ //lockResult.StartPositionZ = screwPoint.Z_Position_Start;
|
|
|
|
|
+ //lockResult.EndPositionZ = currentPosition.Z;
|
|
|
|
|
+ //lockResult.LockDescentSpeed = screwPoint.Z_Velocity_Stop;
|
|
|
|
|
+ //lockResult.FeederNumber = screwPoint != null ? screwPoint.Feeder : 0;
|
|
|
|
|
+ //lockResult.NozzleNumber = "";
|
|
|
|
|
+ //lockResult.OperatorName = _systemDatabaseService.GetCurrentUser().UserName;
|
|
|
|
|
+ //lockResult.ProductImagePath = "";
|
|
|
|
|
+ //lockResult.WaveDatas = ScrewDriver.WaveDatas;
|
|
|
|
|
+ //App.Current.Dispatcher.Invoke(() =>
|
|
|
|
|
+ //{
|
|
|
|
|
+ // _eventAggregator.GetEvent<LockFinishNotification>().Publish(lockResult);
|
|
|
|
|
+ //});
|
|
|
|
|
+ //await _systemDatabaseService.RecordLockResultAsync(lockResult);
|
|
|
await plc.WriteNodeAsync(addressConfig.In_WorkDone.Address, (Int16)0);
|
|
await plc.WriteNodeAsync(addressConfig.In_WorkDone.Address, (Int16)0);
|
|
|
|
|
+ var code = plc.ReadNode<string>(string.Format(addressConfig.In_Code.Address, positionIndex));
|
|
|
|
|
+ // 停止采集压力并保存
|
|
|
|
|
+ await StopAndSavePressureCollectionAsync(currentProduct.Name, code, positionIndex);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -1947,7 +2001,7 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
{
|
|
|
//这里缺少从MES获取产品配方的内容,需要补充
|
|
//这里缺少从MES获取产品配方的内容,需要补充
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ _LastMesCheckTime[i] = DateTime.UtcNow;
|
|
|
|
|
|
|
|
(bool isSuccess, string response) = await _mesService.StationGetAsync(code, 2);
|
|
(bool isSuccess, string response) = await _mesService.StationGetAsync(code, 2);
|
|
|
if (i == 0)
|
|
if (i == 0)
|
|
@@ -1979,8 +2033,12 @@ namespace TeamAAS_VP.Core
|
|
|
SendTaskMessage($"收到{i}上传本站数据请求...", MessageLevel.Debug);
|
|
SendTaskMessage($"收到{i}上传本站数据请求...", MessageLevel.Debug);
|
|
|
|
|
|
|
|
//这里缺少上传MES的本站数据结果及开始和结束时间,需要补充
|
|
//这里缺少上传MES的本站数据结果及开始和结束时间,需要补充
|
|
|
|
|
+ if (i == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ CTtime = DateTime.UtcNow.Subtract(_LastMesCheckTime[i]).TotalSeconds;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- (bool isSuccess, string response) = await _mesService.SubmitGetAsync(code, true, DateTime.Now, DateTime.Now);
|
|
|
|
|
|
|
+ (bool isSuccess, string response) = await _mesService.SubmitGetAsync(code, true, _LastMesCheckTime[i], DateTime.Now);
|
|
|
//假设上传成功,这里缺少上传失败的处理
|
|
//假设上传成功,这里缺少上传失败的处理
|
|
|
|
|
|
|
|
await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)3);
|
|
await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)3);
|
|
@@ -2014,6 +2072,176 @@ namespace TeamAAS_VP.Core
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ #region Pressure collection helpers
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 开始采集压力值
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="productName">配方名称</param>
|
|
|
|
|
+ /// <param name="productCode">产品编号</param>
|
|
|
|
|
+ /// <param name="Index">编号</param>
|
|
|
|
|
+ private void StartPressureCollection(string productName, string productCode, int Index)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ // cancel existing if any
|
|
|
|
|
+ _pressureCts[Index]?.Cancel();
|
|
|
|
|
+ _pressureTimeoutCts[Index]?.Cancel();
|
|
|
|
|
+ _pressureLinkedCts[Index]?.Dispose();
|
|
|
|
|
+ _pressureSamples[Index].Clear();
|
|
|
|
|
+
|
|
|
|
|
+ _pressureCts[Index] = new CancellationTokenSource();
|
|
|
|
|
+ _pressureTimeoutCts[Index] = new CancellationTokenSource();
|
|
|
|
|
+
|
|
|
|
|
+ // timeout after configured seconds
|
|
|
|
|
+ _pressureTimeoutCts[Index].CancelAfter(TimeSpan.FromSeconds(_pressureMaxDurationSeconds));
|
|
|
|
|
+
|
|
|
|
|
+ // link tokens so either stop or timeout cancels
|
|
|
|
|
+ _pressureLinkedCts[Index] = CancellationTokenSource.CreateLinkedTokenSource(_pressureCts[Index].Token, _pressureTimeoutCts[Index].Token);
|
|
|
|
|
+
|
|
|
|
|
+ var token = _pressureLinkedCts[Index].Token;
|
|
|
|
|
+ var addressConfig = _configService.GetPlcAddresses();
|
|
|
|
|
+ var plc = _plcService.GetPlcByNumber(addressConfig.PlcNo) as OpcUaClientPLC;
|
|
|
|
|
+ if (plc == null || !plc.IsConnected) return;
|
|
|
|
|
+ Task.Run(async () =>
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage($"Pressure collection started for position {Index}", MessageLevel.Debug);
|
|
|
|
|
+ while (!token.IsCancellationRequested)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ float pressure = plc.ReadNode<float>(string.Format(addressConfig.In_PressureValue.Address, Index));
|
|
|
|
|
+ lock (_pressureSamples[Index])
|
|
|
|
|
+ {
|
|
|
|
|
+ _pressureSamples[Index].Add((DateTime.Now, pressure));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogError("采集压力值时出错", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ await Task.Delay(_pressureSampleIntervalMs);
|
|
|
|
|
+ }
|
|
|
|
|
+ // if cancelled due to timeout
|
|
|
|
|
+ if (_pressureTimeoutCts[Index].IsCancellationRequested && !_pressureCts[Index].IsCancellationRequested)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage("Pressure collection timed out, saving collected data.", MessageLevel.Alarm);
|
|
|
|
|
+ await StopAndSavePressureCollectionAsync(productName, productCode, Index);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, token);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogError("StartPressureCollection error", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 停止采集并保存压力数据
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="productName"></param>
|
|
|
|
|
+ /// <param name="productCode"></param>
|
|
|
|
|
+ /// <param name="positionIndex"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ private async Task StopAndSavePressureCollectionAsync(string productName, string productCode, int Index)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ // cancel sampling
|
|
|
|
|
+ _pressureCts[Index]?.Cancel();
|
|
|
|
|
+ // allow worker to observe cancel
|
|
|
|
|
+ await Task.Delay(50);
|
|
|
|
|
+
|
|
|
|
|
+ List<(DateTime Timestamp, float Value)> snapshot;
|
|
|
|
|
+ lock (_pressureSamples[Index])
|
|
|
|
|
+ {
|
|
|
|
|
+ snapshot = new List<(DateTime, float)>(_pressureSamples[Index]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (snapshot.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage("No pressure samples collected.", MessageLevel.Info);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // save to file under configured path
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ //获取系统参数
|
|
|
|
|
+ var systemConfig = _configService.GetSystemConfiguration();
|
|
|
|
|
+ if (systemConfig.PressureSensorConfig == null || systemConfig.PressureSensorConfig.Count <= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage("当前没有配置任何压力传感器!", MessageLevel.Alarm);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ //获取当前压力传感器配置
|
|
|
|
|
+ var pressureSensorConfig = systemConfig.PressureSensorConfig.FirstOrDefault(p => p.SensorId == Index);
|
|
|
|
|
+ if (pressureSensorConfig == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ SendTaskMessage($"当前压力传感器配置不存在!- {Index}", MessageLevel.Alarm);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ //PressureFinishNotification : Prism.Events.PubSubEvent<(bool IsSuccess, int Index, (DateTime Timestamp, float Value)[] values,string SavePath )>
|
|
|
|
|
+ string basePath = pressureSensorConfig?.PressureCurvePath ?? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
|
|
+ string datePath = DateTime.Now.ToString("yyyy-MM") + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
|
|
|
|
|
+ string dirPath = Path.Combine(basePath, datePath, productName ?? "UnknownProduct", productCode ?? DateTime.Now.ToString("yyyyMMddHHmmssfff"));
|
|
|
|
|
+ if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);
|
|
|
|
|
+ string csvfileName = $"pressure-{productCode}-{Index}-{DateTime.Now.ToString("HHmmss")}.csv";
|
|
|
|
|
+ string csvPath = Path.Combine(dirPath, csvfileName);
|
|
|
|
|
+ string pngfileName = $"pressure-{productCode}-{Index}-{DateTime.Now.ToString("HHmmss")}.png";
|
|
|
|
|
+ string pngPath = Path.Combine(dirPath, pngfileName);
|
|
|
|
|
+ if (!pressureSensorConfig.IsSavePressureCurve)
|
|
|
|
|
+ {
|
|
|
|
|
+ csvPath = string.Empty;
|
|
|
|
|
+ pngPath = string.Empty;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ App.Current.Dispatcher.Invoke(() =>
|
|
|
|
|
+ {
|
|
|
|
|
+ _eventAggregator.GetEvent<PressureFinishNotification>().Publish((true, Index, snapshot.ToArray(), pngPath));
|
|
|
|
|
+ });
|
|
|
|
|
+ //判断是否保存锁付曲线
|
|
|
|
|
+ if (pressureSensorConfig.IsSavePressureCurve)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!string.IsNullOrEmpty(csvPath))
|
|
|
|
|
+ {
|
|
|
|
|
+ var sb = new StringBuilder();
|
|
|
|
|
+ sb.AppendLine("Timestamp,Value");
|
|
|
|
|
+ foreach (var s in snapshot)
|
|
|
|
|
+ {
|
|
|
|
|
+ sb.AppendLine($"{s.Timestamp:O},{s.Value}");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ File.WriteAllText(csvPath, sb.ToString());
|
|
|
|
|
+ SendTaskMessage($"Pressure samples saved to {csvPath}", MessageLevel.Debug);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogError("保存压力采样文件时出错", ex);
|
|
|
|
|
+ SendTaskMessage("保存压力采样文件时出错: " + ex.Message, MessageLevel.Error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogHelper.WriteLogError("StopAndSavePressureCollectionAsync error", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ finally
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ _pressureLinkedCts[Index]?.Cancel();
|
|
|
|
|
+ _pressureLinkedCts[Index]?.Dispose();
|
|
|
|
|
+ _pressureTimeoutCts[Index]?.Dispose();
|
|
|
|
|
+ _pressureCts[Index]?.Dispose();
|
|
|
|
|
+ _pressureSamples[Index].Clear();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch { }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
private async void DoYieldTime(object state)
|
|
private async void DoYieldTime(object state)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|