private TargetPosition ConvertShieldBoxToTargetPosition(ShieldBox shieldBox) { switch (shieldBox.Id) { case 1: return(Motion.ShieldBox1); case 2: return(Motion.ShieldBox2); case 3: return(Motion.ShieldBox3); case 4: return(Motion.ShieldBox4); case 5: return(Motion.ShieldBox5); case 6: return(Motion.ShieldBox6); default: throw new Exception("Shield box Id out of range exception."); } }
//public void UnloadAndLoad(TargetPosition target, RackGripper gripper) //{ // CheckGripperAvailable(gripper); // MoveToTargetPosition(gripper, target); // CloseGripper(gripper); // MoveToPointTillEnd(Motion.MotorZ, target.ApproachHeight); //Up. // ChangeGripper(target, ref gripper); //Switch gripper. // MoveToPointTillEnd(Motion.MotorZ, target.ZPos); //Down. // OpenGripper(gripper); // MoveToPointTillEnd(Motion.MotorZ, target.ApproachHeight); //Up. // YRetractFromBox(); //} public void UnloadAndLoad(ShieldBox box, RackGripper gripper, bool closeBox) { OnInfoOccured(20025, "Try unload and load box: " + box.Id + " with " + gripper + "."); CheckGripperAvailable(gripper); if (box.IsClosed() == true) { throw new Exception("Box " + box.Id + " is not opened."); } MoveToTargetPosition(gripper, box.Position, false); CloseGripper(gripper); Motion.ToPoint(Motion.MotorZ, box.Position.ZPos + 50); Motion.WaitTillZBiggerThan(box.Position.ZPos + 30); ChangeGripper(box.Position, ref gripper); //Switch gripper. Motion.WaitTillEnd(Motion.MotorZ); CheckPhoneLost(gripper); //Slip in phone. Task.Run(() => { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (stopwatch.ElapsedMilliseconds < 5000) { if (Motion.GetPosition(Motion.MotorZ) < box.Position.ZPos + SlipInHeight) { try { OpenGripper(gripper); } catch (Exception) { break; } } Delay(5); } }); MoveToPointTillEnd(Motion.MotorZ, box.Position.ZPos); //Down. OpenGripper(gripper); MoveToPointTillEnd(Motion.MotorZ, box.Position.ApproachHeight); //Up. if (closeBox) { CloseBoxAsync(box); } YRetractFromBox(); OnInfoOccured(20025, "Finish unload and load box: " + box.Id + " with " + gripper + "."); }
private void ShieldBoxSetup() { if (_shieldBoxInstanced == false) { ShieldBox1 = new ShieldBox(1); ShieldBox2 = new ShieldBox(2); ShieldBox3 = new ShieldBox(3); ShieldBox4 = new ShieldBox(4); ShieldBox5 = new ShieldBox(5); ShieldBox6 = new ShieldBox(6); ShieldBox1.Position = Motion.ShieldBox1; ShieldBox2.Position = Motion.ShieldBox2; ShieldBox3.Position = Motion.ShieldBox3; ShieldBox4.Position = Motion.ShieldBox4; ShieldBox5.Position = Motion.ShieldBox5; ShieldBox6.Position = Motion.ShieldBox6; ShieldBoxs = new ShieldBox[6] { ShieldBox1, ShieldBox2, ShieldBox3, ShieldBox4, ShieldBox5, ShieldBox6 }; _shieldBoxInstanced = true; } foreach (var box in ShieldBoxs) { box.PortName = XmlReaderWriter.GetBoxAttribute(Files.BoxData, box.Id, ShieldBoxItem.COM); box.Enabled = XmlReaderWriter.GetBoxAttribute(Files.BoxData, box.Id, ShieldBoxItem.State) == "Enable"; if (!Enum.TryParse(XmlReaderWriter.GetBoxAttribute(Files.BoxData, box.Id, ShieldBoxItem.Type), out ShieldBoxType type)) { throw new Exception("ShieldBoxSetup fail due to box type convert failure"); } box.Type = type; if (box.Enabled) { try { box.Start(); box.GreenLight(); box.ErrorOccured -= Box_ErrorOccured; box.ErrorOccured += Box_ErrorOccured; } catch (Exception e) { throw new Exception("Box " + box.Id + " is enabled but can't communicate: " + e.Message); } } } }
public Task CloseBoxAsync(ShieldBox box) { return(Task.Run(() => { try { box.CloseBox(); } catch (Exception e) { //OnErrorOccured(40008, "Can't close box due to:" + e.Message); } })); }
public void Unload(RackGripper gripper, TargetPosition target) { ShieldBox box = ConverterTeachPosToShieldBox(target.TeachPos); if (box != null) { if (box.IsClosed()) { throw new Exception("Cant unload, box is not opened."); } } CheckGripperAvailable(gripper); MoveToTargetPosition(gripper, target, false); CloseGripper(gripper); MoveToPointTillEnd(Motion.MotorZ, target.ApproachHeight); YRetractFromBox(); }
public void Load(RackGripper gripper, ShieldBox box, bool closeBox) { OnInfoOccured(20023, "Try loading phone to box:" + box.Id + " with " + gripper + "."); TargetPosition target = ConvertShieldBoxToTargetPosition(box); if (box.IsClosed() == true) { throw new Exception("Box " + box.Id + " is not opened"); } MoveToTargetPosition(gripper, target, true); OpenGripper(gripper); MoveToPointTillEnd(Motion.MotorZ, target.ApproachHeight); if (closeBox) { CloseBoxAsync(box); } YRetractFromBox(); OnInfoOccured(20023, "Finish loading phone to box:" + box.Id + "."); }
/// <summary> /// From current target position. /// </summary> /// <param name="gripper"></param> /// <param name="phone"></param> public void Unload(RackGripper gripper, Phone phone) { OnInfoOccured(20018, "Try unloading phone:" + phone.Id + " with " + gripper + "."); ShieldBox box = ConverterTeachPosToShieldBox(phone.CurrentTargetPosition.TeachPos); if (box != null) { if (box.IsClosed()) { throw new Exception("Cant unload, box is not opened."); } } TargetPosition pos = phone.CurrentTargetPosition; MoveToTargetPosition(gripper, pos, false); CloseGripper(gripper); MoveToPointTillEnd(Motion.MotorZ, pos.ApproachHeight); YRetractFromBox(); CheckPhoneLost(gripper); OnInfoOccured(20018, "Finish unloading phone:" + phone.Id); }
/// <summary> /// /// </summary> /// If message is not complete use: _receivedMessage += message; /// if message is too long and wrong, empty _receivedMessage /// <param name="message"></param> private void MessageParser(string message) { Task.Run(() => { if (message.Contains(";") == false) { OnErrorOccured(40003, "Receive unknown message " + message); return; } int index = message.IndexOf(";", StringComparison.Ordinal); if (index + 1 != message.Length) { OnErrorOccured(40003, "Receive unknown message " + message); return; } message = message.Replace(";", string.Empty); string[] subMessage = message.Split(','); //Todo, is message is not continue, could lost some information. Enum.TryParse(subMessage[0], out TesterCommand command); switch (command) { case TesterCommand.GetRobotState: OnInfoOccured(20001, "Tester " + Id + " requesting Robot state."); SendMessage(TesterCommand.GetRobotState + "," + RobotState + ";"); OnInfoOccured(20001, "Rack response Robot state to Tester " + Id + "."); break; case TesterCommand.GetShieldedBoxState: OnInfoOccured(20002, "Tester " + Id + " requesting shieldedBox State."); int state = 0; if (ShieldBox.ReadyForTesting) { state = (int)ShieldBoxState.Close; } else { state = (int)ShieldBoxState.Open; } if (SimulateMode) { SendMessage(TesterCommand.GetShieldedBoxState + ",2;"); } else { SendMessage(TesterCommand.GetShieldedBoxState + "," + state + ";"); } OnInfoOccured(20002, "Send shieldedBox state to Tester " + Id + "."); break; case TesterCommand.SetTestResult: OnInfoOccured(20003, "Tester " + Id + " send test result: " + subMessage[1] + "."); if (ShieldBox.Phone != null) { ShieldBox.Phone.TestCycleTimeStopWatch.Stop(); } try { SendMessage(TesterCommand.SetTestResult + ",OK;"); OnInfoOccured(20003, "Rack response send test result to Tester " + Id + "."); if (ShieldBox.Phone.AutoOpenBox) { ShieldBox.OpenBox(); } switch (subMessage[1]) { case "0": ShieldBox.Phone.TestResult = TestResult.Pass; break; case "1": ShieldBox.Phone.FailDetail = "Normal_NG"; ShieldBox.Phone.TestResult = TestResult.Fail; ShieldBox.Phone.FailCount++; break; case "2": //Battery low. NG. ShieldBox.Phone.FailDetail = "Low_Battery"; ShieldBox.Phone.TestResult = TestResult.Fail; ShieldBox.Phone.FailCount = 3; break; case "3": //Procedure not match. ShieldBox.Phone.FailDetail = "Procedure_wrong"; ShieldBox.Phone.TestResult = TestResult.Fail; ShieldBox.Phone.FailCount = 3; break; case "4": //Timeout match. ShieldBox.Phone.FailDetail = "Test_timeout"; ShieldBox.Phone.TestResult = TestResult.Fail; ShieldBox.Phone.FailCount = 3; break; default: break; } } catch (BoxException) { OnErrorOccured((int)Error.OpenBoxFail, "Open box failed."); } catch (Exception ex) { OnErrorOccured(40002, "SetTestResult error: " + ex.Message); } break; case TesterCommand.GetSerialNumber: OnInfoOccured(20028, "Tester " + Id + " requesting Serial Number."); if (SimulateMode) { SendMessage(TesterCommand.GetSerialNumber + "," + SimulateSerialNumber + ";"); } else { SendMessage(TesterCommand.GetSerialNumber + "," + ShieldBox.Phone.SerialNumber + ";"); } OnInfoOccured(20028, "Send Serial Number:" + ShieldBox.Phone.SerialNumber + " to Tester " + Id + "."); break; default: OnErrorOccured(40003, "Receive unknown message " + message); break; } }); }