using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.HRC100Robots.GM201LVPRobot; using System; using System.Collections.Generic; using System; using System.Collections.Generic; using System.IO.Ports; using System.Linq; using System.Text; 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.HRC100Robots.GM201LVPRobot { public class GM201LVPRobotMessage : AsciiMessage { public string Command { get; set; } public string[] Data { get; set; } public string ErrorCode { get; set; } } public class GM201LVPRobotConnection : TCPPortConnectionBase { private GM201LVPRobot _robot; public GM201LVPRobotConnection(GM201LVPRobot robot, string ipaddress) : base(ipaddress, "\r", true, SC.GetValue("System.IsSimulatorMode") ? System.Net.Sockets.ProtocolType.Tcp : System.Net.Sockets.ProtocolType.Udp) { _robot = robot; } protected override MessageBase ParseResponse(string rawMessage) { GM201LVPRobotMessage msg = new GM201LVPRobotMessage(); try { msg.RawMessage = rawMessage.Replace("\r", ""); string[] msgdata = rawMessage.Replace("\r", "").Split(','); msg.IsAck = false; msg.IsComplete = false; msg.IsFormatError = false; if (msgdata.Length < 1) { return msg; } if (msgdata[0] == "CSTP") { if (msgdata.Length > 1 && msgdata[1] == "H") { _robot.NotePause(true); msg.IsComplete = false; return msg; } } if (msgdata[0] == "CRSM") { _robot.NotePause(false); msg.IsComplete = false; return msg; } if (msgdata[0] == "FAIL") { // msg.IsFormatError = true; msg.IsError = true; //_robot.OnError($"Execution error,Error Content is {msgdata[1]}"); return msg; } if (replayWithErrorAtCmd.Contains(msgdata[0])) { if (msgdata[msgdata.Length - 1] == "E") { msg.IsError = true; // _robot.OnError($"Execution error,Error Content is {msgdata[1]}"); return msg; } } msg.Command = msgdata[0]; msg.IsAck = true; msg.IsComplete = true; msg.Data = msgdata; //_robot.ParseStatus(msg.Status); return msg; } catch (Exception ex) { LOG.Write(ex); msg.IsFormatError = true; return msg; } } public List replayWithErrorAtCmd = new List() { "INIT", "MTRS", "MTCH", "MABS", "MREL", "MMAP" }; private string Checksum(byte[] bytes) { int sum = 0; foreach (byte code in bytes) { sum += code; } string hex = String.Format("{0:X2}", sum % 256); return hex; } } }