1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Collections.Generic;
- using System.IO.Ports;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Communications;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.SUNWAY
- {
- public class SPaceTRanRobotMessage : AsciiMessage
- {
- public int UNo { get; set; }
- public int SeqNo { get; set; }
- public string Status { get; set; }
- public string Ackcd { get; set; }
- public string Command { get; set; }
- public string[] Data { get; set; }
- public string ErrorCode { get; set; }
- public string EvNo { get; set; }
- public string EvDate { get; set; }
- public string EvData { get; set; }
- }
- public class SPaceTRanRobotConnection : TCPPortConnectionBase
- {
- public const string ERROR = "_ERR";
- public const string RDY = "_RDY";
- public const string CMDToken = " ";
- private SPaceTRanRobot _robot;
- private readonly Regex _rex_error_code = new Regex(@"_ERR\s+(\d+)\s*");
- public SPaceTRanRobotConnection(SPaceTRanRobot robot, string ipaddress): base(ipaddress, "\r", true)
- {
- _robot = robot;
- }
- protected override MessageBase ParseResponse(string rawMessage)
- {
- SPaceTRanRobotMessage msg = new SPaceTRanRobotMessage();
- try
- {
- msg.RawMessage = rawMessage.Replace("\r", "").Trim();
- msg.IsAck = true;
- msg.IsComplete = false;
- msg.IsFormatError = false;
- msg.IsEvent = false;
- if (_rex_error_code.IsMatch(rawMessage))
- {
- msg.IsAck = false;
- msg.IsComplete = false;
- msg.IsError = true;
- var results = _rex_error_code.Match(rawMessage);
- msg.ErrorCode = results.Groups[1].Value;
- _robot.OnError($"Execution error,Error code is {msg.ErrorCode}");
- }
- else if (rawMessage.Trim() == RDY || (rawMessage.Contains(RDY) && !rawMessage.Contains(ERROR)) || rawMessage.Contains("LOAD"))
- {
- msg.IsComplete = (rawMessage.Trim() == RDY) || (rawMessage.Contains(RDY) && !rawMessage.Contains(ERROR));
- msg.IsError = false;
- }
- else
- {
- msg.IsFormatError = true;
- msg.IsAck = false;
- msg.IsComplete = false;
- }
- return msg;
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- msg.IsFormatError = true;
- return msg;
- }
- }
- }
- }
|