@@ -1,4 +1,6 @@
using BPASmartClient.Helper;
using BPASmartClient.AGV;
using BPASmartClient.Helper;
using BPASmartClient.Message;
using FryPot_DosingSystem.Model;
using System;
using System.Collections.Concurrent;
@@ -14,13 +16,78 @@ namespace FryPot_DosingSystem.Control
internal class DosingLogicControl
{
public static DosingLogicControl _instance;
public static DosingLogicControl GetInstance=>_instance ??= new DosingLogicControl();
public ConcurrentDictionary<string,object> PlcReadData=new ConcurrentDictionary<string, object>();
public static DosingLogicControl GetInstance => _instance ??= new DosingLogicControl();
public ConcurrentDictionary<string, object> PlcReadData = new ConcurrentDictionary<string, object>();
/// <summary>
/// 配方队列
/// </summary>
public ConcurrentQueue<NewRecipeModel> RecipeQuene = new ConcurrentQueue<NewRecipeModel>();
/// <summary>
/// 进料原料队列
/// </summary>
public ConcurrentQueue<MaterialInfo> InputMaterialQuene = new ConcurrentQueue<MaterialInfo>();
/// <summary>
/// 出料原料队列
/// </summary>
public ConcurrentQueue<MaterialInfo> OutputMaterialQuene = new ConcurrentQueue<MaterialInfo>();
/// <summary>
/// 全局变量对象声明
/// </summary>
GlobalVariable globalVar;
#region 上位机内部变量
int lineAlarm = 0;//线体故障信号 1:无故障 -1:故障
int FryPotAlarm = 0;//炒锅滚筒故障信号 1:无故障 -1:故障
int ReicpeNum = 0;//记录接收到的配方数
#endregion
#region agv临时变量
bool agvArriveLine = false;//agv是否到达线体装料位置
bool agvArriveFryPot = false;//agv是否到达炒锅送料位置
bool agvFryPotEmptyRollerArrive = false;//agv是否拿到炒锅空桶
#endregion
public DosingLogicControl()
{
globalVar = new GlobalVariable();
ActionManage.GetInstance.Register(new Action<object>(RecipeDataParse), "RecipeSetDown");
ActionManage.GetInstance.Register(new Action(() => { RecipeQuene.Clear(); InputMaterialQuene.Clear(); OutputMaterialQuene.Clear(); }), "ClearRecipes");
ActionManage.GetInstance.Register(new Action(() => { globalVar.PlcInite = 1; }), "StartPlcInite");
ActionManage.GetInstance.Register(new Action(() => { globalVar.PlcInite = 0; }), "EndPlcInite");
ActionManage.GetInstance.Register(new Action(() => { globalVar.ExitMainTask = true; }), "FryPotDosingMainTaskExit");
ResetProgram();
ReadPlcData();
IniteTask();
}
/// <summary>
/// 主任务重启
/// </summary>
private void ResetProgram()
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
if (RTrig.GetInstance("ResetProgram").Start(globalVar.PlcInite == 1))//判断是否初始化 一初始化就重启主任务
{
MessageLog.GetInstance.Show("主任务正在重启");
ThreadManage.GetInstance().StopTask("MainTask", new Action(() =>
{
ThreadManage.GetInstance().StopTask("MainViewReadPlcData", new Action(() =>
{
globalVar = null;
globalVar = new GlobalVariable();
ReicpeNum = 0;
ActionManage.GetInstance.CancelRegister("RecipeSetDown");
ActionManage.GetInstance.Register(new Action<object>(RecipeDataParse), "RecipeSetDown");
ActionManage.GetInstance.Send("ClearRecipes");
ReadPlcData();
IniteTask();
MessageLog.GetInstance.Show("主任务重启完成");
}));
}));
}
Thread.Sleep(10);
}), "ResetProgram");
}
/// <summary>
/// 实时获取plc数据
/// </summary>
public void ReadPlcData()
@@ -29,93 +96,96 @@ namespace FryPot_DosingSystem.Control
{
GetAddressData("D2001", new Action<ushort[]>((data) =>
{
GlobalVariable .rollerLineOne.StationOne = data[0];
GlobalVariable .rollerLineOne.StationTwo = data[1];
GlobalVariable .rollerLineOne.StationThree = data[2];
GlobalVariable .rollerLineOne.StationFour = data[3];
GlobalVariable .rollerLineOne.StationFive = data[4];
GlobalVariable .rollerLineOne.StationSix = data[5];
GlobalVariable .rollerLineOne.StationSeven = data[6];
GlobalVariable .rollerLineOne.StationEight = data[7];
globalVar .rollerLineOne.StationOne = data[0];
globalVar .rollerLineOne.StationTwo = data[1];
globalVar .rollerLineOne.StationThree = data[2];
globalVar .rollerLineOne.StationFour = data[3];
globalVar .rollerLineOne.StationFive = data[4];
globalVar .rollerLineOne.StationSix = data[5];
globalVar .rollerLineOne.StationSeven = data[6];
globalVar .rollerLineOne.StationEight = data[7];
}));
GetAddressData("D2011", new Action<ushort[]>((data) =>
{
GlobalVariable .rollerLineTwo.StationOne = data[0];
GlobalVariable .rollerLineTwo.StationTwo = data[1];
GlobalVariable .rollerLineTwo.StationThree = data[2];
GlobalVariable .rollerLineTwo.StationFour = data[3];
GlobalVariable .rollerLineTwo.StationFive = data[4];
GlobalVariable .rollerLineTwo.StationSix = data[5];
GlobalVariable .rollerLineTwo.StationSeven = data[6];
GlobalVariable .rollerLineTwo.StationEight = data[7];
globalVar .rollerLineTwo.StationOne = data[0];
globalVar .rollerLineTwo.StationTwo = data[1];
globalVar .rollerLineTwo.StationThree = data[2];
globalVar .rollerLineTwo.StationFour = data[3];
globalVar .rollerLineTwo.StationFive = data[4];
globalVar .rollerLineTwo.StationSix = data[5];
globalVar .rollerLineTwo.StationSeven = data[6];
globalVar .rollerLineTwo.StationEight = data[7];
}));
GetAddressData("D2021", new Action<ushort[]>((data) =>
{
GlobalVariable .rollerLineThree.StationOne = data[0];
GlobalVariable .rollerLineThree.StationTwo = data[1];
GlobalVariable .rollerLineThree.StationThree = data[2];
GlobalVariable .rollerLineThree.StationFour = data[3];
GlobalVariable .rollerLineThree.StationFive = data[4];
GlobalVariable .rollerLineThree.StationSix = data[5];
GlobalVariable .rollerLineThree.StationSeven = data[6];
GlobalVariable .rollerLineThree.StationEight = data[7];
globalVar .rollerLineThree.StationOne = data[0];
globalVar .rollerLineThree.StationTwo = data[1];
globalVar .rollerLineThree.StationThree = data[2];
globalVar .rollerLineThree.StationFour = data[3];
globalVar .rollerLineThree.StationFive = data[4];
globalVar .rollerLineThree.StationSix = data[5];
globalVar .rollerLineThree.StationSeven = data[6];
globalVar .rollerLineThree.StationEight = data[7];
}));
GetAddressData("D2040", new Action<ushort[]>((data) =>
{
GlobalVariable .fryPotOne.InputMaterialRollerRunningSingle = data[0];
GlobalVariable .fryPotTwo.InputMaterialRollerRunningSingle = data[1];
GlobalVariable .fryPotThree.InputMaterialRollerRunningSingle = data[2];
GlobalVariable .fryPotFour.InputMaterialRollerRunningSingle = data[3];
GlobalVariable.fryPotFive.InputMaterialRollerRunningSingle = data[4];
globalVar .fryPotOne.InputMaterialRollerRunningSingle = data[0];
globalVar .fryPotTwo.InputMaterialRollerRunningSingle = data[1];
globalVar .fryPotThree.InputMaterialRollerRunningSingle = data[2];
globalVar .fryPotFour.InputMaterialRollerRunningSingle = data[3];
globalVar.fryPotFive.InputMaterialRollerRunningSingle = data[4];
}));
GetAddressData("D2045", new Action<ushort[]>((data) =>
{
GlobalVariable .fryPotOne.InputMaterialArrivedSingle = data[0];
GlobalVariable .fryPotTwo.InputMaterialArrivedSingle = data[1];
GlobalVariable .fryPotThree.InputMaterialArrivedSingle = data[2];
GlobalVariable .fryPotFour.InputMaterialArrivedSingle = data[3];
GlobalVariable .fryPotFive.InputMaterialArrivedSingle = data[4];
globalVar .fryPotOne.InputMaterialArrivedSingle = data[0];
globalVar .fryPotTwo.InputMaterialArrivedSingle = data[1];
globalVar .fryPotThree.InputMaterialArrivedSingle = data[2];
globalVar .fryPotFour.InputMaterialArrivedSingle = data[3];
globalVar .fryPotFive.InputMaterialArrivedSingle = data[4];
}));
GetAddressData("D2050", new Action<ushort[]>((data) =>
{
GlobalVariable .fryPotOne.EmptyBarrelArrivedSingle = data[0];
GlobalVariable .fryPotTwo.EmptyBarrelArrivedSingle = data[1];
GlobalVariable .fryPotThree.EmptyBarrelArrivedSingle = data[2];
GlobalVariable .fryPotFour.EmptyBarrelArrivedSingle = data[3];
GlobalVariable .fryPotFive.EmptyBarrelArrivedSingle = data[4];
globalVar .fryPotOne.EmptyBarrelArrivedSingle = data[0];
globalVar .fryPotTwo.EmptyBarrelArrivedSingle = data[1];
globalVar .fryPotThree.EmptyBarrelArrivedSingle = data[2];
globalVar .fryPotFour.EmptyBarrelArrivedSingle = data[3];
globalVar .fryPotFive.EmptyBarrelArrivedSingle = data[4];
}));
GetAddressData("D2065", new Action<ushort[]>((data) =>
{
GlobalVariable .fryPotOne.EmptyBarrelRollerRunningSingle = data[0];
GlobalVariable .fryPotTwo.EmptyBarrelRollerRunningSingle = data[1];
GlobalVariable .fryPotThree.EmptyBarrelRollerRunningSingle = data[2];
GlobalVariable .fryPotFour.EmptyBarrelRollerRunningSingle = data[3];
GlobalVariable .fryPotFive.EmptyBarrelRollerRunningSingle = data[4];
globalVar .fryPotOne.EmptyBarrelRollerRunningSingle = data[0];
globalVar .fryPotTwo.EmptyBarrelRollerRunningSingle = data[1];
globalVar .fryPotThree.EmptyBarrelRollerRunningSingle = data[2];
globalVar .fryPotFour.EmptyBarrelRollerRunningSingle = data[3];
globalVar .fryPotFive.EmptyBarrelRollerRunningSingle = data[4];
}));
GetAddressData("D2070", new Action<ushort[]>((data) =>
{
GlobalVariable .fryPotOne.RollerTroubleSingle = data[0];
GlobalVariable .fryPotTwo.RollerTroubleSingle = data[1];
GlobalVariable .fryPotThree.RollerTroubleSingle = data[2];
GlobalVariable .fryPotFour.RollerTroubleSingle = data[3];
GlobalVariable .fryPotFive.RollerTroubleSingle = data[4];
globalVar .fryPotOne.RollerTroubleSingle = data[0];
globalVar .fryPotTwo.RollerTroubleSingle = data[1];
globalVar .fryPotThree.RollerTroubleSingle = data[2];
globalVar .fryPotFour.RollerTroubleSingle = data[3];
globalVar .fryPotFive.RollerTroubleSingle = data[4];
}));
GetAddressData("D2078",new Action<ushort[]>(data => {
GlobalVariable.rollerLineOne.RecipeCompleteSingle = data[0];
GlobalVariable.rollerLineTwo.RecipeCompleteSingle = data[1];
GlobalVariable.rollerLineThree.RecipeCompleteSingle = data[2];
GetAddressData("D2078", new Action<ushort[]>(data =>
{
globalVar.rollerLineOne.RecipeCompleteSingle = data[0];
globalVar.rollerLineTwo.RecipeCompleteSingle = data[1];
globalVar.rollerLineThree.RecipeCompleteSingle = data[2];
}));
GetAddressData("D2075",new Action<ushort[]>(data => {
GlobalVariable.CleadBarrelEnterSingle = data[0];
GetAddressData("D2075", new Action<ushort[]>(data =>
{
globalVar.CleadBarrelEnterSingle = data[0];
}));
GetAddressData("D2077", new Action<ushort[]>(data => {
GetAddressData("D2077", new Action<ushort[]>(data =>
{
GlobalVariable .CleadBarrelExitSingle = data[0];
globalVar .CleadBarrelExitSingle = data[0];
}));
Thread.Sleep(10);
}), "MainViewReadPlcData");
}
/// <summary>
@@ -125,7 +195,7 @@ namespace FryPot_DosingSystem.Control
/// <returns></returns>
public void GetAddressData(string address, Action<ushort[]> action)
{
PlcReadData= DeviceOperate.GetInstance.GetAllData();
PlcReadData = DeviceOperate.GetInstance.GetAllData();
if (PlcReadData.ContainsKey(address))
{
action((ushort[])(PlcReadData[address]));
@@ -137,7 +207,7 @@ namespace FryPot_DosingSystem.Control
/// <param name="address"></param>
/// <param name="Value"></param>
public void WritePlcData(string address, ushort Value)
{
{
DeviceOperate.GetInstance.WritePlcData(address, Value);
}
/// <summary>
@@ -145,18 +215,655 @@ namespace FryPot_DosingSystem.Control
/// </summary>
public void IniteTask()
{
ThreadManage.GetInstance().StartLong(new Action(() => {
ThreadManage.GetInstance().StartLong(new Action(() =>
{
MainTask();
}),"启动主任务循环",true);
}), "MainTask");
}
/// <summary>
/// 配方数据接收
/// </summary>
public void RecipeDataParse(object obj)
{
if (obj != null && obj is NewRecipeModel recipe)
{
RecipeQuene.Enqueue(recipe);
ReicpeNum++;
MessageLog.GetInstance.Show($"接收到{ReicpeNum}个配方");
}
}
/// <summary>
/// 开启主任务
/// </summary>
public void MainTask()
{
{
RecipeDataToPlc();
AgvLoadRoller();
FryPotInputMaterial();
FryPotOutputMaterial();
}
/// <summary>
/// 数据下发PLC
/// </summary>
public void RecipeDataToPlc()
{
if (RecipeQuene.Count > 0 && OutputMaterialQuene.Count == 0 && InputMaterialQuene.Count == 0)//后续添加其它限制条件
{
if (RecipeQuene.TryDequeue(out NewRecipeModel result))
{
MessageLog.GetInstance.Show($"开始制作【{result.RecipeName}】 配方");
for (int i = 0; i < result.materialCollection.Count; i++) //遍历单个配方中所有物料
{
//将配方中原料加入新的队列
InputMaterialQuene.Enqueue(new MaterialInfo()
{
materialType = result.materialCollection[i],
materialId = result.RecipeId
});
ushort n = result.materialCollection[i].MaterialLoc;
switch (n / 100)
{
case 1:
case 4: RollerOneDataWrite(i, result.materialCollection[i].MaterialLoc, result.materialCollection[i].MaterialWeight); break;//1号滚筒线桶号以及重量数据下发
case 2:
case 5: RollerTwoDataWrite(i, result.materialCollection[i].MaterialLoc, result.materialCollection[i].MaterialWeight); break;//2号滚筒线桶号以及重量数据下发
case 3: RollerThreeDataWrite(i, result.materialCollection[i].MaterialLoc, result.materialCollection[i].MaterialWeight); break;//3号滚筒线桶号以及重量数据下发
}
}
switch (result.materialCollection[0].MaterialLoc / 100)
{
case 1:
DeviceOperate.GetInstance.WritePlcData("D1009", (ushort)result.materialCollection.Count); break;//发送1号滚筒线工序数据
case 2:
DeviceOperate.GetInstance.WritePlcData("D1026", (ushort)result.materialCollection.Count); break;//发送2号滚筒线工序数据
case 3:
DeviceOperate.GetInstance.WritePlcData("D1043", (ushort)result.materialCollection.Count); break;//发送3号滚筒线工序数据
}
}
}
}
/// <summary>
/// AGV到配方对应线体装桶以及出料到炒锅
/// </summary>
public void AgvLoadRoller()
{
lineAlarm = 0;
if (InputMaterialQuene.Count > 0)
{
switch (InputMaterialQuene.ElementAt(0).materialType.MaterialLoc / 100)
{
case 1:
case 4: AgvToLineOneLoadRoller(); AgvFromLineOneToFryPot(); break;//AGV到1号线体装桶
case 2:
case 5: AgvToLineTwoLoadRoller(); AgvFromLineTwoToFryPot(); break;//AGV到2号线体装桶
case 3: AgvToLineThreeLoadRoller(); AgvFromLineThreeToFryPot(); break;//AGV到3号线体装桶
}
}
}
/// <summary>
/// AGV从炒锅送料位置到倒料过程处理
/// </summary>
public void FryPotInputMaterial()
{
if (OutputMaterialQuene.Count > 0 && !globalVar.InOrOutputLock)
{
while (!agvArriveFryPot)//等待agv到达炒锅位置
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
AgvArriveFryPotSingleSetDown();
FryPotRollerTroubleCheck();
if (FryPotAlarm == 1)//炒锅滚筒无故障
{
//炒锅滚筒进料运行到位处理
FryPotInputMaterialRollerOperate();
globalVar.InOrOutputLock = true;
}
else
{
//MessageLog.GetInstance.ShowEx($"警告:炒锅{OutputMaterialQuene.ElementAt(0).materialType.MaterialLoc / 100}滚筒故障!!!");
}
}
}
/// <summary>
/// 炒锅出桶
/// </summary>
public void FryPotOutputMaterial()
{
if (OutputMaterialQuene.Count > 0 && globalVar.InOrOutputLock)
{
while (!agvArriveFryPot)//等待agv到达炒锅位置
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
AgvArriveFryPotOutEmptyRollerSingleSetDown();//暂时考虑agv送完料后原地等待,不加条件,直接发送到位信号
FryPotRollerTroubleCheck();
if (FryPotAlarm == 1)//无故障
{
FryPotOutEmpetyRollerOperate();
if (OutputMaterialQuene.TryDequeue(out MaterialInfo materialInfo))//空桶出桶后,出料原料队列移除对应原料
{
while (!agvFryPotEmptyRollerArrive)//等待AGV拿到出桶空桶
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
//AGV拿到空桶,让AGV运桶到指定位置,同时可以让下一个AGV从线体装料运到炒锅
globalVar.AllowAgvToLineLoadRoller = true;
globalVar.InOrOutputLock = false;
}
}
else//有故障
{
}
}
}
/// <summary>
/// 炒锅滚筒进料运行到位处理
/// </summary>
public void FryPotInputMaterialRollerOperate()
{
switch (OutputMaterialQuene.ElementAt(0).materialType.MaterialLoc / 100)
{
case 1:
while (globalVar.fryPotOne.InputMaterialArrivedSingle == 0 || globalVar.fryPotOne.InputMaterialRollerRunningSingle == 0)
{
Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
}
MessageLog.GetInstance.Show($"炒锅【1】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break;
case 2:
while (globalVar.fryPotTwo.InputMaterialArrivedSingle == 0 || globalVar.fryPotTwo.InputMaterialRollerRunningSingle == 0)
{
Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
}
MessageLog.GetInstance.Show($"炒锅【2】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break;
case 3:
while (globalVar.fryPotThree.InputMaterialArrivedSingle == 0 || globalVar.fryPotThree.InputMaterialRollerRunningSingle == 0)
{
Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
}
MessageLog.GetInstance.Show($"炒锅【3】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break;
case 4:
while (globalVar.fryPotFour.InputMaterialArrivedSingle == 0 || globalVar.fryPotFour.InputMaterialRollerRunningSingle == 0)
{
Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
}
MessageLog.GetInstance.Show($"炒锅【4】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break;
case 5:
while (globalVar.fryPotFive.InputMaterialArrivedSingle == 0 || globalVar.fryPotFive.InputMaterialRollerRunningSingle == 0)
{
Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
}
MessageLog.GetInstance.Show($"炒锅【5】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}已到进料位置,准备倒料"); break;
}
}
/// <summary>
/// 炒锅滚筒空桶出桶处理
/// </summary>
public void FryPotOutEmpetyRollerOperate()
{
switch (OutputMaterialQuene.ElementAt(0).materialType.MaterialLoc / 100)
{
case 1: while (globalVar.fryPotOne.EmptyBarrelArrivedSingle == 0 || globalVar.fryPotOne.EmptyBarrelRollerRunningSingle == 0) { Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
} MessageLog.GetInstance.Show($"炒锅【1】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}空桶到达出桶位置,正在出桶"); break;
case 2: while (globalVar.fryPotTwo.EmptyBarrelArrivedSingle == 0 || globalVar.fryPotTwo.EmptyBarrelRollerRunningSingle == 0) { Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
} MessageLog.GetInstance.Show($"炒锅【2】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}空桶到达出桶位置,正在出桶"); break;
case 3: while (globalVar.fryPotThree.EmptyBarrelArrivedSingle == 0 || globalVar.fryPotThree.EmptyBarrelRollerRunningSingle == 0) { Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
} MessageLog.GetInstance.Show($"炒锅【3】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}空桶到达出桶位置,正在出桶"); break;
case 4: while (globalVar.fryPotFour.EmptyBarrelArrivedSingle == 0 || globalVar.fryPotFour.EmptyBarrelRollerRunningSingle == 0) { Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
} MessageLog.GetInstance.Show($"炒锅【4】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}空桶到达出桶位置,正在出桶"); break;
case 5: while (globalVar.fryPotFive.EmptyBarrelArrivedSingle == 0 || globalVar.fryPotFive.EmptyBarrelRollerRunningSingle == 0) { Thread.Sleep(5); if (globalVar.ExitMainTask)
return;
} MessageLog.GetInstance.Show($"炒锅【5】原料:{OutputMaterialQuene.ElementAt(0).materialType.MaterialName}空桶到达出桶位置,正在出桶"); break;
}
}
/// <summary>
/// 发送agv送料就位信号至PLC(线体到炒锅)
/// </summary>
public void AgvArriveFryPotSingleSetDown()
{
switch (OutputMaterialQuene.ElementAt(0).materialType.MaterialLoc / 100)
{
case 1: DeviceOperate.GetInstance.WritePlcData("D1055", 1); break;//agv到炒锅1送料就位信号
case 2: DeviceOperate.GetInstance.WritePlcData("D1056", 1); break;//agv到炒锅2送料就位信号
case 3: DeviceOperate.GetInstance.WritePlcData("D1057", 1); break;//agv到炒锅3送料就位信号
case 4: DeviceOperate.GetInstance.WritePlcData("D1058", 1); break;//agv到炒锅4送料就位信号
case 5: DeviceOperate.GetInstance.WritePlcData("D1059", 1); break;//agv到炒锅5送料就位信号
}
}
/// <summary>
/// 发送agv回桶就位信号至PLC
/// </summary>
public void AgvArriveFryPotOutEmptyRollerSingleSetDown()
{
switch (OutputMaterialQuene.ElementAt(0).materialType.MaterialLoc / 100)
{
case 1: DeviceOperate.GetInstance.WritePlcData("D1060", 1); break;//agv到炒锅1送料就位信号
case 2: DeviceOperate.GetInstance.WritePlcData("D1061", 1); break;//agv到炒锅2送料就位信号
case 3: DeviceOperate.GetInstance.WritePlcData("D1062", 1); break;//agv到炒锅3送料就位信号
case 4: DeviceOperate.GetInstance.WritePlcData("D1063", 1); break;//agv到炒锅4送料就位信号
case 5: DeviceOperate.GetInstance.WritePlcData("D1064", 1); break;//agv到炒锅5送料就位信号
}
}
/// <summary>
/// 处理agv从线体1到送料到炒锅的条件
/// </summary>
/// <param name="lineAlarm"></param>
public void AgvFromLineOneToFryPot()
{
erp: if (lineAlarm == 1)//无故障
{
while (!agvArriveLine)//等待AGV到线体装料位置
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
agvArriveLine = false;
AgvArriveLineSingelSetDown();
if (InputMaterialQuene.TryDequeue(out MaterialInfo materialInfo))
{
while (!(globalVar.rollerLineOne.StationEight == materialInfo.materialType.MaterialLoc))//等待线体工号位8存放对应原料桶号
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
OutputMaterialQuene.Enqueue(materialInfo);
//原料到位,agv到位,agv运料到炒锅
}
}
else//有故障
{
while (lineAlarm == -1)
{
Thread.Sleep(50);
if (globalVar.ExitMainTask)
return;
}
MessageLog.GetInstance.Show("线体【1】滚筒故障解除,继续运行");
lineAlarm = 1;
goto erp;
}
}
/// <summary>
/// 处理agv从线体2到送料到炒锅的条件
/// </summary>
/// <param name="lineAlarm"></param>
public void AgvFromLineTwoToFryPot()
{
erp: if (lineAlarm == 1)//无故障
{
while (!agvArriveLine)//等待AGV到线体装料位置
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
agvArriveLine = false;
AgvArriveLineSingelSetDown();
if (InputMaterialQuene.TryDequeue(out MaterialInfo materialInfo))
{
while (!(globalVar.rollerLineTwo.StationEight == materialInfo.materialType.MaterialLoc))//等待线体工号位8存放对应原料桶号
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
OutputMaterialQuene.Enqueue(materialInfo);
//原料到位,agv到位,agv运料到炒锅
}
}
else//有故障
{
while (lineAlarm == -1)
{
Thread.Sleep(50);
if (globalVar.ExitMainTask)
return;
}
MessageLog.GetInstance.Show("线体【2】滚筒故障解除,继续运行");
lineAlarm = 1;
goto erp;
}
}
/// <summary>
/// 处理agv从线体3到送料到炒锅的条件
/// </summary>
/// <param name="lineAlarm"></param>
public void AgvFromLineThreeToFryPot()
{
erp: if (lineAlarm == 1)//无故障
{
while (!agvArriveLine)//等待AGV到线体装料位置
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
agvArriveLine = false;
AgvArriveLineSingelSetDown();
if (InputMaterialQuene.TryDequeue(out MaterialInfo materialInfo))
{
while (!(globalVar.rollerLineThree.StationEight == materialInfo.materialType.MaterialLoc))//等待线体工号位8存放对应原料桶号
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
OutputMaterialQuene.Enqueue(materialInfo);
//原料到位,agv到位,agv运料到炒锅
}
}
else//有故障
{
while (lineAlarm == -1)
{
Thread.Sleep(50);
if (globalVar.ExitMainTask)
return;
}
MessageLog.GetInstance.Show("线体【3】滚筒故障解除,继续运行");
lineAlarm = 1;
goto erp;
}
}
public void AgvToLineOneLoadRoller()
{
if (globalVar.rollerLineOne.OutMaterialingTroubleSingle == 0)//输送线无故障
{
if (InputMaterialQuene.Count > 0)
{
while (!globalVar.AllowAgvToLineLoadRoller || globalVar.rollerLineOne.OutMaterialingSingle == 0)
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
AGVHelper.GetInstance.AgvToLineOneLoadRoller();
MessageLog.GetInstance.Show("AGV去1号线体");
globalVar.AllowAgvToLineLoadRoller = false;
}
}
else
{
MessageLog.GetInstance.ShowEx("警告:滚筒输送线体【1】故障!!!");
lineAlarm = -1;
}
lineAlarm = 1;
}
public void AgvToLineTwoLoadRoller()
{
if (globalVar.rollerLineTwo.OutMaterialingTroubleSingle == 0)//输送线无故障
{
if (InputMaterialQuene.Count > 0)
{
while (!globalVar.AllowAgvToLineLoadRoller || globalVar.rollerLineOne.OutMaterialingSingle == 0) //后续考虑是否用while
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
AGVHelper.GetInstance.AgvToLineTwoLoadRoller();
MessageLog.GetInstance.Show("AGV去2号线体");
globalVar.AllowAgvToLineLoadRoller = false;
}
}
else
{
MessageLog.GetInstance.ShowEx("警告:滚筒输送线体【2】故障!!!");
lineAlarm = -1;
}
lineAlarm = 1;
}
public void AgvToLineThreeLoadRoller()
{
if (globalVar.rollerLineThree.OutMaterialingTroubleSingle == 0)//输送线无故障
{
if (InputMaterialQuene.Count > 0)
{
while (!globalVar.AllowAgvToLineLoadRoller || globalVar.rollerLineOne.OutMaterialingSingle == 0) //后续考虑是否用while
{
Thread.Sleep(5);
if (globalVar.ExitMainTask)
return;
}
AGVHelper.GetInstance.AgvToLineThreeLoadRoller();
MessageLog.GetInstance.Show("AGV去3号线体");
globalVar.AllowAgvToLineLoadRoller = false;
}
}
else
{
MessageLog.GetInstance.ShowEx("警告:滚筒输送线体【3】故障!!!");
lineAlarm = -1;
}
lineAlarm = 1;
}
/// <summary>
/// 1号线体数据下发
/// </summary>
/// <param name="count"></param>
/// <param name="materialLoc"></param>
/// <param name="materialWeight"></param>
public void RollerOneDataWrite(int count, ushort materialLoc, ushort materialWeight)
{
switch (count)
{
case 0:
DeviceOperate.GetInstance.WritePlcData("D1001", materialLoc);//桶1位置
DeviceOperate.GetInstance.WritePlcData("D1010", materialWeight);//桶2重量
break;
case 1:
DeviceOperate.GetInstance.WritePlcData("D1002", materialLoc);//桶2位置
DeviceOperate.GetInstance.WritePlcData("D1011", materialWeight);//桶2重量
break;
case 2:
DeviceOperate.GetInstance.WritePlcData("D1003", materialLoc);//桶3位置
DeviceOperate.GetInstance.WritePlcData("D1012", materialWeight);//桶3重量
break;
case 3:
DeviceOperate.GetInstance.WritePlcData("D1004", materialLoc);//桶4位置
DeviceOperate.GetInstance.WritePlcData("D1013", materialWeight);//桶4重量
break;
case 4:
DeviceOperate.GetInstance.WritePlcData("D1005", materialLoc);//桶5位置
DeviceOperate.GetInstance.WritePlcData("D1014", materialWeight);//桶5重量
break;
case 5:
DeviceOperate.GetInstance.WritePlcData("D1006", materialLoc);//桶6位置
DeviceOperate.GetInstance.WritePlcData("D1015", materialWeight);//桶6重量
break;
case 6:
DeviceOperate.GetInstance.WritePlcData("D1007", materialLoc);//桶7位置
DeviceOperate.GetInstance.WritePlcData("D1016", materialWeight);//桶7重量
break;
case 7:
DeviceOperate.GetInstance.WritePlcData("D1008", materialLoc);//桶8位置
DeviceOperate.GetInstance.WritePlcData("D1017", materialWeight);//桶8重量
break;
}
}
/// <summary>
/// 2号线体数据下发
/// </summary>
/// <param name="count"></param>
/// <param name="materialLoc"></param>
/// <param name="materialWeight"></param>
public void RollerTwoDataWrite(int count, ushort materialLoc, ushort materialWeight)
{
switch (count)
{
case 0:
DeviceOperate.GetInstance.WritePlcData("D1018", materialLoc);//桶1位置
DeviceOperate.GetInstance.WritePlcData("D1027", materialWeight);//桶2重量
break;
case 1:
DeviceOperate.GetInstance.WritePlcData("D1019", materialLoc);//桶2位置
DeviceOperate.GetInstance.WritePlcData("D1028", materialWeight);//桶2重量
break;
case 2:
DeviceOperate.GetInstance.WritePlcData("D1020", materialLoc);//桶3位置
DeviceOperate.GetInstance.WritePlcData("D1029", materialWeight);//桶3重量
break;
case 3:
DeviceOperate.GetInstance.WritePlcData("D1021", materialLoc);//桶4位置
DeviceOperate.GetInstance.WritePlcData("D1030", materialWeight);//桶4重量
break;
case 4:
DeviceOperate.GetInstance.WritePlcData("D1022", materialLoc);//桶5位置
DeviceOperate.GetInstance.WritePlcData("D1031", materialWeight);//桶5重量
break;
case 5:
DeviceOperate.GetInstance.WritePlcData("D1023", materialLoc);//桶6位置
DeviceOperate.GetInstance.WritePlcData("D1032", materialWeight);//桶6重量
break;
case 6:
DeviceOperate.GetInstance.WritePlcData("D1024", materialLoc);//桶7位置
DeviceOperate.GetInstance.WritePlcData("D1033", materialWeight);//桶7重量
break;
case 7:
DeviceOperate.GetInstance.WritePlcData("D1025", materialLoc);//桶8位置
DeviceOperate.GetInstance.WritePlcData("D1034", materialWeight);//桶8重量
break;
}
}
/// <summary>
/// 3号线体数据下发
/// </summary>
/// <param name="count"></param>
/// <param name="materialLoc"></param>
/// <param name="materialWeight"></param>
public void RollerThreeDataWrite(int count, ushort materialLoc, ushort materialWeight)
{
switch (count)
{
case 0:
DeviceOperate.GetInstance.WritePlcData("D1035", materialLoc);//桶1位置
DeviceOperate.GetInstance.WritePlcData("D1044", materialWeight);//桶2重量
break;
case 1:
DeviceOperate.GetInstance.WritePlcData("D1036", materialLoc);//桶2位置
DeviceOperate.GetInstance.WritePlcData("D1045", materialWeight);//桶2重量
break;
case 2:
DeviceOperate.GetInstance.WritePlcData("D1037", materialLoc);//桶3位置
DeviceOperate.GetInstance.WritePlcData("D1046", materialWeight);//桶3重量
break;
case 3:
DeviceOperate.GetInstance.WritePlcData("D1038", materialLoc);//桶4位置
DeviceOperate.GetInstance.WritePlcData("D1047", materialWeight);//桶4重量
break;
case 4:
DeviceOperate.GetInstance.WritePlcData("D1039", materialLoc);//桶5位置
DeviceOperate.GetInstance.WritePlcData("D1048", materialWeight);//桶5重量
break;
case 5:
DeviceOperate.GetInstance.WritePlcData("D1040", materialLoc);//桶6位置
DeviceOperate.GetInstance.WritePlcData("D1049", materialWeight);//桶6重量
break;
case 6:
DeviceOperate.GetInstance.WritePlcData("D1041", materialLoc);//桶7位置
DeviceOperate.GetInstance.WritePlcData("D1050", materialWeight);//桶7重量
break;
case 7:
DeviceOperate.GetInstance.WritePlcData("D1042", materialLoc);//桶8位置
DeviceOperate.GetInstance.WritePlcData("D1051", materialWeight);//桶8重量
break;
}
}
/// <summary>
/// AGV进料就位信号下发至PLC
/// </summary>
public void AgvArriveLineSingelSetDown()
{
switch (InputMaterialQuene.ElementAt(0).materialType.MaterialLoc / 100)
{
case 1:
case 4: DeviceOperate.GetInstance.WritePlcData("D1052", 1); break;//AGV进料就位信号1
case 2:
case 5: DeviceOperate.GetInstance.WritePlcData("D1053", 1); break;//AGV进料就位信号2
case 3: DeviceOperate.GetInstance.WritePlcData("D1054", 1); break;//AGV进料就位信号3
}
}
/// <summary>
/// 炒锅滚筒信号检测
/// </summary>
public void FryPotRollerTroubleCheck()
{
FryPotAlarm = 0;
switch (OutputMaterialQuene.ElementAt(0).materialType.MaterialLoc / 100)
{
case 1:
if (globalVar.fryPotOne.RollerTroubleSingle == 1) { FryPotAlarm = -1; MessageLog.GetInstance.ShowEx("警告:炒锅【1】输送滚筒发生故障"); } else { FryPotAlarm = 1; } while (globalVar.fryPotOne.RollerTroubleSingle == 1)
{
Thread.Sleep(50); if (globalVar.ExitMainTask)
return;
}
FryPotAlarm = 1; break;
case 2:
if (globalVar.fryPotTwo.RollerTroubleSingle == 1) { FryPotAlarm = -1; MessageLog.GetInstance.ShowEx("警告:炒锅【1】输送滚筒发生故障"); } else { FryPotAlarm = 1; } while (globalVar.fryPotTwo.RollerTroubleSingle == 1)
{
Thread.Sleep(50); if (globalVar.ExitMainTask)
return;
}
FryPotAlarm = 1; break;
case 3:
if (globalVar.fryPotThree.RollerTroubleSingle == 1) { FryPotAlarm = -1; MessageLog.GetInstance.ShowEx("警告:炒锅【1】输送滚筒发生故障"); } else { FryPotAlarm = 1; } while (globalVar.fryPotThree.RollerTroubleSingle == 1)
{
Thread.Sleep(50); if (globalVar.ExitMainTask)
return;
}
FryPotAlarm = 1; break;
case 4:
if (globalVar.fryPotFour.RollerTroubleSingle == 1) { FryPotAlarm = -1; MessageLog.GetInstance.ShowEx("警告:炒锅【1】输送滚筒发生故障"); } else { FryPotAlarm = 1; } while (globalVar.fryPotFour.RollerTroubleSingle == 1)
{
Thread.Sleep(50); if (globalVar.ExitMainTask)
return;
}
FryPotAlarm = 1; break;
case 5:
if (globalVar.fryPotFive.RollerTroubleSingle == 1) { FryPotAlarm = -1; MessageLog.GetInstance.ShowEx("警告:炒锅【1】输送滚筒发生故障"); } else { FryPotAlarm = 1; } while (globalVar.fryPotFive.RollerTroubleSingle == 1)
{
Thread.Sleep(50); if (globalVar.ExitMainTask)
return;
}
FryPotAlarm = 1; break;
}
}
}
}