12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.Diagnostics;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Communications;
- using HandlerBase = athosRT.tool.Comm.HandlerBase;
- namespace athosRT.Modules.Robot
- {
- public abstract class RorzeRobot751Handler : HandlerBase
- {
- protected string _commandType;
- protected string _command;
- protected string _parameter;
- private SCConfigItem _scMotionTimeout;
- public RorzeRobot751 Device { get; }
- public RorzeRobot751Handler(RorzeRobot751 device, string command, string parameter = null)
- : base(BuildMessage(command, parameter, device))
- {
- _scMotionTimeout = SC.GetConfigItem("Robot.Robot.MotionTimeout");
- Device = device;
- _command = command;
- _parameter = parameter;
- Name = command;
- AckTimeout = TimeSpan.FromSeconds(_scMotionTimeout.IntValue);
- CompleteTimeout = TimeSpan.FromSeconds(_scMotionTimeout.IntValue);
- }
- protected static string BuildMessage(string command, string parameter, RorzeRobot751 rbt)
- {
- string message = string.Format("oTRB{0}.{1}{2}\r", rbt.RobotBodyNumber, command, parameter ?? "");
- Trace.WriteLine("消息:" + message);
- return message;
- }
- public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
- {
- Trace.WriteLine("执行以下指令");
- Trace.WriteLine("处理过后的信息:" + msg.ToString());
- RorzeRobot751Message rorzeRobot751Message = msg as RorzeRobot751Message;
- base.ResponseMessage = msg;
- if (msg.IsError)
- {
- Device.NoteError(rorzeRobot751Message.RawMessage);
- transactionComplete = true;
- return true;
- }
- if (msg.IsAck)
- {
- SetState(EnumHandlerState.Acked);
- transactionComplete = false;
- return true;
- }
- if (msg.IsComplete)
- {
- SetState(EnumHandlerState.Completed);
- Device.OnActionDone(null);
- transactionComplete = true;
- return true;
- }
- transactionComplete = false;
- return false;
- }
- }
- }
|