From 96adc295cb04fd135d63d3a907f2732274f90965 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 21 四月 2026 01:11:21 +0800
Subject: [PATCH] feat: 添加MES异步上传辅助服务并重构相关代码
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs | 38 ++++++++++++++++++++++++++------------
1 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
index 76aff9c..06829af 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
@@ -20,12 +20,14 @@
using HslCommunication;
using System.ComponentModel;
using System.Reflection;
+using System.Threading;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.StackerCrane;
using WIDESEAWCS_QuartzJob.StackerCrane.Common;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
+using WIDESEAWCS_Core.LogHelper;
namespace WIDESEAWCS_QuartzJob
{
@@ -67,7 +69,10 @@
/// </summary>
private int _lastTaskNum;
- private bool _isChecked = false;
+ /// <summary>
+ /// 鏍囪鏄惁姝e湪妫�鏌ヤ换鍔″畬鎴愮姸鎬侊紙volatile 淇濊瘉澶氱嚎绋嬪彲瑙佹�э級
+ /// </summary>
+ private volatile bool _isChecked = false;
private bool _heartStatr = true;
@@ -225,7 +230,7 @@
{
return DeviceStatus.Idle;
}
- else if (StackerCraneWorkStatusValue == StackerCraneWorkStatus.Putting || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PickUp || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PickUpCompleted || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PutCompleted)
+ else if (StackerCraneWorkStatusValue == StackerCraneWorkStatus.Putting || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PickUp || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PutMove || StackerCraneWorkStatusValue == StackerCraneWorkStatus.PutCompleted)
{
return DeviceStatus.Working;
}
@@ -236,7 +241,11 @@
private int GetCurrentTaskNum()
{
DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CurrentTaskNum));
- return devicePro == null ? throw new Exception($"璇诲彇褰撳墠浠诲姟鍙烽敊璇�,鏈幏鍙栧埌鍗忚淇℃伅,璇锋鏌ラ厤缃弬鏁板悕绉版槸鍚﹂厤缃�,涓旈厤缃负涓簕nameof(CurrentTaskNum)}") : (int)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
+ if (devicePro == null)
+ throw new Exception($"璇诲彇褰撳墠浠诲姟鍙烽敊璇�,鏈幏鍙栧埌鍗忚淇℃伅,璇锋鏌ラ厤缃弬鏁板悕绉版槸鍚﹂厤缃�,涓旈厤缃负{nameof(CurrentTaskNum)}");
+
+ object value = Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType);
+ return Convert.ToInt32(value); // 缁熶竴杞崲涓� int
}
/// <summary>
@@ -311,10 +320,10 @@
{
return deviceProtocolDetail.ProtocolDetailType;
}
- return StackerCraneStatus.Unkonw.ToString();
+ return StackerCraneStatus.Unknown.ToString();
}
}
- return StackerCraneStatus.Unkonw.ToString();
+ return StackerCraneStatus.Unknown.ToString();
}
private void CheckConnect()
@@ -355,7 +364,7 @@
if (Communicator is SiemensS7)
{
if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�");
- DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceProParamName == "InputTaskNum")/*.OrderBy(x=>x.DeviceProOffset)*/.FirstOrDefault();
if (devicePro == null)
{
return false;
@@ -395,30 +404,33 @@
{
OperateResult<TimeSpan> operateResult = new OperateResult<TimeSpan>();
TypeCode typeCode = SiemensDBDataType.GetTypeCode(devicePro.DeviceDataType);
+
+ // 瓒呮椂浠� 10*6000ms (60s) 闄嶄綆鍒� 10*1000ms (10s)锛岄槻姝㈡柇杩炴椂闀挎椂闂撮樆濉�
+ int timeout = 10 * 1000;
switch (typeCode)
{
case TypeCode.Boolean:
- operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue));
+ operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue));
break;
case TypeCode.Byte:
- operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue));
+ operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue));
break;
case TypeCode.Int16:
- operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue));
+ operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue));
break;
case TypeCode.Int32:
- operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue));
+ operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue));
break;
case TypeCode.UInt16:
- operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue));
+ operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue));
break;
case TypeCode.UInt32:
- operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue));
+ operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue));
break;
default:
@@ -436,6 +448,8 @@
}
catch (Exception ex)
{
+ // 璁板綍寮傚父锛岄伩鍏嶉敊璇闈欓粯鍚炴帀
+ QuartzLogger.Error($"CheckStackerCraneTaskCompleted: 璁惧 {_deviceCode} 妫�鏌ュ紓甯�", "CommonStackerCrane", ex);
}
finally
{
--
Gitblit v1.9.3