GM201LVPRobotConnection.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.HRC100Robots.GM201LVPRobot;
  2. using System;
  3. using System.Collections.Generic;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO.Ports;
  7. using System.Linq;
  8. using System.Text;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.RT.SCCore;
  12. using MECF.Framework.Common.Communications;
  13. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.HRC100Robots.GM201LVPRobot
  14. {
  15. public class GM201LVPRobotMessage : AsciiMessage
  16. {
  17. public string Command { get; set; }
  18. public string[] Data { get; set; }
  19. public string ErrorCode { get; set; }
  20. }
  21. public class GM201LVPRobotConnection : TCPPortConnectionBase
  22. {
  23. private GM201LVPRobot _robot;
  24. public GM201LVPRobotConnection(GM201LVPRobot robot, string ipaddress)
  25. : base(ipaddress, "\r", true, SC.GetValue<bool>("System.IsSimulatorMode") ? System.Net.Sockets.ProtocolType.Tcp : System.Net.Sockets.ProtocolType.Udp)
  26. {
  27. _robot = robot;
  28. }
  29. protected override MessageBase ParseResponse(string rawMessage)
  30. {
  31. GM201LVPRobotMessage msg = new GM201LVPRobotMessage();
  32. try
  33. {
  34. msg.RawMessage = rawMessage.Replace("\r", "");
  35. string[] msgdata = rawMessage.Replace("\r", "").Split(',');
  36. msg.IsAck = false;
  37. msg.IsComplete = false;
  38. msg.IsFormatError = false;
  39. if (msgdata.Length < 1)
  40. {
  41. return msg;
  42. }
  43. if (msgdata[0] == "CSTP")
  44. {
  45. if (msgdata.Length > 1 && msgdata[1] == "H")
  46. {
  47. _robot.NotePause(true);
  48. msg.IsComplete = false;
  49. return msg;
  50. }
  51. }
  52. if (msgdata[0] == "CRSM")
  53. {
  54. _robot.NotePause(false);
  55. msg.IsComplete = false;
  56. return msg;
  57. }
  58. if (msgdata[0] == "FAIL")
  59. {
  60. // msg.IsFormatError = true;
  61. msg.IsError = true;
  62. //_robot.OnError($"Execution error,Error Content is {msgdata[1]}");
  63. return msg;
  64. }
  65. if (msgdata[0] == "INIT" && msgdata.Contains("E"))
  66. {
  67. // msg.IsFormatError = true;
  68. msg.IsError = true;
  69. //_robot.OnError($"Execution error,Error Content is {msgdata[1]}");
  70. return msg;
  71. }
  72. if (replayWithErrorAtCmd.Contains(msgdata[0]))
  73. {
  74. if (msgdata[msgdata.Length - 1] == "E")
  75. {
  76. msg.IsError = true;
  77. // _robot.OnError($"Execution error,Error Content is {msgdata[1]}");
  78. return msg;
  79. }
  80. }
  81. msg.Command = msgdata[0];
  82. msg.IsAck = true;
  83. msg.IsComplete = true;
  84. msg.Data = msgdata;
  85. //_robot.ParseStatus(msg.Status);
  86. return msg;
  87. }
  88. catch (Exception ex)
  89. {
  90. LOG.Write(ex);
  91. msg.IsFormatError = true;
  92. return msg;
  93. }
  94. }
  95. public List<string> replayWithErrorAtCmd = new List<string>() { "INIT", "MTRS", "MTCH", "MABS", "MREL", "MMAP" };
  96. private string Checksum(byte[] bytes)
  97. {
  98. int sum = 0;
  99. foreach (byte code in bytes)
  100. {
  101. sum += code;
  102. }
  103. string hex = String.Format("{0:X2}", sum % 256);
  104. return hex;
  105. }
  106. }
  107. }