肖洋
2024-12-09 09d94bf90a606010b1cdaa6da2f788329b2f6a43
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine.cs
@@ -1,4 +1,5 @@
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_QuartzJob
 * 创建者:胡童庆
@@ -11,8 +12,9 @@
 * 修改时间:
 * 版本:V1.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>
@@ -177,7 +188,7 @@
        }
        /// <summary>
        ///
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command"></param>
@@ -213,7 +224,30 @@
            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
            {
@@ -240,7 +274,7 @@
        }
        /// <summary>
        ///
        ///
        /// </summary>
        /// <param name="deviceChildCode"></param>
        /// <returns></returns>
@@ -278,6 +312,7 @@
            _communicator.Dispose();
            GC.SuppressFinalize(this);
        }
        #endregion
    }
}
}