Ejemplo n.º 1
0
        public void InOutBufferFilled_Flush_Once()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
                using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
                {
                    AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);
                    var t = new Task(asyncWriteRndByteArray.WriteRndByteArray);

                    byte[] xmitBytes = new byte[DEFAULT_BUFFER_SIZE];

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

                    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);

                    t.Start();

                    TCSupport.WaitForWriteBufferToLoad(com1, DEFAULT_BUFFER_LENGTH);

                    VerifyFlush(com1);

                    TCSupport.WaitForTaskCompletion(t);
                }
        }
Ejemplo n.º 2
0
        public void OutBufferFilled_Flush_Once()
        {
            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 Flush method 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);

                // Wait for write method to timeout
                while (t.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 3
0
        public void Handshake_None()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, BYTE_SIZE_HANDSHAKE);
                var t = new Thread(asyncWriteRndByteArray.WriteRndByteArray);

                // Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                Debug.WriteLine("Verifying Handshake=None");

                com.Open();
                t.Start();
                var waitTime = 0;

                while (t.ThreadState == ThreadState.Unstarted && waitTime < 2000)
                {
                    // Wait for the thread to start
                    Thread.Sleep(50);
                    waitTime += 50;
                }

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

                Assert.Equal(0, com.BytesToWrite);
            }
        }
        public void BytesToWriteSuccessive()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, s_BYTE_SIZE_BYTES_TO_WRITE);
                var t1 = new Task(asyncWriteRndByteArray.WriteRndByteArray);
                var t2 = new Task(asyncWriteRndByteArray.WriteRndByteArray);

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

                com.Handshake = Handshake.RequestToSend;
                com.Open();
                com.WriteTimeout = 4000;

                // Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                t1.Start();
                TCSupport.WaitForTaskToStart(t1);
                TCSupport.WaitForExactWriteBufferLoad(com, s_BYTE_SIZE_BYTES_TO_WRITE);

                // Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                t2.Start();
                TCSupport.WaitForTaskToStart(t2);
                TCSupport.WaitForExactWriteBufferLoad(com, s_BYTE_SIZE_BYTES_TO_WRITE * 2);

                // Wait for both write methods to timeout
                var aggregatedException = Assert.Throws <AggregateException>(() => TCSupport.WaitForTaskCompletion(t2));
                Assert.IsType <IOException>(aggregatedException.InnerException);
            }
        }
Ejemplo n.º 5
0
        public void BytesToWrite()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, BYTE_SIZE_BYTES_TO_WRITE);
                Thread t = new Thread(asyncWriteRndByteArray.WriteRndByteArray);

                int waitTime;

                Debug.WriteLine("Verifying BytesToWrite with one call to Write");

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

                //Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                t.Start();
                waitTime = 0;

                while (t.ThreadState == ThreadState.Unstarted && waitTime < 2000)
                { //Wait for the thread to start
                    Thread.Sleep(50);
                    waitTime += 50;
                }

                TCSupport.WaitForExactWriteBufferLoad(com, BYTE_SIZE_BYTES_TO_WRITE);

                //Wait for write method to timeout
                while (t.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 6
0
        public void Handshake_None()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndByteArray  asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, BYTE_SIZE_HANDSHAKE);
                System.Threading.Thread t = new System.Threading.Thread(asyncWriteRndByteArray.WriteRndByteArray);

                int waitTime;

                //Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                Debug.WriteLine("Verifying Handshake=None");

                com.Open();
                t.Start();
                waitTime = 0;

                while (t.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000)
                { //Wait for the thread to start
                    System.Threading.Thread.Sleep(50);
                    waitTime += 50;
                }

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

                if (0 != com.BytesToWrite)
                {
                    Fail("ERROR!!! Expcted BytesToWrite=0 actual {0}", com.BytesToWrite);
                }
            }
        }
Ejemplo n.º 7
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);

                int elapsedTime;

                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();
                elapsedTime = 0;

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

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

                // Wait for write method to timeout
                while (t.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 8
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);
                    }
                }
        }
Ejemplo n.º 9
0
    private bool BytesToWrite()
    {
        SerialPort             com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, BYTE_SIZE_BYTES_TO_WRITE);

        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        bool retValue             = true;
        int  waitTime             = 0;

        Console.WriteLine("Verifying BytesToWrite with one call to Write");

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

        //Write a random byte[] asynchronously so we can verify some things while the write call is blocking
        t.Start();
        waitTime = 0;

        while (t.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000)
        { //Wait for the thread to start
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        waitTime = 0;

        while (BYTE_SIZE_BYTES_TO_WRITE > com.BytesToWrite && waitTime < 500)
        {
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        if (BYTE_SIZE_BYTES_TO_WRITE != com.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite={0} actual {1} after first write", BYTE_SIZE_BYTES_TO_WRITE, com.BytesToWrite);
        }

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

        if (com.IsOpen)
        {
            com.Close();
        }

        if (!retValue)
        {
            Console.WriteLine("Err_007!!! Verifying BytesToWrite with one call to Write FAILED");
        }

        return(retValue);
    }
Ejemplo n.º 10
0
        public void InOutBufferFilled_Flush_Multiple()
        {
            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 t = new Thread(asyncWriteRndByteArray.WriteRndByteArray);

                    int    elapsedTime = 0;
                    byte[] xmitBytes   = new byte[DEFAULT_BUFFER_SIZE];

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

                    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);

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

                    t.Start();
                    elapsedTime = 0;

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

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

                    // Wait for write method to timeout
                    while (t.IsAlive)
                    {
                        Thread.Sleep(100);
                    }
                }
        }
Ejemplo n.º 11
0
    public bool Handshake_None()
    {
        SerialPort             com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com);

        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        bool retValue             = true;
        int  waitTime;

        //Write a random byte[] asynchronously so we can verify some things while the write call is blocking
        Console.WriteLine("Verifying Handshake=None");

        com.Open();
        t.Start();
        waitTime = 0;

        while (t.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000)
        { //Wait for the thread to start
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        //Wait for both write methods to timeout
        while (t.IsAlive)
        {
            System.Threading.Thread.Sleep(100);
        }

        if (0 != com.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite=0 actual {0}", com.BytesToWrite);
        }

        if (!retValue)
        {
            Console.WriteLine("Err_009!!! Verifying Handshake=None FAILED");
        }

        if (com.IsOpen)
        {
            com.Close();
        }

        return(retValue);
    }
Ejemplo n.º 12
0
        public void Handshake_None()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, s_BYTE_SIZE_HANDSHAKE);
                var t = new Task(asyncWriteRndByteArray.WriteRndByteArray);

                // Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                Debug.WriteLine("Verifying Handshake=None");

                com.Open();
                t.Start();
                TCSupport.WaitForTaskCompletion(t);

                Assert.Equal(0, com.BytesToWrite);
            }
        }
Ejemplo n.º 13
0
    public bool OutBufferFilled_Flush_Multiple()
    {
        SerialPort             com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);

        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        bool retValue             = true;
        int  elapsedTime          = 0;

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

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

        t.Start();
        elapsedTime = 0;

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

        retValue &= VerifyFlush(com1);
        retValue &= VerifyFlush(com1);
        retValue &= VerifyFlush(com1);

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

        if (!retValue)
        {
            Console.WriteLine("Err_005!!! Verifying call Flush method several times after output buffer has been filled FAILED");
        }

        if (com1.IsOpen)
        {
            com1.Close();
        }

        return(retValue);
    }
Ejemplo n.º 14
0
        public void BytesToWrite()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var asyncWriteRndByteArray = new AsyncWriteRndByteArray(com);
                var t = new Thread(asyncWriteRndByteArray.WriteRndByteArray);

                int waitTime;

                Debug.WriteLine("Verifying BytesToWrite with one call to Write");

                com.Handshake = Handshake.RequestToSend;
                com.Open();
                com.WriteTimeout = 200;

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

                waitTime = 0;
                while (com.BytesToWrite < 1 && waitTime < 250)
                {
                    Thread.Sleep(50);
                    waitTime += 50;
                }

                if (1 != com.BytesToWrite)
                {
                    Fail("ERROR!!! Expcted BytesToWrite={0} actual {1} after first write", 1,
                         com.BytesToWrite);
                }

                // Wait for write method to timeout
                while (t.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 15
0
        public void BytesToWrite()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, s_BYTE_SIZE_BYTES_TO_WRITE);
                var t = new Task(asyncWriteRndByteArray.WriteRndByteArray);

                Debug.WriteLine("Verifying BytesToWrite with one call to Write");

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

                // Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                t.Start();
                TCSupport.WaitForTaskToStart(t);

                TCSupport.WaitForWriteBufferToLoad(com, s_BYTE_SIZE_BYTES_TO_WRITE);

                TCSupport.WaitForTaskCompletion(t);
            }
        }
Ejemplo n.º 16
0
        public void OutBufferFilled_Flush_Once()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);
                var t = new Task(asyncWriteRndByteArray.WriteRndByteArray);

                Debug.WriteLine("Verifying Flush method 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);

                TCSupport.WaitForTaskCompletion(t);
            }
        }
Ejemplo n.º 17
0
        public void OutBufferFilled_Flush_Cycle()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);
                var t1 = new Task(asyncWriteRndByteArray.WriteRndByteArray);
                var t2 = new Task(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);

                TCSupport.WaitForTaskCompletion(t1);

                t2.Start();

                TCSupport.WaitForWriteBufferToLoad(com1, DEFAULT_BUFFER_LENGTH);

                VerifyFlush(com1);

                TCSupport.WaitForTaskCompletion(t2);
            }
        }
Ejemplo n.º 18
0
        public void BytesToWriteSuccessive()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, BYTE_SIZE_BYTES_TO_WRITE);
                var t1 = new Thread(asyncWriteRndByteArray.WriteRndByteArray);
                var t2 = new Thread(asyncWriteRndByteArray.WriteRndByteArray);

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

                com.Handshake = Handshake.RequestToSend;
                com.Open();
                com.WriteTimeout = 4000;

                // Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                t1.Start();
                var waitTime = 0;

                while (t1.ThreadState == ThreadState.Unstarted && waitTime < 2000)
                {
                    // Wait for the thread to start
                    Thread.Sleep(50);
                    waitTime += 50;
                }

                waitTime = 0;

                while (BYTE_SIZE_BYTES_TO_WRITE > com.BytesToWrite && waitTime < 500)
                {
                    Thread.Sleep(50);
                    waitTime += 50;
                }

                Assert.Equal(BYTE_SIZE_BYTES_TO_WRITE, com.BytesToWrite);

                // Write a random byte[] 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;
                }

                waitTime = 0;

                while (BYTE_SIZE_BYTES_TO_WRITE * 2 > com.BytesToWrite && waitTime < 500)
                {
                    Thread.Sleep(50);
                    waitTime += 50;
                }

                Assert.Equal(BYTE_SIZE_BYTES_TO_WRITE * 2, com.BytesToWrite);

                // Wait for both write methods to timeout
                while (t1.IsAlive || t2.IsAlive)
                {
                    Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 19
0
    public bool OutBufferFilled_Flush_Cycle()
    {
        SerialPort             com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);

        System.Threading.Thread t1 = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        System.Threading.Thread t2 = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        bool retValue    = true;
        int  elapsedTime = 0;

        Console.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)
        {
            System.Threading.Thread.Sleep(50);
            elapsedTime += 50;
        }

        if (!VerifyFlush(com1))
        {
            Console.WriteLine("Err_29292jsazie Verifying Flush FAILED after buffer was filled once");
            retValue = false;
        }

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


        t2.Start();
        elapsedTime = 0;

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

        if (!VerifyFlush(com1))
        {
            Console.WriteLine("Err_065784ahzoabh Verifying Flush FAILED after buffer was filled the second time");
            retValue = false;
        }

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


        if (!retValue)
        {
            Console.WriteLine("Err_006!!! Verifying call Flush method after output buffer has been filled discarded and filled again FAILED");
        }

        if (com1.IsOpen)
        {
            com1.Close();
        }

        return(retValue);
    }
Ejemplo n.º 20
0
        private void Verify_Handshake(Handshake handshake)
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
                using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
                {
                    AsyncWriteRndByteArray  asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, BYTE_SIZE_HANDSHAKE);
                    System.Threading.Thread t = new System.Threading.Thread(asyncWriteRndByteArray.WriteRndByteArray);

                    byte[] XOffBuffer = new byte[1];
                    byte[] XOnBuffer  = new byte[1];
                    int    waitTime;

                    XOffBuffer[0] = 19;
                    XOnBuffer[0]  = 17;

                    Debug.WriteLine("Verifying Handshake={0}", handshake);

                    com1.Handshake = handshake;
                    com1.Open();
                    com2.Open();

                    //Setup to ensure write will bock with type of handshake method being used
                    if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake)
                    {
                        com2.RtsEnable = false;
                    }

                    if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake)
                    {
                        com2.Write(XOffBuffer, 0, 1);
                        System.Threading.Thread.Sleep(250);
                    }

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

                    waitTime = 0;
                    while (BYTE_SIZE_HANDSHAKE > com1.BytesToWrite && waitTime < 500)
                    {
                        System.Threading.Thread.Sleep(50);
                        waitTime += 50;
                    }

                    //Verify that the correct number of bytes are in the buffer
                    if (BYTE_SIZE_HANDSHAKE != com1.BytesToWrite)
                    {
                        Fail("ERROR!!! Expcted BytesToWrite={0} actual {1}", BYTE_SIZE_HANDSHAKE, com1.BytesToWrite);
                    }

                    //Verify that CtsHolding is false if the RequestToSend or RequestToSendXOnXOff handshake method is used
                    if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) && com1.CtsHolding)
                    {
                        Fail("ERROR!!! Expcted CtsHolding={0} actual {1}", false, com1.CtsHolding);
                    }

                    //Setup to ensure write will succeed
                    if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake)
                    {
                        com2.RtsEnable = true;
                    }

                    if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake)
                    {
                        com2.Write(XOnBuffer, 0, 1);
                    }

                    //Wait till write finishes
                    while (t.IsAlive)
                    {
                        System.Threading.Thread.Sleep(100);
                    }

                    Assert.Equal(0, com1.BytesToWrite);

                    //Verify that CtsHolding is true if the RequestToSend or RequestToSendXOnXOff handshake method is used
                    if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) &&
                        !com1.CtsHolding)
                    {
                        Fail("ERROR!!! Expcted CtsHolding={0} actual {1}", true, com1.CtsHolding);
                    }
                }
        }
Ejemplo n.º 21
0
    public bool InOutBufferFilled_Flush_Cycle()
    {
        SerialPort             com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        SerialPort             com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName);
        AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, DEFAULT_BUFFER_SIZE);

        System.Threading.Thread t1 = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        System.Threading.Thread t2 = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        bool retValue    = true;
        int  elapsedTime = 0;

        byte[] xmitBytes = new byte[DEFAULT_BUFFER_SIZE];

        Console.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);

        while (com1.BytesToRead < DEFAULT_BUFFER_SIZE && elapsedTime < MAX_WAIT_TIME)
        {
            System.Threading.Thread.Sleep(50);
            elapsedTime += 50;
        }

        t1.Start();
        elapsedTime = 0;

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

        retValue &= VerifyFlush(com1);

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

        t2.Start();
        elapsedTime = 0;

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

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

        while (com1.BytesToRead < DEFAULT_BUFFER_SIZE && elapsedTime < MAX_WAIT_TIME)
        {
            System.Threading.Thread.Sleep(50);
            elapsedTime += 50;
        }

        retValue &= VerifyFlush(com1);

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

        if (!retValue)
        {
            Console.WriteLine("Err_009!!! Verifying call Flush method after input and output buffer has been filled discarded and filled again FAILED");
        }

        if (com1.IsOpen)
        {
            com1.Close();
        }

        if (com2.IsOpen)
        {
            com2.Close();
        }

        return(retValue);
    }
Ejemplo n.º 22
0
        public void BytesToWriteSuccessive()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndByteArray  asyncWriteRndByteArray = new AsyncWriteRndByteArray(com, BYTE_SIZE_BYTES_TO_WRITE);
                System.Threading.Thread t1 = new System.Threading.Thread(asyncWriteRndByteArray.WriteRndByteArray);
                System.Threading.Thread t2 = new System.Threading.Thread(asyncWriteRndByteArray.WriteRndByteArray);

                int waitTime;

                Debug.WriteLine("Verifying BytesToWrite with successive calls to Write");
                com.Handshake = Handshake.RequestToSend;
                com.Open();
                com.WriteTimeout = 1000;

                //Write a random byte[] asynchronously so we can verify some things while the write call is blocking
                t1.Start();
                waitTime = 0;

                while (t1.ThreadState == System.Threading.ThreadState.Unstarted && waitTime < 2000)
                { //Wait for the thread to start
                    System.Threading.Thread.Sleep(50);
                    waitTime += 50;
                }

                waitTime = 0;
                while (BYTE_SIZE_BYTES_TO_WRITE > com.BytesToWrite && waitTime < 500)
                {
                    System.Threading.Thread.Sleep(50);
                    waitTime += 50;
                }

                if (BYTE_SIZE_BYTES_TO_WRITE != com.BytesToWrite)
                {
                    Fail("ERROR!!! Expcted BytesToWrite={0} actual {1} after first write", BYTE_SIZE_BYTES_TO_WRITE, com.BytesToWrite);
                }

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

                waitTime = 0;
                while (BYTE_SIZE_BYTES_TO_WRITE * 2 > com.BytesToWrite && waitTime < 500)
                {
                    System.Threading.Thread.Sleep(50);
                    waitTime += 50;
                }

                if (BYTE_SIZE_BYTES_TO_WRITE * 2 != com.BytesToWrite)
                {
                    Fail("ERROR!!! Expcted BytesToWrite={0} actual {1} after second write", BYTE_SIZE_BYTES_TO_WRITE * 2, com.BytesToWrite);
                }

                //Wait for both write methods to timeout
                while (t1.IsAlive || t2.IsAlive)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 23
0
        private void Verify_Handshake(Handshake handshake)
        {
            using (var com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
                using (var com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
                {
                    var asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1, s_BYTE_SIZE_HANDSHAKE);
                    var t = new Task(asyncWriteRndByteArray.WriteRndByteArray);

                    var XOffBuffer = new byte[1];
                    var XOnBuffer  = new byte[1];

                    XOffBuffer[0] = 19;
                    XOnBuffer[0]  = 17;

                    Debug.WriteLine("Verifying Handshake={0}", handshake);
                    com1.Handshake = handshake;

                    com1.Open();
                    com2.Open();

                    // Setup to ensure write will bock with type of handshake method being used
                    if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake)
                    {
                        com2.RtsEnable = false;
                    }

                    if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake)
                    {
                        com2.BaseStream.Write(XOffBuffer, 0, 1);
                        Thread.Sleep(250);
                    }

                    // Write a random byte asynchronously so we can verify some things while the write call is blocking
                    t.Start();
                    TCSupport.WaitForTaskToStart(t);
                    TCSupport.WaitForWriteBufferToLoad(com1, s_BYTE_SIZE_HANDSHAKE);

                    // Verify that CtsHolding is false if the RequestToSend or RequestToSendXOnXOff handshake method is used
                    if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) &&
                        com1.CtsHolding)
                    {
                        Fail("ERROR!!! Expected CtsHolding={0} actual {1}", false, com1.CtsHolding);
                    }

                    // Setup to ensure write will succeed
                    if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake)
                    {
                        com2.RtsEnable = true;
                    }

                    if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake)
                    {
                        com2.BaseStream.Write(XOnBuffer, 0, 1);
                    }

                    TCSupport.WaitForTaskCompletion(t);

                    // Verify that the correct number of bytes are in the buffer
                    Assert.Equal(0, com1.BytesToWrite);

                    // Verify that CtsHolding is true if the RequestToSend or RequestToSendXOnXOff handshake method is used
                    if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) &&
                        !com1.CtsHolding)
                    {
                        Fail("ERROR!!! Expected CtsHolding={0} actual {1}", true, com1.CtsHolding);
                    }
                }

            #endregion
        }
Ejemplo n.º 24
0
    private bool BytesToWriteSuccessive()
    {
        SerialPort             com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com);

        System.Threading.Thread t1 = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        System.Threading.Thread t2 = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        bool retValue = true;
        int  waitTime = 0;

        Console.WriteLine("Verifying BytesToWrite with successive calls to Write");

        com.Handshake = Handshake.RequestToSend;
        com.Open();
        com.WriteTimeout = 4000;

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

        waitTime = 0;
        while (com.BytesToWrite < 1 && waitTime < 250)
        {
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        if (1 != com.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite={0} actual {1} after first write", 1, com.BytesToWrite);
        }

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

        waitTime = 0;
        while (com.BytesToWrite < 1 * 2 && waitTime < 250)
        {
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        if (1 * 2 != com.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite={0} actual {1} after second write", 1 * 2, com.BytesToWrite);
        }

        //Wait for both write methods to timeout
        while (t1.IsAlive || t2.IsAlive)
        {
            System.Threading.Thread.Sleep(100);
        }

        if (com.IsOpen)
        {
            com.Close();
        }

        if (!retValue)
        {
            Console.WriteLine("Err_008!!! Verifying BytesToWrite with successive calls to Write FAILED");
        }

        return(retValue);
    }
Ejemplo n.º 25
0
    public bool Verify_Handshake(Handshake handshake)
    {
        SerialPort             com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        SerialPort             com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName);
        AsyncWriteRndByteArray asyncWriteRndByteArray = new AsyncWriteRndByteArray(com1);

        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndByteArray.WriteRndByteArray));
        bool retValue             = true;
        int  waitTime             = 0;

        Console.WriteLine("Verifying Handshake={0}", handshake);
        com1.Handshake = handshake;
        com1.Open();
        com2.Open();

        //Setup to ensure write will bock with type of handshake method being used
        if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake)
        {
            com2.RtsEnable = false;
        }

        if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake)
        {
            com2.BaseStream.WriteByte((byte)19);
            System.Threading.Thread.Sleep(250);
        }

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

        waitTime = 0;
        while (com1.BytesToWrite < 1 && waitTime < 250)
        {
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        //Verify that the correct number of bytes are in the buffer
        if (1 != com1.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite={0} actual {1}", 1, com1.BytesToWrite);
        }

        //Verify that CtsHolding is false if the RequestToSend or RequestToSendXOnXOff handshake method is used
        if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) && com1.CtsHolding)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted CtsHolding={0} actual {1}", false, com1.CtsHolding);
        }

        //Setup to ensure write will succeed
        if (Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake)
        {
            com2.RtsEnable = true;
        }

        if (Handshake.XOnXOff == handshake || Handshake.RequestToSendXOnXOff == handshake)
        {
            com2.BaseStream.WriteByte((byte)17);
        }

        //Wait till write finishes
        while (t.IsAlive)
        {
            System.Threading.Thread.Sleep(100);
        }

        //Verify that the correct number of bytes are in the buffer
        if (0 != com1.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite=0 actual {0}", com1.BytesToWrite);
        }

        //Verify that CtsHolding is true if the RequestToSend or RequestToSendXOnXOff handshake method is used
        if ((Handshake.RequestToSend == handshake || Handshake.RequestToSendXOnXOff == handshake) && !com1.CtsHolding)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted CtsHolding={0} actual {1}", true, com1.CtsHolding);
        }

        if (com1.IsOpen)
        {
            com1.Close();
        }

        if (com2.IsOpen)
        {
            com2.Close();
        }

        return(retValue);
    }