using Newtonsoft.Json;
|
using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
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 PrintJob : JobBase, IJob
|
{
|
|
static List<AGVCenterEqDB> centerEqDBList;
|
public PrintJob()
|
{
|
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.OmronPLCClient.Read<bool>(station.dbData["R_hreat"]);
|
// var waring = clinet.OmronPLCClient.Read<bool>(station.dbData["R_waring"]);
|
var step = clinet.OmronPLCClient.Read<ushort>(station.dbData["R_step"]);
|
//var requestType = clinet.OmronPLCClient.Read<ushort>(station.dbData["R_requestType"]);
|
//var isAB = clinet.OmronPLCClient.Read<bool>(station.dbData["R_isAB"]);
|
//var isToRihgt = clinet.OmronPLCClient.Read<bool>(station.dbData["R_isToRihgt"]);
|
//var diffNum = clinet.OmronPLCClient.Read<ushort>(station.dbData["R_diffNum"]);
|
|
//转换为调度中心地址
|
byte[] clientData = new byte[100];
|
//clientData[0] = (byte)(hreat ? 1 : 0);
|
clientData[90 + 1] = (byte)step;
|
//clientData[92] = (byte)(waring ? 1 : 0);
|
//int data_93 = 0;
|
//data_93 += isAB ? 2 : 0;
|
//data_93 += isToRihgt ? 4 : 0;
|
//clientData[93] = (byte)data_93;
|
//clientData[94] = (byte)diffNum;
|
|
TransferData(station, clinet, clientData);
|
//Create(clinet, station, requestType);
|
}
|
else if (station.stationType == "out")
|
{
|
//var materialtype = clinet.OmronPLCClient.Read<bool>(station.dbData["R_materialtype"]);
|
var waring = clinet.OmronPLCClient.Read<bool>(station.dbData["R_waring"]);
|
var step = clinet.OmronPLCClient.Read<ushort>(station.dbData["R_step"]);
|
var requestType = clinet.OmronPLCClient.Read<ushort>(station.dbData["R_requestType"]);
|
var isAB = clinet.OmronPLCClient.Read<bool>(station.dbData["R_isAB"]);
|
var isToRihgt = clinet.OmronPLCClient.Read<bool>(station.dbData["R_isToRihgt"]);
|
var diffNum = clinet.OmronPLCClient.Read<ushort>(station.dbData["R_diffNum"]);
|
|
//转换为调度中心地址
|
byte[] clientData = new byte[100];
|
clientData[90 + 1] = (byte)step;
|
clientData[92] = (byte)(waring ? 1 : 0);
|
int data_93 = 0;
|
data_93 += isAB ? 2 : 0;
|
data_93 += isToRihgt ? 4 : 0;
|
clientData[93] = (byte)data_93;
|
clientData[94] = (byte)diffNum;
|
|
TransferData(station, clinet, clientData);
|
Create(clinet, station, requestType);
|
}
|
}
|
}
|
}
|
|
private void Create(PLCClient clinet, StationInfo station, int requestType)
|
{
|
try
|
{
|
//入口上料
|
if (station.stationType == "in" && requestType == 1)
|
{
|
WCSCommon.CreateTask(station, true);
|
}
|
//出口卸料
|
else if (station.stationType == "out" && requestType == 2)
|
{
|
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">AGV的PLC</param>
|
/// <param name="eq_Client">主机设备PLC</param>
|
/// <param name="eqData">读的主机设备状态</param>
|
private void TransferData(StationInfo station, PLCClient eq_Client, byte[] eqData)
|
{
|
var agv_Client = WIDESEA_WCS.WCSService.Clients.FirstOrDefault(t => t.PLCName == station.agvCenterName);
|
if (agv_Client != null)
|
{
|
//读AGV
|
var agvData = (byte[])agv_Client.ReadDBValue(station.agvDBList[0], 100);
|
int hreat = (int)agvData[0];
|
int step = (int)agvData[90 + 1];
|
bool waring = agvData[92] == 0x1;
|
|
//写涂布主机流程步骤
|
eq_Client.OmronPLCClient.Write(station.dbData["W_step"], step);
|
eq_Client.OmronPLCClient.Write(station.dbData["W_waring"], waring);
|
if (station.stationType == "in")
|
{
|
eq_Client.OmronPLCClient.Write(station.dbData["W_hreat"], hreat);
|
var material_Type = DataTrans.GetStr(agvData, 26);
|
eq_Client.OmronPLCClient.Write(station.dbData["W_materialtype"], material_Type);
|
}
|
//写给AGV
|
agv_Client.WriteDBValue(station.agvDBList[1], eqData);
|
}
|
else
|
{
|
WriteLog.GetLog().Write($"【异常】{station.agvCenterName},读取调度中心PLC失败" + "\n", eq_Client.PLCName);
|
}
|
}
|
}
|
}
|