Beispiel #1
0
        public void OutBufferFilled_Flush_Multiple()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);
                Thread t = new Thread(asyncWriteRndByteArray.WriteRndByteArray);

                Debug.WriteLine("Verifying call Flush method several times after output buffer has been filled");

                com1.Open();
                com1.WriteTimeout = 500;
                com1.Handshake    = Handshake.RequestToSend;

                t.Start();

                TCSupport.WaitForWriteBufferToLoad(com1, DEFAULT_BUFFER_LENGTH);

                VerifyFlush(com1);
                VerifyFlush(com1);
                VerifyFlush(com1);

                // Wait for write method to timeout
                while (t.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }
Beispiel #2
0
        public void InOutBufferFilled_Flush_Cycle()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
                using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
                {
                    AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);
                    Thread t1 = new Thread(asyncWriteRndByteArray.WriteRndByteArray);
                    Thread t2 = new Thread(asyncWriteRndByteArray.WriteRndByteArray);

                    byte[] xmitBytes = new byte[DEFAULT_BUFFER_SIZE];

                    Debug.WriteLine(
                        "Verifying call Flush method after input and output buffer has been filled discarded and filled again");

                    com1.Open();
                    com2.Open();
                    com1.WriteTimeout = 500;
                    com1.Handshake    = Handshake.RequestToSend;

                    for (int i = 0; i < xmitBytes.Length; i++)
                    {
                        xmitBytes[i] = (byte)i;
                    }

                    com2.Write(xmitBytes, 0, xmitBytes.Length);

                    TCSupport.WaitForReadBufferToLoad(com1, DEFAULT_BUFFER_SIZE);

                    t1.Start();

                    TCSupport.WaitForWriteBufferToLoad(com1, DEFAULT_BUFFER_LENGTH);

                    VerifyFlush(com1);

                    // Wait for write method to timeout
                    while (t1.IsAlive)
                    {
                        Thread.Sleep(100);
                    }

                    t2.Start();

                    TCSupport.WaitForWriteBufferToLoad(com1, DEFAULT_BUFFER_LENGTH);

                    com2.Write(xmitBytes, 0, xmitBytes.Length);

                    TCSupport.WaitForReadBufferToLoad(com1, DEFAULT_BUFFER_SIZE);

                    VerifyFlush(com1);

                    // Wait for write method to timeout
                    while (t2.IsAlive)
                    {
                        Thread.Sleep(100);
                    }
                }
        }
Beispiel #3
0
        public void BytesToWriteSuccessive()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, s_STRING_SIZE_BYTES_TO_WRITE);
                Thread           t1 = new Thread(asyncWriteRndStr.WriteRndStr);
                Thread           t2 = new Thread(asyncWriteRndStr.WriteRndStr);

                int numNewLineBytes;
                int waitTime;

                Debug.WriteLine("Case BytesToWriteSuccessive : Verifying BytesToWrite with successive calls to Write");

                com.Handshake = Handshake.RequestToSend;
                com.Open();
                com.WriteTimeout = 1000;
                numNewLineBytes  = com.Encoding.GetByteCount(com.NewLine.ToCharArray());

                //Write a random string asynchronously so we can verify some things while the write call is blocking
                t1.Start();
                waitTime = 0;
                while (t1.ThreadState == ThreadState.Unstarted && waitTime < 2000)
                { //Wait for the thread to start
                    Thread.Sleep(50);
                    waitTime += 50;
                }

                TCSupport.WaitForWriteBufferToLoad(com, s_STRING_SIZE_BYTES_TO_WRITE + numNewLineBytes);

                //Write a random string asynchronously so we can verify some things while the write call is blocking
                t2.Start();
                waitTime = 0;
                while (t2.ThreadState == ThreadState.Unstarted && waitTime < 2000)
                { //Wait for the thread to start
                    Thread.Sleep(50);
                    waitTime += 50;
                }

                TCSupport.WaitForWriteBufferToLoad(com, (s_STRING_SIZE_BYTES_TO_WRITE + numNewLineBytes) * 2);

                //Wait for both write methods to timeout
                while (t1.IsAlive || t2.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }
Beispiel #4
0
        public void OutBufferFilled_Flush_Cycle()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);
                Thread t1 = new Thread(asyncWriteRndByteArray.WriteRndByteArray);
                Thread t2 = new Thread(asyncWriteRndByteArray.WriteRndByteArray);

                int elapsedTime;

                Debug.WriteLine(
                    "Verifying call Flush method after output buffer has been filled discarded and filled again");

                com1.Open();
                com1.WriteTimeout = 500;
                com1.Handshake    = Handshake.RequestToSend;

                t1.Start();
                elapsedTime = 0;

                while (com1.BytesToWrite < DEFAULT_BUFFER_LENGTH && elapsedTime < MAX_WAIT_TIME)
                {
                    Thread.Sleep(50);
                    elapsedTime += 50;
                }

                VerifyFlush(com1);

                // Wait for write method to timeout
                while (t1.IsAlive)
                {
                    Thread.Sleep(100);
                }

                t2.Start();

                TCSupport.WaitForWriteBufferToLoad(com1, DEFAULT_BUFFER_LENGTH);

                VerifyFlush(com1);

                // Wait for write method to timeout
                while (t2.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }