using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.LogInfo;
using WIDESEA_WCS.WCSClient;
namespace WIDESEA_WCS
{
[DisallowConcurrentExecution]
public class ChilderCarJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient;
if (client != null && client.IsConnected)
{
RunChilder(client);
}
return Task.CompletedTask;
}
private static string currentState { get; set; }
///
/// 当前运行状态
///
public static string CurrentState
{
get { return currentState; }
set
{
WriteLog.Write_Log("自动运行", "currentState", value);
currentState = value;
}
}
///
/// 子车目的地址
///
public static int childerPoint { get; set; }
///
/// 龙门目的地址
///
public static int gantryPoint { get; set; }
///
/// 升降取料的目的地址
///
public const int liftingPoint1 = 100;
///
/// 升降提起的目的地址
///
public const int liftingPoint2 = 200;
///
/// 子车完整取料流程
///
///
public void RunChilder(PLCClient client)
{
if (CurrentState == "子车开始")
{
//起始条件
int startPoint = childerPoint / 1000;
int endPoint = childerPoint % 1000;
client.Write("1010", startPoint);
client.Write("1011", endPoint); //写入目的地址
client.Write("64", true);//写入启动命令
CurrentState = "子车前往目的地址";
}
else if (CurrentState == "子车前往目的地址")
{
var arrive = client.Read("216"); //子车执行到位
if (arrive)
{
CurrentState = "龙门开始";
}
}
else if (CurrentState == "龙门开始")
{
//起始条件
int startPoint = gantryPoint / 1000;
int endPoint = gantryPoint % 1000;
client.Write("1028", startPoint);
client.Write("1029", endPoint); //写入目的地址
client.Write("208", true);//写入启动命令
CurrentState = "龙门前往目的地址";
}
else if (CurrentState == "龙门前往目的地址")
{
var arrive = client.Read("217"); //龙门执行到位
if (arrive)
{
CurrentState = "升降开始";
}
}
else if (CurrentState == "升降开始")
{
//起始条件
int startPoint = liftingPoint1 / 1000;
int endPoint = liftingPoint1 % 1000;
client.Write("1032", startPoint);
client.Write("1033", endPoint); //写入目的地址
client.Write("211", true);//写入启动命令
CurrentState = "升降前往目的地址";
}
else if (CurrentState == "升降前往目的地址")
{
var arrive = client.Read("218"); //升降到位
if (arrive)
{
CurrentState = "夹紧开始";
}
}
else if (CurrentState == "夹紧开始")
{
client.Write("213", true);//请求夹紧
var arrive = client.Read("219"); //夹紧完成
if (arrive)
{
CurrentState = "升降提起开始";
}
}
else if (CurrentState == "升降提起开始")
{
int startPoint = liftingPoint2 / 1000;
int endPoint = liftingPoint2 % 1000;
client.Write("1032", startPoint);
client.Write("1033", endPoint); //写入目的地址
client.Write("211", true);//写入启动命令
CurrentState = "升降提起前往目的地址";
}
else if (CurrentState == "升降提起前往目的地址")
{
var arrive = client.Read("218"); //升降到位
if (arrive)
{
CurrentState = "子车任务完成";
}
}
}
}
}