From abff6261e5e74ff16a844f4739f84d49b6133000 Mon Sep 17 00:00:00 2001 From: xxyy <cathay_xy@163.com> Date: 星期六, 15 二月 2025 13:01:02 +0800 Subject: [PATCH] 新增分容空框出库功能及代码结构优化 --- Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs | 78 ++++++++++++++++++++++++++++++++++---- 1 files changed, 69 insertions(+), 9 deletions(-) diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs index 7aa2adf..e40fb0c 100644 --- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs +++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs @@ -1,4 +1,5 @@ 锘�#region << 鐗� 鏈� 娉� 閲� >> + /*---------------------------------------------------------------- * 鍛藉悕绌洪棿锛歐IDESEAWCS_QuartzJob * 鍒涘缓鑰咃細鑳$搴� @@ -11,8 +12,9 @@ * 淇敼鏃堕棿锛� * 鐗堟湰锛歏1.0.1 * 淇敼璇存槑锛� - * + * *----------------------------------------------------------------*/ + #endregion << 鐗� 鏈� 娉� 閲� >> using HslCommunication; @@ -34,6 +36,7 @@ public class CommonConveyorLine : IConveyorLine { #region Private Member + /// <summary> /// 鍫嗗灈鏈洪�氳瀵硅薄 /// </summary> @@ -62,9 +65,11 @@ private bool _heartStatr = true; private bool _isConnected = true; + #endregion #region Public Member + /// <summary> /// 杈撻�佺嚎閫氳瀵硅薄 /// </summary> @@ -104,9 +109,11 @@ /// 璁惧鐘舵�� /// </summary> public DeviceStatus Status => DeviceStatus.Offline; + #endregion #region Constructor Function + /// <summary> /// 鏋勯�犲嚱鏁� /// </summary> @@ -124,9 +131,11 @@ _deviceName = deviceName; CheckConnect(); } + #endregion #region Private Method + private void CheckConnect() { Task.Run(() => @@ -150,9 +159,11 @@ } }); } + #endregion #region Public Method + /// <summary> /// 璇诲彇PLC鍗忚鍦板潃鐨勬暟鎹� /// </summary> @@ -163,7 +174,7 @@ /// <returns>璇诲彇鍒扮殑鏁版嵁</returns> public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum { - if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�"); + if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁溿�� {DeviceName} 銆�"); DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode); return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); } @@ -177,7 +188,7 @@ } /// <summary> - /// + /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="command"></param> @@ -186,7 +197,7 @@ /// <exception cref="Exception"></exception> public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new() { - if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�"); + if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁溿�恵DeviceName}銆�"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (devicePro == null) { @@ -208,12 +219,35 @@ /// <exception cref="Exception"></exception> public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new() { - if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�"); + if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁溿�恵DeviceName}銆�"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "ReadDeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (devicePro == null) { - throw new Exception("鏈壘鍒板崗璁俊鎭�"); + throw new Exception("鏈壘鍒板崗璁俊鎭�:" + deviceChildCode); + } + else + { + return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); + } + } + + /// <summary> + /// 璇诲彇PLC鏁版嵁锛岃繑鍥炶嚜瀹氫箟瀵硅薄 + /// </summary> + /// <typeparam name="T">娉涘瀷</typeparam> + /// <param name="deviceChildCode">瀛愯澶囩紪鍙�</param> + /// <param name="deviceProParamType">鍙傛暟绫诲瀷</param> + /// <returns>杩斿洖鑷畾涔夊璞℃垨鎶涘嚭寮傚父</returns> + /// <exception cref="Exception"></exception> + public T ReadCustomer<T>(string deviceChildCode, string deviceProParamType) where T : IDataTransfer, new() + { + if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁溿�恵DeviceName}銆�"); + DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); + + if (devicePro == null) + { + throw new Exception("鏈壘鍒板崗璁俊鎭�:" + deviceChildCode); } else { @@ -234,13 +268,13 @@ where TEnum : Enum where TValue : notnull { - if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁�"); + if (!IsConnected) throw new Exception($"閫氳杩炴帴閿欒锛岃妫�鏌ョ綉缁溿�� {DeviceName} 銆�"); DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); } /// <summary> - /// + /// 妫�娴嬬珯鍙版槸鍚︽湁璐� /// </summary> /// <param name="deviceChildCode"></param> /// <returns></returns> @@ -272,12 +306,38 @@ return false; } + /// <summary> + /// 妫�娴嬬珯鍙版槸鍚︽湁璐� + /// </summary> + /// <param name="deviceChildCode"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + public bool IsOccupiedx(string deviceChildCode) + { + if (Communicator.IsConnected) + { + var device = _deviceProDTOs.Where(x => x.DeviceChildCode == deviceChildCode && x.DeviceProParamName == "InteractiveSignal").FirstOrDefault(); + + object readStatus = Communicator.ReadAsObj(device.DeviceProAddress, device.DeviceDataType); + + //todo 鍗忚鏄庣粏淇℃伅鏈幏鍙栧埌鏃舵姏鍑哄紓甯� + if (readStatus.ToString() != "2") + { + return true; + } + return false; + } + //todo 閫氳鏈繛鎺ユ椂鎶涘嚭寮傚父 + return false; + } + public void Dispose() { _heartStatr = false; _communicator.Dispose(); GC.SuppressFinalize(this); } + #endregion } -} +} \ No newline at end of file -- Gitblit v1.9.3