using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using Quartz;
|
using SixLabors.ImageSharp;
|
using SqlSugar.Extensions;
|
using System;
|
using System.Collections.Generic;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Communicator;
|
using WIDESEAWCS_IBasicInfoRepository;
|
using WIDESEAWCS_IBasicInfoService;
|
using WIDESEAWCS_ISystemServices;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_Tasks.TaskAcquisition;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
/// <summary>
|
/// 任务获取 后底板1 的任务
|
/// </summary>
|
///
|
[DisallowConcurrentExecution]
|
public class TaskAcquisition_Back1_Job : JobBase, IJob
|
{
|
private readonly ITaskRepository _taskRepository;
|
private readonly ITaskService _taskService;
|
private readonly ISys_ConfigService _sys_ConfigService;
|
private readonly IDt_StationManagerRepository _stationManagerRepository;
|
private readonly IDt_MaterialInfoRepository _IDt_MaterialInfoRepository;
|
public TaskAcquisition_Back1_Job(ITaskRepository taskRepository, ITaskService taskService, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository, IDt_MaterialInfoRepository IDt_MaterialInfoRepository)
|
{
|
_taskRepository = taskRepository;
|
_taskService = taskService;
|
_sys_ConfigService = configService;
|
_stationManagerRepository = stationManagerRepository;
|
_IDt_MaterialInfoRepository = IDt_MaterialInfoRepository;
|
}
|
public Task Execute(IJobExecutionContext context)
|
{
|
string ip = "127.0.0.1";
|
int port = 502;
|
string Region = "后底板1";
|
ModbusTcp modbusTcp = new ModbusTcp(ip, port, Region);
|
Baseconversion baseconversion = new Baseconversion();
|
modbusTcp.Connect();
|
|
Dictionary<int, int> Signal = new Dictionary<int, int>() { [10] = 2, [30] = 3, [50] = 4, [70] = 5 };
|
Dictionary<int, int> FeedingPoint = new Dictionary<int, int>() { [10] = 2001, [30] = 2002, [50] = 2003, [70] = 2004 }; // 叫料的点位 终点位置
|
|
try
|
{
|
for (int i = 10; i < 90; i += 20)
|
{
|
byte[] SignalNumber = modbusTcp.Read(Signal[i].ToString(), 1); // 信号 1:叫料 2:拉出空框
|
|
if (SignalNumber[1] == 1)
|
{
|
byte[] PartNumber = modbusTcp.Read(i.ToString(), 20); // 读取零件号
|
|
if (PartNumber[1] == 0) continue;
|
|
string Ku1_Value = baseconversion.TenthTurn16(PartNumber);
|
if (Ku1_Value != "" && Ku1_Value != null)
|
{
|
// 等功能测试完,这里要做日志记录
|
|
Console.WriteLine(Ku1_Value);
|
// 找对应的零件号是否已经绑定(组盘)
|
Dt_MaterialInfo dt_MaterialInfo = _IDt_MaterialInfoRepository.QueryFirst(x => x.MaterialName == Ku1_Value);
|
|
if (dt_MaterialInfo != null && dt_MaterialInfo.IsBind && dt_MaterialInfo.EndPosition == null)
|
{
|
Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.PalletCode == dt_MaterialInfo.ContainerCode);
|
if (dt_Task != null) continue; //证明有当前任务
|
|
dt_Task = new Dt_Task();
|
dt_Task.PalletCode = dt_MaterialInfo.ContainerCode;
|
dt_Task.SourceAddress = dt_MaterialInfo.Position; // 当前位置
|
dt_Task.TargetAddress = FeedingPoint[i].ToString(); // 终点位置
|
dt_Task.Grade = 2;
|
dt_Task.TaskState = TaskAGVCarryStatusEnum.AGV_CarryNew.ObjToInt();
|
dt_Task.TaskType = TaskAGVCarryTypeEnum.Carry.ObjToInt();
|
dt_Task.Roadway = (Signal[i] - 1).ToString(); // 库1 叫料那就是1巷道
|
dt_Task.CurrentAddress = dt_MaterialInfo.Position; // 当前位置
|
dt_Task.NextAddress = FeedingPoint[i].ToString(); // 终点位置
|
|
dt_MaterialInfo.EndPosition = FeedingPoint[i].ToString(); // 终点位置
|
|
_taskRepository.AddData(dt_Task);
|
_IDt_MaterialInfoRepository.UpdateData(dt_MaterialInfo);
|
}
|
|
// 如果没绑定则不生成任务 如果查找到对应的零件号绑定了 则生成一条任务数据
|
}
|
}
|
|
if (SignalNumber[1] == 2) // 表示拉出空框
|
{
|
Dictionary<int, int> Endpointposition = new Dictionary<int, int>() { [10] = 3001, [20] = 3002, [30] = 3003, [40] = 3004 }; // 叫料的点位 终点位置
|
Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.SourceAddress == FeedingPoint[i].ToString() && x.TaskType == (int)TaskAGVCarryTypeEnum.CarryEmpty);
|
if (dt_Task != null) continue;
|
|
dt_Task = new Dt_Task();
|
dt_Task.PalletCode = "空框子";
|
dt_Task.SourceAddress = FeedingPoint[i].ToString();
|
dt_Task.TargetAddress = Endpointposition[i].ToString();
|
dt_Task.Grade = 2;
|
dt_Task.TaskState = TaskAGVCarryStatusEnum.AGV_CarryNew.ObjToInt();
|
dt_Task.TaskType = TaskAGVCarryTypeEnum.CarryEmpty.ObjToInt();
|
dt_Task.Roadway = (Signal[i] - 1).ToString(); // 库1 叫料那就是1巷道
|
dt_Task.CurrentAddress = FeedingPoint[i].ToString(); // 当前位置
|
dt_Task.NextAddress = Endpointposition[i].ToString(); // 终点位置
|
_taskRepository.AddData(dt_Task);
|
}
|
|
}
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
|
|
// 16进制转成10进制
|
// 2. 16进制 → 转回十进制(你要的功能)
|
ulong decimalResult = Convert.ToUInt64("123", 16);
|
Console.WriteLine("16进制转回十进制:" + decimalResult);
|
|
// 写入
|
bool flag = modbusTcp.Write("30", decimalResult.ToString());
|
|
modbusTcp.Disconnect();
|
Console.WriteLine("进入了TaskAcquisition_Back1_Job");
|
return Task.CompletedTask;
|
}
|
}
|
}
|