public bool JobTask(ref bool isrun, bool isSideA, Queue <RollPosition> robotRollQ, RollPosition roll, ListView lv) { // 等待板可放料 FrmMain.logOpt.Write($"{roll.RealLocation}等待可放料信号。", LogType.ROBOT_STACK); if (!PanelAvailable(roll.RealLocation)) { FrmMain.logOpt.Write($"!{roll.RealLocation}未收到可放料信号,请检查板状态和是否有形状不规则报警。", LogType.ROBOT_STACK); return(false); } else { FrmMain.logOpt.Write($"{roll.RealLocation}收到可放料信号。", LogType.ROBOT_STACK); } // 机器人正忙,等待。 while (isrun) { if (TryIsBusy()) { onerror?.Invoke(true, "机器人忙"); FrmMain.logOpt.Write($"!机器人正忙", LogType.ROBOT_STACK); Thread.Sleep(OPCClient.DELAY * 10); } else { break; } } onerror?.Invoke(true, "机器人准备好"); var writeok = TryWritePositionPro(roll); if (!writeok) { onerror?.Invoke(false, $"发坐标失败"); log($"!{roll.LabelCode}发送坐标失败。", LogType.ROBOT_STACK); return(false); } if (TryRunJob(JOB_NAME)) { onerror?.Invoke(true, $"{JOB_NAME}动作发送完成"); log($"发出机器人示教器动作{JOB_NAME}命令成功, {roll.LabelCode}", LogType.ROBOT_STACK); lock (client) { client.TryWrite(param.RobotParam.RobotJobStart, true); } } else { onerror?.Invoke(false, "动作发送失败"); log($"!机器人示教器动作{JOB_NAME}发送失败, {roll.LabelCode}", LogType.ROBOT_STACK); return(false); } Thread.Sleep(RobotHelper.DELAY * 100); // 500ms. while (isrun) { var side = isSideA ? "A" : "B"; onerror?.Invoke(true, $"等待抓料信号({side}) "); var leaving = false; lock (client) { leaving = isSideA ? param.RobotParam.PlcSnA.ReadSN(client) : param.RobotParam.PlcSnB.ReadSN(client); } if (!leaving) { onerror?.Invoke(true, $"等待抓料信号({side})..."); } if (leaving) { onerror?.Invoke(true, $"{roll.LabelCode}抓起"); log($"布卷抓起: {roll.brief()}.", LogType.ROBOT_STACK); DequeueRoll(robotRollQ, roll, lv); // 出队列 LableCode.SetOnPanelState(roll.LabelCode); // 写数据库。 var sideslot = isSideA ? param.RobotParam.RobotStartA : param.RobotParam.RobotStartB; lock (client) { client.TryWrite(sideslot, false); if (isSideA) { param.RobotParam.PlcSnA.WriteSN(client); } else { param.RobotParam.PlcSnB.WriteSN(client); } } break; } Thread.Sleep(RobotHelper.DELAY * 200); // 1000ms. } // 等待布卷上垛信号 while (isrun) { if (TryIsRollOnPanel()) { NotifyOpcJobFinished(roll); // 告知OPC onerror?.Invoke(true, $"{roll.LabelCode}上垛"); log($"收到布卷{roll.LabelCode}上垛信号,布卷已上垛,实际交地:{roll.RealLocation}。", LogType.ROBOT_STACK); break; } Thread.Sleep(RobotHelper.DELAY * 20); } Thread.Sleep(RobotHelper.DELAY * 400); return(true); }
public bool JobTask(ref bool isrun, bool isSideA, Queue <RollPosition> robotRollQ, RollPosition roll, ListView lv) { // 等待板可放料 if (!PanelAvailable(roll.RealLocation)) { FrmMain.logOpt.Write($"!{roll.RealLocation}未收到可放料信号,请检查板状态和是否有形状不规则报警。", LogType.ROBOT_STACK); return(false); } // 机器人正忙,等待。 while (isrun) { if (IsBusy()) { FrmMain.logOpt.Write($"!机器人正忙", LogType.ROBOT_STACK); #if DEBUG Thread.Sleep(FakeOpcClient.DELAY * 10); #endif } else { break; } } if (!TryWritePositionPro(roll)) { return(false); } if (TryRunJob(JOB_NAME)) { log($"发出机器人示教器动作{JOB_NAME}命令成功。", LogType.ROBOT_STACK); client.TryWrite(param.RobotParam.RobotJobStart, true); } else { log($"!机器人示教器动作{JOB_NAME}发送失败。", LogType.ROBOT_STACK); return(false); } Thread.Sleep(RobotHelper.DELAY * 200); //删除对列布卷 while (isrun) { var leaving = client.TryReadBool(isSideA ? param.RobotParam.RobotStartA : param.RobotParam.RobotStartB); if (leaving) { log($"roll is leaving: {roll.LabelCode}.", LogType.ROBOT_STACK, LogViewType.OnlyFile); DequeueRoll(robotRollQ, roll, lv); client.TryWrite(isSideA ? param.RobotParam.RobotStartA : param.RobotParam.RobotStartB, false); break; } Thread.Sleep(RobotHelper.DELAY); } // 等待布卷上垛信号 while (isrun) { if (IsRollOnPanel()) { // 写数据库。 LableCode.SetOnPanelState(roll.LabelCode); // 告知OPC NotifyOpcJobFinished(roll); log("布卷已上垛。", LogType.ROBOT_STACK, LogViewType.Both); break; } Thread.Sleep(RobotHelper.DELAY * 20); } // 等待机器人结束码垛。 while (isrun && IsBusy()) { Thread.Sleep(RobotHelper.DELAY * 20); } DequeueRoll(robotRollQ, roll, lv); if (!isrun) //解决压布,布卷未上垛问题 // 写数据库。 { LableCode.SetOnPanelState(roll.LabelCode); // 告知OPC NotifyOpcJobFinished(roll); log($"{roll.LabelCode}布卷已上垛。", LogType.ROBOT_STACK, LogViewType.Both); } log($"robot job done: {roll.LabelCode}.", LogType.ROBOT_STACK); return(true); }