MinicsManager.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Aitex.Core.RT.Event;
  2. using Aitex.Core.RT.RecipeCenter;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.Equipment;
  5. using MECF.Framework.Common.SCCore;
  6. using Microsoft.VisualBasic.Devices;
  7. using RTCommunicatorBase;
  8. using RTCommunicatorTLV;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace MECF.Framework.Common.Minics
  17. {
  18. public class MinicsManager : Singleton<MinicsManager>, IRTMini8Provider
  19. {
  20. public void Connected(string ip, int port)
  21. {
  22. Console.WriteLine($"DisconnectedNotify {ip} {port}");
  23. }
  24. public void DisConnected(string ip, int port)
  25. {
  26. Console.WriteLine($"DisconnectedNotify {ip} {port}");
  27. }
  28. private RTCommunicator_TLV communicator = new RTCommunicator_TLV();
  29. public void Initialize(string ip = "127.0.0.1", int port = 50052)
  30. {
  31. communicator.Initialize(this);
  32. SWJConnectedMinics(ip, port);
  33. }
  34. public void SWJConnectedMinics(string ip, int port)
  35. {
  36. if (communicator.StartService(ip, port))
  37. {
  38. EV.PostInfoLog(ModuleName.Minics.ToString(), $"minics Connected {ip}:{port} sucessful");
  39. }
  40. else
  41. {
  42. for (int i = 1; i <= 3; i++)
  43. {
  44. var status = this.communicator.StartService(ip, port);
  45. try
  46. {
  47. if (status)
  48. break;
  49. }
  50. catch
  51. {
  52. if (i == 3)
  53. return;
  54. Thread.Sleep(300);
  55. EV.PostAlarmLog(ModuleName.Minics.ToString(), $"retry minics Connected {ip}:{port} error {i} times");
  56. }
  57. }
  58. }
  59. }
  60. public void End()
  61. {
  62. }
  63. public void SelectMinicsConfig(string minicsConfigName)
  64. {
  65. communicator.SelectConfigFile(minicsConfigName);
  66. }
  67. }
  68. }