| | |
| | | using HslCommunication; |
| | | using System.ComponentModel; |
| | | using System.Reflection; |
| | | using System.Threading; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Common; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | |
| | | /// </summary> |
| | | private int _lastTaskNum; |
| | | |
| | | private bool _isChecked = false; |
| | | /// <summary> |
| | | /// 标记是否正在检查任务完成状态(volatile 保证多线程可见性) |
| | | /// </summary> |
| | | private volatile bool _isChecked = false; |
| | | |
| | | private bool _heartStatr = true; |
| | | |
| | |
| | | if (Communicator is SiemensS7) |
| | | { |
| | | if (!IsConnected) throw new Exception($"通讯连接错误,请检查网络"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceProParamName == "InputTaskNum")/*.OrderBy(x=>x.DeviceProOffset)*/.FirstOrDefault(); |
| | | if (devicePro == null) |
| | | { |
| | | return false; |
| | |
| | | { |
| | | OperateResult<TimeSpan> operateResult = new OperateResult<TimeSpan>(); |
| | | TypeCode typeCode = SiemensDBDataType.GetTypeCode(devicePro.DeviceDataType); |
| | | |
| | | // 超时从 10*6000ms (60s) 降低到 10*1000ms (10s),防止断连时长时间阻塞 |
| | | int timeout = 10 * 1000; |
| | | switch (typeCode) |
| | | { |
| | | case TypeCode.Boolean: |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue)); |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToBoolean(deviceProtocolDetail.ProtocalDetailValue)); |
| | | break; |
| | | |
| | | case TypeCode.Byte: |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue)); |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToByte(deviceProtocolDetail.ProtocalDetailValue)); |
| | | break; |
| | | |
| | | case TypeCode.Int16: |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue)); |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToInt16(deviceProtocolDetail.ProtocalDetailValue)); |
| | | break; |
| | | |
| | | case TypeCode.Int32: |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue)); |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToInt32(deviceProtocolDetail.ProtocalDetailValue)); |
| | | break; |
| | | |
| | | case TypeCode.UInt16: |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue)); |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToUInt16(deviceProtocolDetail.ProtocalDetailValue)); |
| | | break; |
| | | |
| | | case TypeCode.UInt32: |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, 10 * 6000, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue)); |
| | | operateResult = Communicator.Wait(devicePro.DeviceProAddress, 500, timeout, Convert.ToUInt32(deviceProtocolDetail.ProtocalDetailValue)); |
| | | break; |
| | | |
| | | default: |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录异常,避免错误被静默吞掉 |
| | | QuartzLogger.Error($"CheckStackerCraneTaskCompleted: 设备 {_deviceCode} 检查异常", "CommonStackerCrane", ex); |
| | | } |
| | | finally |
| | | { |