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 | 54 +++++++++++++++++++++++++++++++++++-------------------
1 files changed, 35 insertions(+), 19 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 5e746e7..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,11 +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
{
@@ -32,7 +35,7 @@
/// 涓�鑸爢鍨涙満瀹炵幇绫伙紝瀹炵幇鍫嗗灈鏈烘帴鍙e眰
/// </summary>
[Description("鍫嗗灈鏈�")]
- public class CommonStackerCrane : IStackerCrane
+ public class CommonStackerCrane : StackerCraneBase, IStackerCrane
{
#region Private Member
@@ -66,7 +69,10 @@
/// </summary>
private int _lastTaskNum;
- private bool _isChecked = false;
+ /// <summary>
+ /// 鏍囪鏄惁姝e湪妫�鏌ヤ换鍔″畬鎴愮姸鎬侊紙volatile 淇濊瘉澶氱嚎绋嬪彲瑙佹�э級
+ /// </summary>
+ private volatile bool _isChecked = false;
private bool _heartStatr = true;
@@ -157,6 +163,11 @@
public bool IsConnected => Communicator.IsConnected && _isConnected;
/// <summary>
+ /// 鍫嗗灈鏈哄畬鎴愪簨浠舵槸鍚﹀凡璁㈤槄
+ /// </summary>
+ public bool IsEventSubscribed => StackerCraneTaskCompletedEventHandler != null;
+
+ /// <summary>
/// 鍫嗗灈鏈轰换鍔″畬鎴愪簨浠�
/// </summary>
public event EventHandler<StackerCraneTaskCompletedEventArgs> StackerCraneTaskCompletedEventHandler;
@@ -166,10 +177,6 @@
/// </summary>
public object StackerCraneTaskCommand { get; set; }
- /// <summary>
- /// 鍫嗗灈鏈哄畬鎴愪簨浠舵槸鍚﹀凡璁㈤槄
- /// </summary>
- public bool IsEventSubscribed => StackerCraneTaskCompletedEventHandler != null;
/// <summary>
/// 涓婁竴娆′换鍔$殑绫诲瀷
@@ -223,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;
}
@@ -234,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>
@@ -309,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()
@@ -353,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;
@@ -385,38 +396,41 @@
_isChecked = true;
try
{
- DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(StackerCraneWorkStatus));
+ DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(StackerCraneCompleted));
if (devicePro != null)
{
- DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePro.DeviceProParamName && x.ProtocolDetailType == StackerCraneWorkStatus.WorkCompleted.ToString());
+ DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePro.DeviceProParamName && x.ProtocolDetailType == StackerCraneCompleted.Completed.ToString());
if (deviceProtocolDetail != null)
{
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:
@@ -434,6 +448,8 @@
}
catch (Exception ex)
{
+ // 璁板綍寮傚父锛岄伩鍏嶉敊璇闈欓粯鍚炴帀
+ QuartzLogger.Error($"CheckStackerCraneTaskCompleted: 璁惧 {_deviceCode} 妫�鏌ュ紓甯�", "CommonStackerCrane", ex);
}
finally
{
--
Gitblit v1.9.3