RorzeRobot751Handler.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Diagnostics;
  3. using Aitex.Core.RT.SCCore;
  4. using MECF.Framework.Common.Communications;
  5. using HandlerBase = athosRT.tool.Comm.HandlerBase;
  6. namespace athosRT.Modules.Robot
  7. {
  8. public abstract class RorzeRobot751Handler : HandlerBase
  9. {
  10. protected string _commandType;
  11. protected string _command;
  12. protected string _parameter;
  13. private SCConfigItem _scMotionTimeout;
  14. public RorzeRobot751 Device { get; }
  15. public RorzeRobot751Handler(RorzeRobot751 device, string command, string parameter = null)
  16. : base(BuildMessage(command, parameter, device))
  17. {
  18. _scMotionTimeout = SC.GetConfigItem("Robot.Robot.MotionTimeout");
  19. Device = device;
  20. _command = command;
  21. _parameter = parameter;
  22. Name = command;
  23. AckTimeout = TimeSpan.FromSeconds(_scMotionTimeout.IntValue);
  24. CompleteTimeout = TimeSpan.FromSeconds(_scMotionTimeout.IntValue);
  25. }
  26. protected static string BuildMessage(string command, string parameter, RorzeRobot751 rbt)
  27. {
  28. string message = string.Format("oTRB{0}.{1}{2}\r", rbt.RobotBodyNumber, command, parameter ?? "");
  29. Trace.WriteLine("消息:" + message);
  30. return message;
  31. }
  32. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  33. {
  34. Trace.WriteLine("执行以下指令");
  35. Trace.WriteLine("处理过后的信息:" + msg.ToString());
  36. RorzeRobot751Message rorzeRobot751Message = msg as RorzeRobot751Message;
  37. base.ResponseMessage = msg;
  38. if (msg.IsError)
  39. {
  40. Device.NoteError(rorzeRobot751Message.RawMessage);
  41. transactionComplete = true;
  42. return true;
  43. }
  44. if (msg.IsAck)
  45. {
  46. SetState(EnumHandlerState.Acked);
  47. transactionComplete = false;
  48. return true;
  49. }
  50. if (msg.IsComplete)
  51. {
  52. SetState(EnumHandlerState.Completed);
  53. Device.OnActionDone(null);
  54. transactionComplete = true;
  55. return true;
  56. }
  57. transactionComplete = false;
  58. return false;
  59. }
  60. }
  61. }