#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using AutoMapper;
|
using HslCommunication;
|
using Quartz;
|
using System;
|
using System.Linq;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using WIDESEA_Common.Log;
|
using WIDESEAWCS_DTO.BasicInfo;
|
using WIDESEAWCS_IBasicInfoService;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_Model.Models.System;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_Tasks.ConveyorLineJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
/// <summary>
|
/// 通用输送线任务,负责处理输送线设备的通信与任务执行
|
/// </summary>
|
/// <remarks>
|
/// 1. 通过PLC通信读取设备状态和条码信息 <br/>
|
/// 2. 根据条码查询产品信息和去向工位 <br/>
|
/// 3. 将产品尺寸和去向信息写入PLC <br/>
|
/// 4. 处理异常情况并记录错误日志
|
/// </remarks>
|
/// <attribute>[DisallowConcurrentExecution]</attribute>
|
[DisallowConcurrentExecution]
|
public class CommonConveyorLineJob : JobBase, IJob
|
{
|
private readonly ITaskService _taskService;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly IRouterService _routerService;
|
private readonly IOrderDetailsService _OrderDetailsService;
|
private readonly IMapper _mapper;
|
|
public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IOrderDetailsService orderDetails, IMapper mapper)
|
{
|
_taskService = taskService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_routerService = routerService;
|
_OrderDetailsService = orderDetails;
|
_mapper = mapper;
|
}
|
|
static string barcode = string.Empty; //条码
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
|
if (flag && value != null && value is OtherDevice otherDevice)
|
{
|
bool request = otherDevice.Communicator.Read<bool>("DB15.22.0"); //申请
|
bool response = otherDevice.Communicator.Read<bool>("DB15.22.1"); //应答
|
|
bool wcsResponse = otherDevice.Communicator.Read<bool>("DB15.0.0"); //应答
|
|
if (request && !response && !wcsResponse)
|
{
|
bool[] useables = otherDevice.Communicator.Read<bool>("DB15.22.3", 3);
|
|
int[] useableArray = GetIndexArray(useables, false);
|
|
List<int> useableStations = useableArray.ToList();
|
for (int i = 0; i < useableStations.Count; i++)
|
{
|
useableStations[i] += 1;
|
}
|
|
barcode = otherDevice.Communicator.Read<string>("DB15.32"); //条码
|
|
List<byte> bytes = otherDevice.Communicator.Read("DB15.34", 40).ToList();
|
|
byte[] temp = bytes.ToArray().SelectMiddle(0, bytes.IndexOf(0));
|
|
barcode = Encoding.Default.GetString(temp);
|
|
string pattern = @"\d+"; // 匹配数字
|
Match match = Regex.Match(barcode, pattern);
|
string barcodeNumber = match.Value;
|
|
if (!string.IsNullOrEmpty(barcodeNumber))
|
{
|
// 1. 获取去向
|
int toplc = _OrderDetailsService.GetOrderDetails(barcodeNumber, useableStations, out ProductInfoDTO productInfo);
|
|
if (toplc > 0)//获取到有效去向
|
{
|
if (toplc == 1 && productInfo.Length < productInfo.Width)
|
{
|
otherDevice.Communicator.Write("DB15.10", productInfo.Width);
|
otherDevice.Communicator.Write("DB15.14", productInfo.Length);
|
otherDevice.Communicator.Write("DB15.18", productInfo.Height);
|
}
|
else
|
{
|
otherDevice.Communicator.Write("DB15.10", productInfo.Length);
|
otherDevice.Communicator.Write("DB15.14", productInfo.Width);
|
otherDevice.Communicator.Write("DB15.18", productInfo.Height);
|
}
|
|
|
otherDevice.Communicator.Write("DB15.6", toplc); //写入去向
|
otherDevice.Communicator.Write("DB15.0", true);
|
|
//var datast = _OrderDetailsService.ToMesBarc(int.Parse(barcode));
|
}
|
else if (toplc == -1)//板材无条码
|
{
|
otherDevice.Communicator.Write("DB15.0.3", true);
|
}
|
else if (toplc == -2) //板材大小不在区间
|
{
|
otherDevice.Communicator.Write("DB15.0.2", true);
|
}
|
}
|
}
|
else
|
{
|
if (wcsResponse && !request)
|
otherDevice.Communicator.Write("DB15.0", false); //清除响应
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteError(nameof(CommonConveyorLineJob), ex.ToString(), ex);
|
}
|
return Task.CompletedTask;
|
}
|
|
public int[] GetIndexArray<T>(T[] values, T value)
|
{
|
List<int> result = new List<int>();
|
for (int i = 0; i < values.Length; i++)
|
{
|
if (value?.Equals(values[i]) ?? false)
|
{
|
result.Add(i);
|
}
|
}
|
return result.ToArray();
|
}
|
}
|
}
|