using System.Collections.Generic; using System.IO.Ports; using System.Linq; using System.Text; using Aitex.Core.RT.Log; using MECF.Framework.Common.Communications; namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotHirataR4 { public class HirataR4RobotMessage : AsciiMessage { public string Data { get; set; } public string ErrorText { get; set; } } public class HirataR4RobotConnection : SerialPortConnectionBase { //private bool _isAckMode = false;//should read from config file private string _cachedBuffer = string.Empty; private List _lstCacheBuffer = new List(); public HirataR4RobotConnection(string portName, int baudRate = 19200, int dataBits = 7, Parity parity = Parity.Even, StopBits stopBits = StopBits.One) : base(portName, baudRate, dataBits, parity, stopBits, "\0", false) { } public override bool SendMessage(byte[] message) { _lstCacheBuffer.Clear(); return base.SendMessage(message); } protected override MessageBase ParseResponse(byte[] rawBuffer) { _lstCacheBuffer.AddRange(rawBuffer); byte[] temps = _lstCacheBuffer.ToArray(); HirataR4RobotMessage msg = new HirataR4RobotMessage(); msg.IsFormatError = false; msg.IsComplete = false; msg.IsEvent = false; if (temps.Length <= 7) return msg; byte lrc = 0x00; for (int i=1;i data) { byte ret = 0x00; for (var i = 0; i < data.Count; i++) { ret ^= data[i]; } return ret; } } }