RorzeRobot751Connection.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO.Ports;
  4. using System.Linq;
  5. using System.Text;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.SCCore;
  9. using MECF.Framework.Common.Communications;
  10. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Rorze
  11. {
  12. public class RorzeRobot751Message:AsciiMessage
  13. {
  14. public int UNo { get; set; }
  15. public int SeqNo { get; set; }
  16. public string Status { get; set; }
  17. public string Ackcd { get; set; }
  18. public string Command { get; set; }
  19. public string[] Data { get; set; }
  20. public string ErrorCode { get; set; }
  21. public string EvNo { get; set; }
  22. public string EvDate { get; set; }
  23. public string EvData { get; set; }
  24. }
  25. public class RorzeRobot751Connection: TCPPortConnectionBase
  26. {
  27. private RorzeRobot751 _robot;
  28. public RorzeRobot751Connection(RorzeRobot751 robot, string ipaddress)
  29. : base(ipaddress, "\r", true)
  30. {
  31. _robot = robot;
  32. }
  33. protected override MessageBase ParseResponse(string rawMessage)
  34. {
  35. RorzeRobot751Message msg = new RorzeRobot751Message();
  36. try
  37. {
  38. msg.RawMessage = rawMessage.Replace("\r","");
  39. msg.IsAck = false;
  40. msg.IsComplete = false;
  41. msg.IsFormatError = false;
  42. msg.IsEvent = false;
  43. switch(rawMessage[0])
  44. {
  45. case 'a':
  46. msg.IsAck = true;
  47. msg.IsComplete = false;
  48. msg.Data = rawMessage.Split(';').LastOrDefault().Split('/');
  49. break;
  50. case 'n':
  51. msg.IsNak = true;
  52. msg.IsComplete = false;
  53. break;
  54. case 'c':
  55. msg.IsError = true;
  56. msg.IsComplete = false;
  57. break;
  58. case 'e':
  59. msg.IsEvent = true;
  60. msg.IsComplete = false;
  61. _robot.OnEventReceived(rawMessage);
  62. break;
  63. }
  64. return msg;
  65. }
  66. catch(Exception ex)
  67. {
  68. LOG.Write(ex);
  69. msg.IsFormatError = true;
  70. return msg;
  71. }
  72. }
  73. protected override void OnEventArrived(MessageBase msg)
  74. {
  75. RorzeRobot751Message evt = msg as RorzeRobot751Message;
  76. if(evt.EvNo == "100")
  77. {
  78. string errocode = evt.EvData.Substring(1, evt.EvData.Length-1);
  79. _robot.NotifyAlarmByErrorCode(errocode.ToUpper());
  80. if(Convert.ToInt32(errocode,16) > 0xF0)
  81. _robot.OnError($"Robot occurred error:{evt.EvData} on {evt.EvDate}.");
  82. else
  83. EV.PostWarningLog("Robot", $"Robot occurred error:{evt.EvData} on {evt.EvDate}.");
  84. }
  85. if(evt.EvNo == "140")
  86. {
  87. }
  88. }
  89. }
  90. }