using Newtonsoft.Json;
|
using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Common.Tools;
|
using WIDESEA_Entity.DomainModels.Equipment;
|
using WIDESEA_WCS.Jobs;
|
using WIDESEA_WCS.JobsPart.Public;
|
using WIDESEA_WCS.WCSClient;
|
|
namespace WIDESEA_WCS
|
{
|
/// <summary>
|
/// 分切机调度【三菱】
|
/// </summary>
|
[DisallowConcurrentExecution]
|
public class SlitterJob : JobBase, IJob
|
{
|
static List<AGVCenterEqDB> centerEqDBList;
|
|
public SlitterJob()
|
{
|
if (centerEqDBList == null || centerEqDBList.Count == 0)
|
{
|
string tsjJson = File.ReadAllText(AppContext.BaseDirectory + "/分切机.json", Encoding.UTF8);
|
centerEqDBList = JsonConvert.DeserializeObject<List<AGVCenterEqDB>>(tsjJson);
|
}
|
}
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
//ExecuteJob(context, DoAction);
|
}
|
catch { }
|
return Task.FromResult(string.Empty);
|
}
|
|
|
//private void DoAction(IJobExecutionContext context)
|
//{
|
// var clinet = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
|
|
// var stationList = centerEqDBList.FirstOrDefault(t => t.tiShenJiName == clinet.PLCName);
|
// if (stationList != null)
|
// {
|
// foreach (var station in stationList.stationInfos)
|
// {
|
// if (station.stationType == "in")
|
// {
|
// var hreat = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_hreat"]);
|
// var requestIn = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_requestIn"]);
|
// var allowIn = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_allowIn"]);
|
// var allowLeave = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_allowLeave"]);
|
|
// //转换为调度中心地址
|
// byte[] clientData = new byte[100];
|
// clientData[0] = (byte)(hreat ? 1 : 0);
|
// int step = 0;
|
// if (allowIn)
|
// {
|
// step = 1;
|
// }
|
// if (allowLeave)
|
// {
|
// step = 2;
|
// }
|
// clientData[90 + 1] = (byte)step;
|
|
// TransferData(station, clinet, clientData);
|
// Create(clinet, station, requestIn);
|
// }
|
// else if (station.stationType.StartsWith("out"))
|
// {
|
// var requestOut = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_requestOut"]);
|
// var allowIn = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_allowIn"]);
|
// var allowLeave = clinet.MelsecPLCClient.Read<bool>(station.dbData["R_allowLeave"]);
|
|
// //转换为调度中心地址
|
// byte[] clientData = new byte[100];
|
// int step = 0;
|
// if (allowIn)
|
// {
|
// step = 1;
|
// }
|
// if (allowLeave)
|
// {
|
// step = 2;
|
// }
|
// int data_93 = 0;
|
// if (station.stationType == "outB")
|
// {
|
// data_93 = 2;
|
// }
|
// clientData[93] = (byte)data_93;
|
// clientData[90 + 1] = (byte)step;
|
|
// TransferData(station, clinet, clientData);
|
// Create(clinet, station, requestOut);
|
// }
|
// }
|
// }
|
//}
|
|
private void Create(PLCClient clinet, StationInfo station, bool request)
|
{
|
try
|
{
|
//入口无料
|
if (station.stationType == "in" && request)
|
{
|
WCSCommon.CreateTask(station, true);
|
}
|
//出口有料
|
else if (station.stationType.StartsWith("out") && request)
|
{
|
WCSCommon.CreateTask(station, false);
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteLog.GetLog().Write($"【提升机任务请求异常】{clinet.PLCName},{station.stationCode}口。{ex.Message}" + "\n", clinet.PLCName);
|
}
|
}
|
|
|
/// <summary>
|
/// 中转AGV对接数据
|
/// </summary>
|
/// <param name="station"></param>
|
/// <param name="eq_Client"></param>
|
/// <param name="eq_Data"></param>
|
//private void TransferData(StationInfo station, PLCClient eq_Client, byte[] eq_Data)
|
//{
|
// var agv_Client = WIDESEA_WCS.WCSService.Clients.FirstOrDefault(t => t.PLCName == station.agvCenterName);
|
// if (agv_Client != null)
|
// {
|
// var agvData = (byte[])agv_Client.ReadDBValue(station.agvDBList[0], 100);
|
// int step = (int)agvData[90 + 1];
|
|
// //物料类型
|
// if (station.stationType == "in")
|
// {
|
// //心跳
|
// int hreat = (int)agvData[0];
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_hreat"], hreat);
|
// if (step == 0)
|
// {
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_requestIn"], false);
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_requestClose"], false);
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_haveLeave"], false);
|
// }
|
// else if (step == 1)
|
// {
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_requestIn"], true);
|
// }
|
// else if (step == 2)
|
// {
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_requestClose"], true);
|
// }
|
// else if (step == 3)
|
// {
|
// //离开后,辊分机。自复位
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_haveLeave"], true);
|
// }
|
// }
|
// else if (station.stationType.StartsWith("out"))
|
// {
|
// if (step == 0)
|
// {
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_requestIn"], false);
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_requestOpen"], false);
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_haveLeave"], false);
|
// }
|
// else if (step == 1)
|
// {
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_requestIn"], true);
|
// }
|
// else if (step == 2)
|
// {
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_requestOpen"], true);
|
// }
|
// else if (step == 3)
|
// {
|
// eq_Client.MelsecPLCClient.Write(station.dbData["W_haveLeave"], true);
|
// }
|
// }
|
// agv_Client.WriteDBValue(station.agvDBList[1], eq_Data);
|
// }
|
// else
|
// {
|
// WriteLog.GetLog(eq_Client.PLCName).Write($"【异常】{station.agvCenterName},读取调度中心PLC失败" + "\n", eq_Client.PLCName);
|
// }
|
//}
|
}
|
}
|