/// <summary> /// Todo tray change /// </summary> /// <returns></returns> public async Task <WaitBlock> WorkAsync() { return(await Task.Run(async() => { string log = string.Empty; try { //Task<WaitBlock>[] blocks; if (_currentCycleId == 0) { _currentCycleId = 1; } //if (VLoadStation.GetInsideOpticalSensor()==false) //{ // VLoadStation.LoadATray(); //} //if (VUnloadStation.GetInsideOpticalSensor() == false) //{ // VUnloadStation.LoadATray(); //} //if (LLoadStation.GetInsideOpticalSensor()==false) //{ // LLoadStation.LoadATray(); //} do { //WorkTable.Fixtures[(int)FixtureId.V].IsEmpty = false; //WorkTable.Fixtures[(int)FixtureId.V].NG = false; log = string.Empty; //Stop production. if (VRobot.StopProduction) { bool allEmpty = true; foreach (var fixture in WorkTable.Fixtures) { if (fixture.IsEmpty == false) { allEmpty = false; } } if (allEmpty) { break; } } //if (VRobot.LoadTray.CurrentPart.XIndex > VRobot.LoadTray.ColumneCount) //{ // VLoadTrayEmptyManualResetEvent.Reset(); // VLoadTrayEmptyManualResetEvent.WaitOne(); //} //blocks = new Task<WaitBlock>[2]; //blocks[0] = VRobot.WorkAsync(); //blocks[1] = LRobot.WorkAsync(); //blocks[2] = UVLight.WorkAsync(); //blocks[0] = VRobot.WorkAsync(); //blocks[0] = LRobot.WorkAsync(); //blocks[1] = UVLight.WorkAsync(); //await blocks[0]; //await blocks[1]; //Task.WaitAll(blocks); //CheckTaskResults(blocks); //Helper.CheckTaskResult(blocks[1]); var vTask = VRobot.WorkAsync(_currentCycleId); var gpTask = GluePointRobot.WorkAsync(_currentCycleId); var glTask = GlueLineRobot.WorkAsync(_currentCycleId); var lTask = LRobot.WorkAsync(_currentCycleId); var uVTask = UVLight.WorkAsync(_currentCycleId); await vTask; await gpTask; await glTask; await lTask; await uVTask; log += vTask.Result.Message + Environment.NewLine; log += gpTask.Result.Message + Environment.NewLine; log += glTask.Result.Message + Environment.NewLine; log += lTask.Result.Message + Environment.NewLine; Helper.CheckTaskResult(vTask); Helper.CheckTaskResult(gpTask); Helper.CheckTaskResult(glTask); Helper.CheckTaskResult(lTask); Helper.CheckTaskResult(uVTask); var tableTask = WorkTable.TurnsAsync(); await tableTask; Helper.CheckTaskResult(tableTask); _currentCycleId++; } while (KeepThisShitRunning); return new WaitBlock() { Message = "Production stopped." }; } catch (Exception ex) { return new WaitBlock() { Code = ErrorCode.ProductionFail, Message = "Production interruptted due to: " + ex.Message + " " + log, }; } })); }
public void Setup() { LaserSensorGlueLine = new LaserSensor("COM4", 9600, 2); LaserSensorGluePoint = new LaserSensor("COM3", 9600, 1); PressureSensorGlueLine = new PressureSensor("COM6", 9600, 2); PressureSensorGluePoint = new PressureSensor("COM5", 9600, 1); LaserSensorGluePoint.Start(); LaserSensorGlueLine.Start(); PressureSensorGluePoint.Start(); PressureSensorGlueLine.Start(); Mc = new MotionController(); Mc.Connect(); Mc.Setup(); Mc.ZeroAllPositions(); Vision = new VisionServer(Mc); WorkTable = new RoundTable(Mc); WorkTable.Setup(); UVLight = new UVLight(Mc, WorkTable); LoadCapturePositions(); LoadUserOffsets(); LoadDevelopPoints(); LoadGlueParameters(); LoadUserSettings(); SettingManager = new SettingManager(this); LRobot = new LStation(Mc, Vision, WorkTable, CapturePositions, UserOffsets); LRobot.Setup(); VLoadStation = new VLoadTrayStation(Mc); VLoadStation.Setup(); VUnloadStation = new VUnloadTrayStation(Mc); VUnloadStation.Setup(); LLoadStation = new LLoadTrayStation(Mc); LLoadStation.Setup(); LUnloadStation = new LUnloadTrayStation(Mc); LUnloadStation.Setup(); VRobot = new VStation(Mc, Vision, WorkTable, VLoadStation, VUnloadStation, CapturePositions, UserOffsets); VRobot.Setup(); GlueLineRobot = new GlueLineStation(Mc, Vision, WorkTable, CoordinateId.GlueLine, GlueParameters, CapturePositions, UserOffsets, PressureSensorGlueLine, LaserSensorGlueLine); GlueLineRobot.Setup(); GluePointRobot = new GluePointStation(Mc, Vision, WorkTable, CoordinateId.GluePoint, GlueParameters, CapturePositions, UserOffsets, PressureSensorGluePoint, LaserSensorGluePoint); GluePointRobot.Setup(); VRobot.CheckVacuumValue = _checkVacuum; LRobot.CheckVacuumValue = _checkVacuum; }