RorzeRobot751Connection.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Log;
  6. using MECF.Framework.Common.Communications;
  7. using TCPPortConnectionBase = athosRT.tool.Comm.TCPPortConnectionBase;
  8. namespace athosRT.Modules.Robot
  9. {
  10. public class RorzeRobot751Connection : TCPPortConnectionBase
  11. {
  12. private RorzeRobot751 _robot;
  13. public RorzeRobot751Connection(RorzeRobot751 robot, string ipaddress)
  14. : base(ipaddress)
  15. {
  16. _robot = robot;
  17. }
  18. protected override MessageBase ParseResponse(string rawMessage)
  19. {
  20. RorzeRobot751Message rorzeRobot751Message = new RorzeRobot751Message();
  21. try
  22. {
  23. rorzeRobot751Message.RawMessage = rawMessage.Replace("\r", "");
  24. rorzeRobot751Message.IsAck = false;
  25. rorzeRobot751Message.IsComplete = false;
  26. rorzeRobot751Message.IsFormatError = false;
  27. rorzeRobot751Message.IsEvent = false;
  28. switch (rawMessage[0])
  29. {
  30. case 'a':
  31. rorzeRobot751Message.IsAck = true;
  32. rorzeRobot751Message.IsComplete = false;
  33. rorzeRobot751Message.Data = rawMessage.Split(';').LastOrDefault().Split('/');
  34. break;
  35. case 'n':
  36. rorzeRobot751Message.IsNak = true;
  37. rorzeRobot751Message.IsComplete = false;
  38. break;
  39. case 'c':
  40. rorzeRobot751Message.IsError = true;
  41. rorzeRobot751Message.IsComplete = false;
  42. break;
  43. case 'e':
  44. rorzeRobot751Message.IsEvent = true;
  45. rorzeRobot751Message.IsComplete = false;
  46. _robot.OnEventReceived(rawMessage);
  47. break;
  48. }
  49. return rorzeRobot751Message;
  50. }
  51. catch (Exception ex)
  52. {
  53. LOG.Write(ex, 2, "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\Rorze751\\RorzeRobot751Connection.cs", "ParseResponse", 76);
  54. rorzeRobot751Message.IsFormatError = true;
  55. return rorzeRobot751Message;
  56. }
  57. }
  58. protected override void OnEventArrived(MessageBase msg)
  59. {
  60. RorzeRobot751Message rorzeRobot751Message = msg as RorzeRobot751Message;
  61. if (rorzeRobot751Message.EvNo == "100")
  62. {
  63. string text = rorzeRobot751Message.EvData.Substring(1, rorzeRobot751Message.EvData.Length - 1);
  64. _robot.NotifyAlarmByErrorCode(text.ToUpper());
  65. if (Convert.ToInt32(text, 16) > 240)
  66. {
  67. _robot.OnError("Robot occurred error:" + rorzeRobot751Message.EvData + " on " + rorzeRobot751Message.EvDate + ".");
  68. }
  69. else
  70. {
  71. EV.PostWarningLog("Robot", "Robot occurred error:" + rorzeRobot751Message.EvData + " on " + rorzeRobot751Message.EvDate + ".");
  72. }
  73. }
  74. if (!(rorzeRobot751Message.EvNo == "140"))
  75. {
  76. }
  77. }
  78. protected override void ActiveHandlerProceedMessage(MessageBase msg)
  79. {
  80. //Trace.WriteLine("ActiveHandlerProceedMessage override");
  81. lock (_lockerActiveHandler)
  82. {
  83. //if (_activeHandler != null && (msg.IsFormatError || (_activeHandler.HandleMessage(msg, out var transactionComplete) && transactionComplete)))
  84. if (_activeHandler != null && (_activeHandler.HandleMessage(msg, out var transactionComplete) && transactionComplete))
  85. {
  86. _activeHandler = null;
  87. }
  88. }
  89. }
  90. }
  91. }