KV8000.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GSG.NET.Logging;
  7. using GSG.NET.TCP;
  8. using GSG.NET.Utils;
  9. namespace OHVLoggerTest
  10. {
  11. public class KV8000
  12. {
  13. static Logger logger = Logger.GetLogger();
  14. TcpConnector h = new TcpConnector();
  15. const byte CR = 0x0d;
  16. public bool Connecte()
  17. {
  18. h.Connect( new TcpComm
  19. {
  20. Active = true,
  21. Ip = "192.168.0.20",
  22. PortNo = 8501,
  23. } ) ;
  24. return h.Connected;
  25. }
  26. /// <summary>
  27. /// 주행 시작 시 진단 PLC Bit On
  28. /// </summary>
  29. /// <returns></returns>
  30. public bool SetPLCStartDrive()
  31. {
  32. try
  33. {
  34. if ( !h.Connected )
  35. {
  36. h.Connect( new TcpComm
  37. {
  38. Active = true,
  39. Ip = "192.168.0.20",
  40. PortNo = 8501,
  41. } );
  42. }
  43. if ( !h.Connected )
  44. return false;
  45. var mb = new MemoryBuffer();
  46. mb.AppendAscii( "WR MR100 1" );
  47. mb.Append( CR );
  48. this.h.WriteFlush( mb.ToBytes );
  49. }
  50. catch ( Exception e )
  51. {
  52. h.CloseSocket();
  53. logger.E( $"[PLC] - Set Value Connection Error {e}" );
  54. return false;
  55. }
  56. return true;
  57. }
  58. /// <summary>
  59. /// 주행 정지 시 진단 PLC Bit Off
  60. /// </summary>
  61. /// <returns></returns>
  62. public bool ResetPLCStartDrive()
  63. {
  64. try
  65. {
  66. if ( !h.Connected )
  67. {
  68. h.Connect( new TcpComm
  69. {
  70. Active = true,
  71. Ip = "192.168.0.20",
  72. PortNo = 8501,
  73. } );
  74. }
  75. if ( !h.Connected )
  76. return false;
  77. var mb = new MemoryBuffer();
  78. mb.AppendAscii( "WR MR100 0" );
  79. mb.Append( CR );
  80. this.h.WriteFlush( mb.ToBytes );
  81. }
  82. catch ( Exception e )
  83. {
  84. h.CloseSocket();
  85. logger.E( $"[PLC] - Reset Value Connection Error {e}" );
  86. return false;
  87. }
  88. return true;
  89. }
  90. }
  91. }