public void AddByte(byte bt) { if (!IsHeaderFind && bt == PACKAGE_HEADER) { IsHeaderFind = true; DataRecieveQueue.Enqueue(bt); if (PackageSize == 1) { IsPackageFind = true; return; } } else if (IsHeaderFind) { DataRecieveQueue.Enqueue(bt); if (DataRecieveQueue.Count == PackageSize) { RawData = DataRecieveQueue.ToArray(); var CalcXOR = CheckXor.GetStringXOR(RawData, 0, RawData.Length - 2); //Clear queue int dataLen = DataRecieveQueue.Count; for (int i = 0; i < dataLen; i++) { DataRecieveQueue.Dequeue(); } if (RawData[PackageSize - 1] == CalcXOR[1] && RawData[PackageSize - 2] == CalcXOR[0]) { OnPackageRecieved?.Invoke(this, new PackageRecieveArgs() { RawData = this.RawData, Cmd = (EnumCommand)RawData[1] }); IsPackageFind = true; } else { IsHeaderFind = false; IsPackageFind = false; } } } }
private void Filter_OnPackageReceived(object sender, string e) { OnPackageRecieved?.Invoke(this, e); }