using BPA.Message; using BPA.Message.Enum; using BPASmartClient.Business; using BPASmartClient.Device; using BPASmartClient.EventBus; using BPASmartClient.Helper; using BPASmartClient.Model; using BPASmartClient.MorkBF.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using static BPASmartClient.EventBus.EventBus; namespace BPASmartClient.MorkBF { public class Control_MorkBF : BaseDevice { GVL_MorkBF morkBF = new GVL_MorkBF(); public override DeviceClientType DeviceType => DeviceClientType.MORKCS; public override void DoMain() { MonitorViewModel.DeviceId = DeviceId; CommandRegist();//调试 ServerInit(); DataParse();//数据解析 ScreenDataServer();//大屏数据上报 DeviceProcessLogShow("MORKF 设备初始化完成"); } private void DataParse() { EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle) { if (@event == null) return; if (@event is DoOrderEvent order) { if (order.MorkOrder.GoodBatchings == null) return; OrderCount++; DeviceProcessLogShow($"接收到{OrderCount}次订单"); } }); } private void ServerInit() { //物料信息 EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (@event == null) return; if (@event is MaterialDeliveryEvent material) { orderMaterialDelivery = material.orderMaterialDelivery; } }); //配方数据信息 EventBus.EventBus.GetInstance().Subscribe(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack) { if (@event == null) return; if (@event is RecipeBomEvent recipe) { recipeBoms = recipe.recipeBoms; } }); } /// /// 调试 /// /// private void CommandRegist() { #region 炒锅1 ActionManage.GetInstance.Register(FirePot1_SetFireGear, "FirePot1_SetFireGear");//炒锅1设定加热挡位 ActionManage.GetInstance.Register(FirePot1_StartFire, "FirePot1_StartFire");//炒锅1加热启动 ActionManage.GetInstance.Register(FirePot1_StartFire, "FirePot1_StopFire");//炒锅1关闭加热 ActionManage.GetInstance.Register(FirePot1_SetStirGear, "FirePot1_SetStirGear");//炒锅1设定搅拌挡位 ActionManage.GetInstance.Register(FirePot1_StartStir, "FirePot1_StartStir");//炒锅1搅拌启动 ActionManage.GetInstance.Register(FirePot1_StartStir, "FirePot1_StopStir");//炒锅1搅拌停止 ActionManage.GetInstance.Register(FirePot1_SetTurnSpeed, "FirePot1_SetTurnSpeed");//炒锅1翻转频率设定 #endregion #region 炒锅2 ActionManage.GetInstance.Register(FirePot2_SetFireGear, "FirePot2_SetFireGear");//炒锅2设定加热挡位 ActionManage.GetInstance.Register(FirePot2_StartFire, "FirePot2_StartFire");//炒锅2加热启动 ActionManage.GetInstance.Register(FirePot2_StartFire, "FirePot2_StopFire");//炒锅2关闭加热 ActionManage.GetInstance.Register(FirePot2_SetStirGear, "FirePot2_SetStirGear");//炒锅2设定搅拌挡位 ActionManage.GetInstance.Register(FirePot2_StartStir, "FirePot2_StartStir");//炒锅2搅拌启动 ActionManage.GetInstance.Register(FirePot2_StartStir, "FirePot2_StopStir");//炒锅2搅拌停止 ActionManage.GetInstance.Register(FirePot2_SetTurnSpeed, "FirePot2_SetTurnSpeed");//炒锅2翻转频率设定 #endregion #region 炒锅通用 ActionManage.GetInstance.Register(FirePot_Reset, "FirePot_Reset");//复位; ActionManage.GetInstance.Register(FirePot_PotGotoOrigin, "FirePot_PotGotoOrigin");//炒锅回原点 ActionManage.GetInstance.Register(FirePot_PotGotoP1, "FirePot_PotGotoP1");//炒锅去位置1 ActionManage.GetInstance.Register(FirePot_PotGotoP2, "FirePot_PotGotoP2");//炒锅去位置2 ActionManage.GetInstance.Register(FirePot_PotGotoP3, "FirePot_PotGotoP3");//炒锅去位置3 ActionManage.GetInstance.Register(FirePot_PotGotoP4, "FirePot_PotGotoP4");//炒锅去位置4 ActionManage.GetInstance.Register(FirePot_PotGotoOutFoodPositiong, "FirePot_PotGotoOutFoodPositiong");//炒锅去出餐位置 ActionManage.GetInstance.Register(FirePot_PotGotoInFoodPosition, "FirePot_PotGotoInFoodPosition");//炒锅去投料位置 ActionManage.GetInstance.Register(FirePot_StartOutFood, "FirePot_StartOutFood");//出餐启动 ActionManage.GetInstance.Register(FirePot_Clean, "FirePot_Clean");//清洗 ActionManage.GetInstance.Register(FirePot_StartPumpWater, "FirePot_StartPumpWater");//抽水启动 ActionManage.GetInstance.Register(FirePot_StartPumpOil, "FirePot_StartPumpOil");//抽油启动 #endregion #region 机器人 ActionManage.GetInstance.Register(RobotStart, "RobotStart");//机器人启动 ActionManage.GetInstance.Register(RobotStop, "RobotStop");//机器人停止 ActionManage.GetInstance.Register(RobotReset, "RobotReset");//复位 ActionManage.GetInstance.Register(RobotProgramStart, "RobotProgramStart");//程序启动 ActionManage.GetInstance.Register(Robot_Pot1AllowInMaterail, "Robot_Pot1AllowInMaterail");//1号炒锅允许机器人投料 ActionManage.GetInstance.Register(Robot_Pot1OutFoodInSlowDown, "Robot_Pot1OutFoodInSlowDown");//1号炒锅出餐倒料到减速位 ActionManage.GetInstance.Register(Robot_Pot1OutFood, "Robot_Pot1OutFoodInSlowDown");//1号炒锅出餐倒料完成 ActionManage.GetInstance.Register(Robot_Pot2AllowInMaterail, "Robot_Pot2AllowInMaterail");//2号炒锅允许机器人投料 ActionManage.GetInstance.Register(Robot_Pot2OutFoodInSlowDown, "Robot_Pot2OutFoodInSlowDown");//2号炒锅出餐倒料到减速位 ActionManage.GetInstance.Register(Robot_Pot2OutFood, "Robot_Pot2OutFood");//2号炒锅出餐倒料完成 ActionManage.GetInstance.Register(RobotActionStart, "Robot_Pot2OutFood");//2号炒锅出餐倒料完成 #endregion } public override void MainTask() { } private void FirePot1_Process() { } private void FirePot2_Process() { } public override void ReadData() { GetStatus("M20.0",new Action((o)=> { if (o == null) return; if(o is bool[] values&&values.Length == 19) { morkBF.FirePot1_InitCompleted = values[0]; morkBF.FirePot1_IsAuto = values[1]; morkBF.FirePot1_Emergencystop = values[2]; morkBF.FirePot1_MealTubExist = values[3]; morkBF.FirePot1_VegetablesTub1Exist = values[4]; morkBF.FirePot1_VegetablesTub2Exist = values[5]; morkBF.FirePot1_Seasoning1Exist = values[6]; morkBF.FirePot1_Seasoning2Exist = values[7]; morkBF.FirePot1_Accessories1Exist = values[8]; morkBF.FirePot1_Accessories2Exist = values[9]; morkBF.FirePot1_OutFoodTubExist = values[10]; morkBF.FirePot1_OnOrigin = values[11]; morkBF.FirePot1_FirePosition1 = values[12]; morkBF.FirePot1_FirePosition2 = values[13]; morkBF.FirePot1_FirePosition3 = values[14]; morkBF.FirePot1_FirePosition4 = values[15]; morkBF.FirePot1_PotOnOutFoodPosition = values[16]; morkBF.FirePot1_PotOnIntoFoodPosition = values[17]; morkBF.FirePot1_PotOnCleanPosition = values[18]; } }),0); GetStatus("VW120", new Action((o) => { if (o == null) return; if (o is int[] values&&values.Length == 2) { morkBF.FirePot1_Temperature = values[0]; morkBF.FirePot1_Pulse = values[1]; } }), 0); GetStatus("M25.0", new Action((o) => { if (o == null) return; if (o is bool[] values&& values.Length == 19) { morkBF.FirePot2_InitCompleted = values[0]; morkBF.FirePot2_IsAuto = values[1]; morkBF.FirePot2_Emergencystop = values[2]; morkBF.FirePot2_MealTubExist = values[3]; morkBF.FirePot2_VegetablesTub1Exist = values[4]; morkBF.FirePot2_VegetablesTub2Exist = values[5]; morkBF.FirePot2_Seasoning1Exist = values[6]; morkBF.FirePot2_Seasoning2Exist = values[7]; morkBF.FirePot2_Accessories1Exist = values[8]; morkBF.FirePot2_Accessories2Exist = values[9]; morkBF.FirePot2_OutFoodTubExist = values[10]; morkBF.FirePot2_OnOrigin = values[11]; morkBF.FirePot2_FirePosition1 = values[12]; morkBF.FirePot2_FirePosition2 = values[13]; morkBF.FirePot2_FirePosition3 = values[14]; morkBF.FirePot2_FirePosition4 = values[15]; morkBF.FirePot2_PotOnOutFoodPosition = values[16]; morkBF.FirePot2_PotOnIntoFoodPosition = values[17]; morkBF.FirePot2_PotOnCleanPosition = values[18]; } }), 0); GetStatus("VW150", new Action((o) => { if (o == null) return; if (o is int[] values&& values.Length == 2) { morkBF.FirePot2_Temperature = values[0]; morkBF.FirePot2_Pulse = values[1]; } }), 0); GetStatus("GM500", new Action((o) => { if (o == null) return; if (o is bool[] values && values.Length == 7) { morkBF.Robot_FirePot1OutMeal = values[0]; morkBF.Robot_FirePot1OutVegetables1 = values[1]; morkBF.Robot_FirePot1OutVegetables2 = values[2]; morkBF.Robot_FirePot1OutSeasoning = values[3]; morkBF.Robot_FirePot1OutAccessories = values[4]; morkBF.Robot_ArriveFirePot1 = values[5]; morkBF.Robot_FirePot1OutFoodComplete = values[6]; } }), 1); GetStatus("GM510", new Action((o) => { if (o == null) return; if (o is bool[] values && values.Length == 7) { morkBF.Robot_FirePot2OutMeal = values[0]; morkBF.Robot_FirePot2OutVegetables1 = values[1]; morkBF.Robot_FirePot2OutVegetables2 = values[2]; morkBF.Robot_FirePot2OutSeasoning = values[3]; morkBF.Robot_FirePot2OutAccessories = values[4]; morkBF.Robot_ArriveFirePot2 = values[5]; morkBF.Robot_FirePot2OutFoodComplete = values[6]; } }), 1); GetStatus("GI5", new Action((o) => { if (o == null) return; if (o is int[] values && values.Length == 1) { morkBF.Robot_ActionCallback = values[0]; } }), 1); } public override void ResetProgram() { morkBF = null; morkBF = new GVL_MorkBF(); } public override void SimOrder() { } public override void Stop() { } /// /// 获取炒锅PLC的所有状态 /// /// /// /// 炒锅编号 private void GetStatus(string key, Action action, int num) { if (dicPort2peripheralStatus.ContainsKey(num)) { if (dicPort2peripheralStatus[num].ContainsKey(key)) { action((object)dicPort2peripheralStatus[num][key]);//获取PLC指定地址的状态值 } } } #region 控制 private void FirePot_Write(string address, object value, int i = 0) { WriteControlExact(address, value, i); } private void Robot_Write(string address, object value, int i = 1) { WriteControlExact(address, value, i); } #region 炒锅1 /// /// 炒锅1设定加热挡位 /// /// private void FirePot1_SetFireGear(object o) { if (o == null) return; if (o is int value) { FirePot_Write("VW100", value); } } /// /// 炒锅1加热启停 /// /// private void FirePot1_StartFire(object o) { if (o == null) return; if (o is bool value) { FirePot_Write("M10.0", value); } } /// /// 炒锅1设置搅拌挡位 /// /// private void FirePot1_SetStirGear(object o) { if (o == null) return; if (o is int value) { FirePot_Write("VW102", value); } } /// /// 炒锅1搅拌启停 /// /// private void FirePot1_StartStir(object o) { if (o == null) return; if (o is bool value) { FirePot_Write("M10.1", value); } } /// /// 设置炒锅1翻转速度 /// /// private void FirePot1_SetTurnSpeed(object o) { if (o == null) return; if (o is int value) { FirePot_Write("VW104", value); } } #endregion #region 炒锅2 /// /// 炒锅2设定加热挡位 /// /// private void FirePot2_SetFireGear(object o) { if (o == null) return; if (o is int value) { FirePot_Write("VW130", value); } } /// /// 炒锅2加热启停 /// /// private void FirePot2_StartFire(object o) { if (o == null) return; if (o is bool value) { FirePot_Write("M15.0", value); } } /// /// 炒锅2设置搅拌挡位 /// /// private void FirePot2_SetStirGear(object o) { if (o == null) return; if (o is int value) { FirePot_Write("VW132", value); } } /// /// 炒锅2搅拌启停 /// /// private void FirePot2_StartStir(object o) { if (o == null) return; if (o is bool value) { FirePot_Write("M15.1", value); } } /// /// 设置炒锅2翻转速度 /// /// private void FirePot2_SetTurnSpeed(object o) { if (o == null) return; if (o is int value) { FirePot_Write("VW134", value); } } #endregion #region 炒锅通用 /// /// 炒锅复位 /// /// private void FirePot_Reset(object o) { if (o == null) return; if (o is int i) { if (i == 1) { } else if (i == 2) { } } } /// /// 炒锅回原点 /// /// private void FirePot_PotGotoOrigin(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M10.5", true); } else if (i == 2) { FirePot_Write("M15.5", true); } } } /// /// 炒锅去位置1 /// /// private void FirePot_PotGotoP1(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M11.2", true); } else if (i == 2) { FirePot_Write("M16.2", true); } } } /// /// 炒锅去位置2 /// /// private void FirePot_PotGotoP2(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M11.3", true); } else if (i == 2) { FirePot_Write("M16.3", true); } } } /// /// 炒锅去位置3 /// /// private void FirePot_PotGotoP3(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M11.4", true); } else if (i == 2) { FirePot_Write("M16.4", true); } } } /// /// 炒锅去位置4 /// /// private void FirePot_PotGotoP4(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M11.5", true); } else if (i == 2) { FirePot_Write("M16.5", true); } } } /// /// 炒锅去出餐位置 /// /// private void FirePot_PotGotoOutFoodPositiong(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M11.6", true); } else if (i == 2) { FirePot_Write("M16.6", true); } } } /// /// 炒锅去投料位置 /// /// private void FirePot_PotGotoInFoodPosition(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M11.7", true); } else if (i == 2) { FirePot_Write("M16.7", true); } } } /// /// 出餐启动 /// /// private void FirePot_StartOutFood(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M10.6", true); } else if (i == 2) { FirePot_Write("M15.6", true); } } } /// /// 清洗 /// /// private void FirePot_Clean(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M10.7", true); } else if (i == 2) { FirePot_Write("M15.7", true); } } } /// /// 抽水启动 /// /// private void FirePot_StartPumpWater(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M11.0", true); } else if (i == 2) { FirePot_Write("M16.0", true); } } } /// /// 抽油启动 /// /// private void FirePot_StartPumpOil(object o) { if (o == null) return; if (o is int i) { if (i == 1) { FirePot_Write("M16.0", true); } else if (i == 2) { FirePot_Write("M16.1", true); } } } #endregion #region 机器人 /// /// 机器人启动 /// private void RobotStart() { Robot_Write("GM600",true); } /// /// 机器人停止 /// private void RobotStop() { Robot_Write("GM601", true); } /// /// 机器人复位 /// private void RobotReset() { Robot_Write("GM602", true); } /// /// 机器人程序重启 /// private void RobotProgramStart() { Robot_Write("GM603", true); } /// /// 1号炒锅允许机器人投料(炒锅在投料位给出) /// private void Robot_Pot1AllowInMaterail() { Robot_Write("GM520", true); } /// /// 1号炒锅出餐倒料到减速位 /// private void Robot_Pot1OutFoodInSlowDown() { Robot_Write("GM621", true); } /// /// 1号炒锅出餐倒料完成 /// private void Robot_Pot1OutFood() { Robot_Write("GM522", true); } /// /// 2号炒锅允许机器人投料(炒锅在投料位给出) /// private void Robot_Pot2AllowInMaterail() { Robot_Write("GM530", true); } /// /// 2号炒锅出餐倒料到减速位。开始倒菜 /// private void Robot_Pot2OutFoodInSlowDown() { Robot_Write("GM531", true); } /// /// 2号炒锅出餐倒料完成 /// private void Robot_Pot2OutFood() { Robot_Write("GM532", true); } /// /// /// private void RobotActionStart(object o) { if (o == null) return; if(o is int value) { Robot_Write("GI0",value); } } #endregion #endregion private void ScreenDataServer() { LocalMqtt.GetInstance.Init(ScreenDeviceType.大炒); ThreadManage.GetInstance().StartLong(new Action(() => { List statsModels = new List(); statsModels.Add(new StatsModel() { Name = "帝王蟹", Count = 666 }); ScreenModelMaxWok maxWok = new ScreenModelMaxWok { IsRun = new Random().Next(0, 2) == 0 ? IsRun.运行 : IsRun.停止, WorkStatus_1 = (WorkStatus)new Random().Next(0, 3), WorkStatus_2 = (WorkStatus)new Random().Next(0, 3), RobotStatu = (WorkStatus)new Random().Next(0, 3), Alarm = new List(), FailuresCount = 0, StatsCount = statsModels, MaxWok_Dishes_1 = "满汉全席", MaxWok_Dishes_2 = "海鲜大餐", MaxWok_Task_1 = "炒制菜品", MaxWok_Task_2 = "热油", MaxWok_Process_1 = new List(), MaxWok_HeatGear_1 = new Random().Next(0, 5).ToString(), MaxWok_HeatGear_2 = new Random().Next(0, 5).ToString(), MaxWok_StirGear_1 = new Random().Next(0, 5).ToString(), MaxWok_StirGear_2 = new Random().Next(0, 5).ToString(), MaxWok_FlipSpeed_1 = new Random().Next(250, 450).ToString(), MaxWok_FlipSpeed_2 = new Random().Next(250, 450).ToString(), MaxWok_Temp_1 = new Random().Next(250, 450).ToString(), MaxWok_Temp_2 = new Random().Next(250, 450).ToString(), MaxWok_OrderCount_1 = 2, MaxWok_OrderCount_2 = 2, MaxWok_ErrorOrderCount_1 = 0, MaxWok_ErrorOrderCount_2 = 0, }; LocalMqtt.GetInstance.Publish(maxWok); Thread.Sleep(1000); }), "大屏数据上报"); } } }