示例#1
0
        public void Send(byte[] bytes, int length)
        {
            // Packet must start with correct header
            if (bytes[0] == 0xAA)
            {
                int    dLen   = bytes[3];
                byte[] packet = new byte[dLen + 5];
                Array.Copy(bytes, packet, bytes.Length);
                int chk = 0;
                for (int i = 1; i < bytes.Length; i++)
                {
                    chk = chk + bytes[i];
                }
                packet[packet.Length - 1] = (byte)chk;

                if (!TxQueue.TryToEnqueue(packet))
                {
                    ErrorLog.Error("Error in {0}, could not Enqueue packet to send", this.GetType().Name);
                }

                if (TxThread == null || TxThread.ThreadState != Thread.eThreadStates.ThreadRunning)
                {
                    TxThread          = new Thread(SendBufferProcess, null, Thread.eThreadStartOptions.CreateSuspended);
                    TxThread.Priority = Thread.eThreadPriority.HighPriority;
                    TxThread.Name     = string.Format("Samsung Display ComPort - Tx Handler");
                    TxThread.Start();
                }
            }
            else
            {
                throw new FormatException("Packet did not begin with correct value");
            }
        }