| | |
| | | |
| | | 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 |
| | |
| | | private int GetCurrentTaskNum() |
| | | { |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(CurrentTaskNum)); |
| | | return devicePro == null ? throw new Exception() : (int)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | return devicePro == null ? throw new Exception($"读取当前任务号错误,未获取到协议信息,请检查配置参数名称是否配置,且配置为为{nameof(CurrentTaskNum)}") : (int)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | for (int i = 0; i < devicePros.Count; i++) |
| | | { |
| | | object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType); |
| | | //todo 协议明细信息未获取到时抛出异常 |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception(); |
| | | deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamType && x.ProtocalDetailValue.Equals(readStatus.ToString())); |
| | | if (deviceProtocolDetail != null) |
| | |
| | | } |
| | | //todo 通讯未连接时抛出异常 |
| | | return StackerCraneStatus.Unkonw.ToString(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 比较两个值是否相等。 |
| | | /// </summary> |
| | | /// <param name="value">第一个值。</param> |
| | | /// <param name="paramValue">第二个值。</param> |
| | | /// <returns>返回比较结果。</returns> |
| | | private bool Compare(object value, object paramValue) |
| | | { |
| | | return value.Equals(paramValue); |
| | | } |
| | | |
| | | private void CheckConnect() |
| | |
| | | /// <returns></returns> |
| | | public bool SendCommand<T>(T command) where T : IDataTransfer, new() |
| | | { |
| | | if(Communicator is SiemensS7) |
| | | if (Communicator is SiemensS7) |
| | | { |
| | | if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | |
| | | /// 根据参数名称读取堆垛机对应的数据。 |
| | | /// </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 |