GM201LVPRobotConnection.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 (replayWithErrorAtCmd.Contains(msgdata[0]))
  66. {
  67. if (msgdata[msgdata.Length - 1] == "E")
  68. {
  69. msg.IsError = true;
  70. // _robot.OnError($"Execution error,Error Content is {msgdata[1]}");
  71. return msg;
  72. }
  73. }
  74. msg.Command = msgdata[0];
  75. msg.IsAck = true;
  76. msg.IsComplete = true;
  77. msg.Data = msgdata;
  78. //_robot.ParseStatus(msg.Status);
  79. return msg;
  80. }
  81. catch (Exception ex)
  82. {
  83. LOG.Write(ex);
  84. msg.IsFormatError = true;
  85. return msg;
  86. }
  87. }
  88. public List<string> replayWithErrorAtCmd = new List<string>() { "INIT", "MTRS", "MTCH", "MABS", "MREL", "MMAP" };
  89. private string Checksum(byte[] bytes)
  90. {
  91. int sum = 0;
  92. foreach (byte code in bytes)
  93. {
  94. sum += code;
  95. }
  96. string hex = String.Format("{0:X2}", sum % 256);
  97. return hex;
  98. }
  99. }
  100. }