wanshenmean
2024-11-01 34bafb439a438c0f4e85ef7006dac590140d155c
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs
@@ -1,4 +1,5 @@
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_QuartzJob
 * 创建者:胡童庆
@@ -13,6 +14,7 @@
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#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>
@@ -222,6 +233,29 @@
        }
        /// <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($"通讯连接错误,请检查网络");
            DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
            if (devicePro == null)
            {
                throw new Exception("未找到协议信息");
            }
            else
            {
                return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress);
            }
        }
        /// <summary>
        /// 根据参数名称、设备子编号写入对应的数据。
        /// </summary>
        /// <typeparam name="TEnum">参数名称枚举类型。</typeparam>
@@ -278,6 +312,7 @@
            _communicator.Dispose();
            GC.SuppressFinalize(this);
        }
        #endregion
    }
}