Exemplo n.º 1
0
        private void parseBuffer()
        {
            isParsingBuffer = true;
            int           offset   = 0;
            bool          flag     = false;
            bool          received = false;
            LinkEventArgs lea      = new LinkEventArgs();
            int           dataused;

            while (offset < bufferSize)
            {
                PackageParseResult res = receivePackage.ReadFromBuffer(buffer, bufferSize, offset, out dataused);
                switch (res)
                {
                case PackageParseResult.NoSTX:
                    offset++;
                    break;

                case PackageParseResult.NoEnoughData:
                    flag = true;
                    break;

                case PackageParseResult.BadCheckSum:
                    offset++;
                    break;

                case PackageParseResult.Yes:
                    offset += dataused;
                    receivePackage.TimeStamp = this.ConnectedTime;
                    //lock (ReceivedPackageQueue)
                    {
                        //enqueueHandler.BeginInvoke(receivePackage.Clone(), null, null);
                        receivedPackageQueue.Enqueue(receivePackage.Clone());
                    }
                    received = true;
                    //lea.Package.Add(receivePackage.Clone());
                    break;
                }
                if (flag)
                {
                    break;
                }
            }

            for (int i = offset; i < bufferSize; i++)
            {
                buffer[i - offset] = buffer[i];
            }
            bufferSize     -= offset;
            isParsingBuffer = false;
            if (received)
            {
                OnReceivePackageEvent(this, lea);
            }
        }
Exemplo n.º 2
0
 protected void OnSendPackageEvent(CommLink sender, LinkEventArgs e)
 {
     OnSendPackage?.Invoke(this, e);
 }