| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 | 
							- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Device.Unit;
 
- using Aitex.Core.RT.Event;
 
- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Sorter.Common;
 
- using MECF.Framework.Common.Device.Bases;
 
- using MECF.Framework.Common.Equipment;
 
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using FurnaceRT.Equipments.Systems;
 
- using static Aitex.Core.RT.Device.Unit.IoAutoShutter;
 
- using FurnaceRT.Devices;
 
- using static Aitex.Core.RT.Device.Unit.IoBoat;
 
- namespace FurnaceRT.Equipments.Boats
 
- {
 
-     public class BoatHome : ModuleRoutine, IRoutine
 
-     {
 
-         enum RoutineStep
 
-         {
 
-             AutoShutterOpen,
 
-             AutoShutterClose,
 
-             CheckPrepareMove,
 
-             SetReset,
 
-             SetServoOn,
 
-             BoatZAxisHome,
 
-             BoatRAxisHome,
 
-             Delay1,
 
-             SetBoatRAxisMoveStop,
 
-         }
 
-         private BoatModule _boatModule;
 
-         private int _timeout = 0;
 
-         private int _shutterTimeout = 0;
 
-         public BoatHome(BoatModule boatModule)
 
-         {
 
-             _boatModule = boatModule;
 
-             Module = boatModule.Module;
 
-             Name = "Boat Home";
 
-         }
 
-         public Result Start(params object[] objs)
 
-         {
 
-             Reset();
 
-             _timeout = SC.GetValue<int>($"{Module}.MotionTimeout");
 
-             _shutterTimeout = SC.GetValue<int>($"{Module}.AutoShutter.MotionTimeout");
 
-             _boatModule.AutoShutterMoveFailedForInterlock.RetryMessage = (int)BoatModule.MSG.Home;
 
-             _boatModule.AutoShutterOpenTimeOut.RetryMessage = (int)BoatModule.MSG.Home;
 
-             _boatModule.AutoShutterCloseTimeOut.RetryMessage = (int)BoatModule.MSG.Home;
 
-             _boatModule.BoatZAxisHomeFailed.RetryMessage = (int)BoatModule.MSG.Home;
 
-             _boatModule.BoatZAxisHomeTimeout.RetryMessage = (int)BoatModule.MSG.Home;
 
-             _boatModule.BoatRAxisHomeFailed.RetryMessage = (int)BoatModule.MSG.Home;
 
-             _boatModule.BoatRAxisHomeTimeout.RetryMessage = (int)BoatModule.MSG.Home;
 
-             Notify($"Start");
 
-             return Result.RUN;
 
-         }
 
-         public void Abort()
 
-         {
 
-             _boatModule.BoatZAxisStop();
 
-             _boatModule.BoatRAxisStop();
 
-         }
 
-         public override Result Monitor()
 
-         {
 
-             try
 
-             {
 
-                 PauseRountine(_boatModule.RAxisDevice.IsPause);
 
-                 if (_boatModule.RAxisDevice.IsPause)
 
-                     return Result.RUN;
 
-                 AutoShutterOpen((int)RoutineStep.AutoShutterOpen, true, _timeout);
 
-                 CheckPrepareMove((int)RoutineStep.CheckPrepareMove, 2);
 
-                 
 
-                 SetBoatZAxisMove((int)RoutineStep.BoatZAxisHome, BoatPosition.HomePosition, (int)_timeout);
 
-                 SetBoatRAxisMoveStop((int)RoutineStep.SetBoatRAxisMoveStop);
 
-                 Delay((int)RoutineStep.Delay1, 2);
 
-                 SetBoatRAxisHome((int)RoutineStep.BoatRAxisHome, _timeout);
 
-                 AutoShutterOpen((int)RoutineStep.AutoShutterClose, false, _timeout);
 
-             }
 
-             catch (RoutineBreakException)
 
-             {
 
-                 return Result.RUN;
 
-             }
 
-             catch (RoutineFaildException ex)
 
-             {
 
-                 return Result.FAIL;
 
-             }
 
-             Notify("Finished");
 
-             return Result.DONE;
 
-         }
 
-         private void SetBoatRAxisMoveStop(int id)
 
-         {
 
-             Tuple<bool, Result> ret = Execute(id, () =>
 
-             {
 
-                 Notify($"Set RAxis boat stop");
 
-                 _boatModule.RAxisDevice.ServoStop();
 
-                 return true;
 
-             });
 
-             if (ret.Item1)
 
-             {
 
-                 if (ret.Item2 == Result.FAIL)
 
-                 {
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else
 
-                     throw (new RoutineBreakException());
 
-             }
 
-         }
 
-         private void SetBoatRAxisHome(int id, int timeout)
 
-         {
 
-             Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-             {
 
-                 Notify($"Boat RAxis home");
 
-                 if (!_boatModule.RAxisDevice.SetServoHome())
 
-                 {
 
-                     _boatModule.BoatRAxisHomeFailed.Set();
 
-                 }
 
-                 return true;
 
-             }, () =>
 
-             {
 
-                 if (_boatModule.RAxisDevice.IsError)
 
-                     return null;
 
-                 return _boatModule.RAxisDevice.IsHomeDone && _boatModule.RAxisDevice.IsReady;
 
-             }, timeout * 1000);
 
-             if (ret.Item1)
 
-             {
 
-                 if (ret.Item2 == Result.FAIL)
 
-                 {
 
-                     _boatModule.RAxisDevice.ServoStop();
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-                 {
 
-                     _boatModule.RAxisDevice.ServoStop();
 
-                     _boatModule.BoatRAxisHomeTimeout.Set($"can not complete in {timeout} seconds");
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else
 
-                     throw (new RoutineBreakException());
 
-             }
 
-         }
 
-         private void CheckPrepareMove(int id, int timeout)
 
-         {
 
-             var reason = "";
 
-             Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-             {
 
-                 Notify($"Check boat move enable");
 
-                 return true;
 
-             }, () =>
 
-             {
 
-                 return _boatModule.CheckPrepareMove(out reason);
 
-             }, timeout * 2 * 1000);
 
-             if (ret.Item1)
 
-             {
 
-                 if (ret.Item2 == Result.FAIL)
 
-                 {
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-                 {
 
-                     _boatModule.BoatZAxisMoveFailedForInterlock.Set($"{reason} is not OK, can not complete in {timeout} seconds");
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else
 
-                     throw (new RoutineBreakException());
 
-             }
 
-         }
 
-         private void SetBoatZAxisMove(int id, BoatPosition position, int timeout)
 
-         {
 
-             Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-             {
 
-                 Notify($"Boat ZAxis movet to {position}");
 
-                 string reason;
 
-                 if (!_boatModule.ZAxisDevice.SetServoMoveTo(position.ToString(), out reason))
 
-                 {
 
-                     //_boatModule.BoatDevice.BoatRAxisMoveFailedForInterlock.Description = reason;
 
-                     _boatModule.BoatZAxisMoveFailedForInterlock.Set(reason);
 
-                 }
 
-                 return true;
 
-             }, () =>
 
-             {
 
-                 if (_boatModule.ZAxisDevice.IsError)
 
-                     return null;
 
-                 return _boatModule.ZAxisDevice.CheckServoAtPosition(position.ToString());
 
-             }, timeout * 2 * 1000);
 
-             if (ret.Item1)
 
-             {
 
-                 if (ret.Item2 == Result.FAIL)
 
-                 {
 
-                     _boatModule.ZAxisDevice.ServoStop();
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-                 {
 
-                     _boatModule.ZAxisDevice.ServoStop();
 
-                     _boatModule.BoatZAxisMoveTimeOut.Set($"can not complete in {timeout} seconds");
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else
 
-                     throw (new RoutineBreakException());
 
-             }
 
-         }
 
-         private void AutoShutterOpen(int id, bool isOpen, int timeout)
 
-         {
 
-             Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-             {
 
-                 Notify($"shutter {(isOpen ? "open" : "close")}");
 
-                 string reason;
 
-                 if (!_boatModule.ShutterDevice.SetOpen(isOpen, out reason))
 
-                 {
 
-                     _boatModule.ShutterDevice.AutoShutterMoveFailedForInterlock.Set();
 
-                     return false;
 
-                 }
 
-                 return true;
 
-             }, () =>
 
-             {
 
-                 return isOpen ? _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Open : _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Close;
 
-             }, timeout * 1000);
 
-             if (ret.Item1)
 
-             {
 
-                 if (ret.Item2 == Result.FAIL)
 
-                 {
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-                 {
 
-                     if (isOpen)
 
-                     {
 
-                         _boatModule.ShutterDevice.AutoShutterOpenTimeOut.Set($"can not complete in {timeout} seconds");
 
-                     }
 
-                     else
 
-                     {
 
-                         _boatModule.ShutterDevice.AutoShutterCloseTimeOut.Set($"can not complete in {timeout} seconds");
 
-                     }
 
-                     throw (new RoutineFaildException());
 
-                 }
 
-                 else
 
-                     throw (new RoutineBreakException());
 
-             }
 
-         }
 
-         //private void AutoShutterOpen(int id, bool isOpen, int timeout)
 
-         //{
 
-         //    Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-         //    {
 
-         //        Notify($"Auto shutter {(isOpen ? "open" : "close")}");
 
-         //        string reason;
 
-         //        if (!_boatModule.AutoShutterDevice.SetOpen(isOpen, out reason))
 
-         //        {
 
-         //            _boatModule.AutoShutterMoveFailedForInterlock.Set();
 
-         //            return false;
 
-         //        }
 
-         //        return true;
 
-         //    }, () =>
 
-         //    {
 
-         //        return isOpen ? _boatModule.AutoShutterDevice.OpenCloseStatus == ASOpenCloseStatus.Open : _boatModule.AutoShutterDevice.OpenCloseStatus == ASOpenCloseStatus.Close;
 
-         //        //return true;
 
-         //    }, timeout * 1000);
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-         //        {
 
-         //            if (isOpen)
 
-         //            {
 
-         //                //autoShutter.AutoShutterOpenTimeOut.Description = $"can not complete in {timeout} seconds";
 
-         //                _boatModule.AutoShutterOpenTimeOut.Set($"can not complete in {timeout} seconds");
 
-         //            }
 
-         //            else
 
-         //            {
 
-         //                //autoShutter.AutoShutterCloseTimeOut.Description = $"can not complete in {timeout} seconds";
 
-         //                _boatModule.AutoShutterCloseTimeOut.Set($"can not complete in {timeout} seconds");
 
-         //            }
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-         //private void AutoShutterUp(int id, bool isUp, int timeout)
 
-         //{
 
-         //    Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-         //    {
 
-         //        Notify($"Auto shutter {(isUp ? "up" : "down")}");
 
-         //        string reason;
 
-         //        if (!_boatModule.AutoShutterDevice.SetUp(isUp, out reason))
 
-         //        {
 
-         //            _boatModule.AutoShutterMoveFailedForInterlock.Set();
 
-         //            return false;
 
-         //        }
 
-         //        return true;
 
-         //    }, () =>
 
-         //    {
 
-         //        return isUp ? _boatModule.AutoShutterDevice.UpDownStatus == ASUpDownStatus.Up : _boatModule.AutoShutterDevice.UpDownStatus == ASUpDownStatus.Down;
 
-         //        //return true;
 
-         //    }, timeout * 1000);
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-         //        {
 
-         //            if (isUp)
 
-         //            {
 
-         //                //autoShutter.AutoShutterUpTimeOut.Description = $"can not complete in {timeout} seconds";
 
-         //                _boatModule.AutoShutterUpTimeOut.Set($"can not complete in {timeout} seconds");
 
-         //            }
 
-         //            else
 
-         //            {
 
-         //                //autoShutter.AutoShutterDownTimeOut.Description = $"can not complete in {timeout} seconds";
 
-         //                _boatModule.AutoShutterDownTimeOut.Set($"can not complete in {timeout} seconds");
 
-         //            }
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-         //private void SetReset(int id)
 
-         //{
 
-         //    Tuple<bool, Result> ret = Execute(id, () =>
 
-         //    {
 
-         //        Notify($"Set boat reset");
 
-         //        _boatModule.BoatDevice.SetReset();
 
-         //        return true;
 
-         //    });
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-         //private void SetServoOn(int id)
 
-         //{
 
-         //    Tuple<bool, Result> ret = Execute(id, () =>
 
-         //    {
 
-         //        Notify($"Set boat servo on");
 
-         //        _boatModule.BoatDevice.SetServoOn();
 
-         //        return true;
 
-         //    });
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-         //private void SetZAxisBoatSpeed(int id, float speed)
 
-         //{
 
-         //    Tuple<bool, Result> ret = Execute(id, () =>
 
-         //    {
 
-         //        Notify($"Set ZAxis boat speed={speed}");
 
-         //        _boatModule.BoatDevice.SetZAxisSpeed(speed);
 
-         //        return true;
 
-         //    });
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-         //private void BoatZAxisMoveTo(int id, BoatPosition targetPosition, int timeout)
 
-         //{
 
-         //    Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-         //    {
 
-         //        Notify($"Boat ZAxis home");
 
-         //        string reason;
 
-         //        if (!_boatModule.BoatDevice.ZAxisMoveTo(targetPosition, out reason))
 
-         //        {
 
-         //            //_boatModule.BoatDevice.BoatZAxisMoveFailedForInterlock.Description = reason;
 
-         //            _boatModule.BoatDevice.BoatZAxisHomeFailed.Set(reason);
 
-         //            return false;
 
-         //        }
 
-         //        return true;
 
-         //    }, () =>
 
-         //    {
 
-         //        return _boatModule.BoatDevice.BoatCurrentPosition == targetPosition && !_boatModule.BoatDevice.IsZAxisMoving;
 
-         //    }, timeout * 1000);
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-         //        {
 
-         //            //_boatModule.BoatDevice.BoatZAxisMoveTimeOut.Description = $"can not complete in {timeout} seconds";
 
-         //            _boatModule.BoatDevice.BoatZAxisHomeTimeout.Set($"can not complete in {timeout} seconds");
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-         //private void SetBoatRAxisMode(int id, BoatRotationMode rotationMode, int timeout)
 
-         //{
 
-         //    Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-         //    {
 
-         //        Notify($"Boat RAxis home");
 
-         //        if (!_boatModule.BoatDevice.RAxisRotate(rotationMode, out string reason))
 
-         //        {
 
-         //            _boatModule.BoatDevice.BoatRAxisHomeFailed.Set();
 
-         //        }
 
-         //        return true;
 
-         //    }, () =>
 
-         //    {
 
-         //        return _boatModule.BoatDevice.IsRAxisAtHome && !_boatModule.BoatDevice.IsRAxisRotating;
 
-         //    }, timeout * 1000);
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else if (ret.Item2 == Result.TIMEOUT) //timeout
 
-         //        {
 
-         //            //_boatModule.BoatDevice.BoatRAxisHomeTimeout.Description = $"can not complete in {timeout} seconds";
 
-         //            _boatModule.BoatDevice.BoatRAxisHomeTimeout.Set($"can not complete in {timeout} seconds");
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-         //private void SetBoatRAxisSpeed(int id, float speed)
 
-         //{
 
-         //    Tuple<bool, Result> ret = Execute(id, () =>
 
-         //    {
 
-         //        Notify($"Set RAxis boat speed={speed}");
 
-         //        _boatModule.SetRAxisSpeed(speed);
 
-         //        return true;
 
-         //    });
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-         //private void SetBoatRAxisInterval(int id, float interval)
 
-         //{
 
-         //    Tuple<bool, Result> ret = Execute(id, () =>
 
-         //    {
 
-         //        Notify($"Set boat r axis interval={interval}");
 
-         //        _boatModule.SetRAxisIntervalPosition(interval);
 
-         //        return true;
 
-         //    });
 
-         //    if (ret.Item1)
 
-         //    {
 
-         //        if (ret.Item2 == Result.FAIL)
 
-         //        {
 
-         //            throw (new RoutineFaildException());
 
-         //        }
 
-         //        else
 
-         //            throw (new RoutineBreakException());
 
-         //    }
 
-         //}
 
-     }
 
- }
 
 
  |