| | |
| | | |
| | | using HslCommunication; |
| | | using Microsoft.AspNetCore.Http; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | |
| | | public bool IsEventSubscribed => StackerCraneTaskCompletedEventHandler != null; |
| | | |
| | | public int? LastTaskType { get; set; } = null; |
| | | |
| | | #endregion |
| | | |
| | | #region Constructor Function |
| | |
| | | /// 根据参数名称读取堆垛机对应的数据。 |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">参数名称枚举类型。</typeparam> |
| | | /// <typeparam name="TRsult">读取结果的返回值类型。</typeparam> |
| | | /// <typeparam name="TResult">读取结果的返回值类型。</typeparam> |
| | | /// <param name="value">参数名称。</param> |
| | | /// <returns>返回读取到的数据。</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public TRsult GetValue<TEnum, TRsult>(TEnum value) where TEnum : Enum |
| | | public TResult GetValue<TEnum, TResult>(TEnum value) where TEnum : Enum |
| | | { |
| | | if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString()); |
| | | return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString()) ?? throw new Exception($"读取数据错误,未在协议信息里面找到参数{value.ToString()}"); |
| | | return (TResult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | where TValue : notnull |
| | | { |
| | | if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString()); |
| | | return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString()) ?? throw new Exception($"写入数据错误,未在协议信息里面找到参数{value.ToString()}"); |
| | | return Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); |
| | | } |
| | | |
| | | // 实现IDisposable接口的Dispose方法 |
| | | public void Dispose() |
| | | { |
| | | // 将_heartStatr设置为false |
| | | _heartStatr = false; |
| | | // 调用_communicator的Dispose方法 |
| | | _communicator.Dispose(); |
| | | // 告诉垃圾回收器不再调用此对象的终结器 |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | #endregion |