Conveyor.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System.Threading;
  2. using GSG.NET.Concurrent;
  3. using GSG.NET.Logging;
  4. using GSG.NET.Utils;
  5. using VehicleControlSystem.ControlLayer.IO;
  6. namespace VehicleControlSystem.ControlLayer
  7. {
  8. public class Conveyor
  9. {
  10. Logger logger = Logger.GetLogger();
  11. EzIO ezIO = null;
  12. public Conveyor(EzIO io)
  13. {
  14. this.ezIO = io;
  15. }
  16. public int OnOffConveyor( bool isOn, bool isLoad = false )
  17. {
  18. this.SetConveyorSpeed( isLoad ); //Load 시 속도를 조금 더 빠르게 하기 위해.
  19. if ( isLoad )
  20. this.ezIO.OutputOn( "OUT_CV_CWCCW" );
  21. else
  22. this.ezIO.OutputOff( "OUT_CV_CWCCW" );
  23. if ( isOn )
  24. this.ezIO.OutputOn( "OUT_CV_RUN" );
  25. else
  26. this.ezIO.OutputOff( "OUT_CV_RUN" );
  27. LockUtils.Wait(500);
  28. if (this.IsInverterError())
  29. {
  30. this.ezIO.OutputOff("OUT_CV_RUN");
  31. return 16;
  32. }
  33. return 0;
  34. }
  35. public void SetConveyorSpeed( bool IsLoad )
  36. {
  37. if ( IsLoad )
  38. this.ezIO.WriteOutputIO( "OUT_CV_DA", true );
  39. else
  40. this.ezIO.WriteOutputIO( "OUT_CV_DA", false );
  41. }
  42. public bool IsCvRun() => this.ezIO.IsOn( "OUT_CV_RUN" );
  43. public bool IsCvCWCCW() => this.ezIO.IsOn( "OUT_CV_CWCCW" );
  44. /// <summary>
  45. /// 입구 감지 로딩시 감속 사용
  46. /// </summary>
  47. /// <returns></returns>
  48. public bool IsDetectedLoadStart() => this.ezIO.IsOn( "IN_CV_DETECT_00" );
  49. /// <summary>
  50. /// 실물 감지
  51. /// </summary>
  52. /// <returns></returns>
  53. public bool IsDetectedCenter() => this.ezIO.IsOn( "IN_CV_DETECT_01" );
  54. public bool IsDetectedLoadStop() => this.ezIO.IsOn( "IN_CV_DETECT_02" );
  55. public bool IsInverterError() => !this.ezIO.IsOn( "IN_CV_ERROR" ); //Normal Close 로 생각 됨.
  56. public bool IsLifterPositinCheck() => this.ezIO.IsOn( "IN_LIFTER_POSITION_DETECT" );
  57. public bool IsLifterDuplication() => this.ezIO.IsOn( "IN_LIFTER_DUPLICATION_DETECT" );
  58. public bool IsPIOInterLockOn() => this.ezIO.IsOn( "IN_PIO_INTERLOCK" );
  59. public int ConveyorLoad()
  60. {
  61. if ( IsDetectedCenter() )
  62. return 9;
  63. logger.D( "[Manual Load] - Conveyor On" );
  64. OnOffConveyor( true, true );
  65. bool isStartDetected = false;
  66. long sTime = SwUtils.CurrentTimeMillis;
  67. while ( true )
  68. {
  69. if ( SwUtils.Gt( sTime, 20 * ConstUtils.ONE_SECOND ) ) //Wait 20Sec
  70. {
  71. OnOffConveyor( false, true );
  72. return 10;
  73. }
  74. if ( this.IsDetectedLoadStart() && !isStartDetected )
  75. isStartDetected = true;
  76. if ( !this.IsDetectedLoadStart() && isStartDetected )
  77. {
  78. //this.SetConveyorSpeed( false );
  79. logger.D( "[Manual Load] - Conveyor Slow State" );
  80. }
  81. if ( IsDetectedLoadStop() )
  82. break;
  83. }
  84. OnOffConveyor( false );
  85. logger.D( "[Manual Load] - Conveyor Off" );
  86. return 0;
  87. }
  88. public int ConveyorUnload()
  89. {
  90. if ( !IsDetectedCenter() )
  91. return 11;
  92. logger.D( "[Manual Unload] - Conveyor On" );
  93. OnOffConveyor( true, false );
  94. long sTime = SwUtils.CurrentTimeMillis;
  95. while ( true )
  96. {
  97. if ( SwUtils.Gt( sTime, 20 * ConstUtils.ONE_SECOND ) ) //Wait 20Sec
  98. {
  99. OnOffConveyor( false, false );
  100. return 12;
  101. }
  102. if ( !IsDetectedLoadStart() && !IsDetectedCenter() )
  103. break;
  104. }
  105. Thread.Sleep( 2000 );
  106. OnOffConveyor( false );
  107. logger.D( "[Manual Unload] - Conveyor Off" );
  108. return 0;
  109. }
  110. }
  111. }