public void BytesToWrite()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, s_STRING_SIZE_BYTES_TO_WRITE);
                var t = new Task(asyncWriteRndStr.WriteRndStr);

                int numNewLineBytes;

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

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

                numNewLineBytes = com.Encoding.GetByteCount(com.NewLine.ToCharArray());

                //Write a random string asynchronously so we can verify some things while the write call is blocking
                t.Start();

                TCSupport.WaitForTaskToStart(t);

                TCSupport.WaitForWriteBufferToLoad(com, s_STRING_SIZE_BYTES_TO_WRITE + numNewLineBytes);

                TCSupport.WaitForTaskCompletion(t);
            }
        }
        public void BytesToWriteSuccessive()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, s_STRING_SIZE_BYTES_TO_WRITE);
                var t1 = new Task(asyncWriteRndStr.WriteRndStr);
                var t2 = new Task(asyncWriteRndStr.WriteRndStr);

                int numNewLineBytes;

                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();
                TCSupport.WaitForTaskToStart(t1);
                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();
                TCSupport.WaitForTaskToStart(t2);
                TCSupport.WaitForWriteBufferToLoad(com, (s_STRING_SIZE_BYTES_TO_WRITE + numNewLineBytes) * 2);

                //Wait for both write methods to timeout
                TCSupport.WaitForTaskCompletion(t1);
                var aggregatedException = Assert.Throws <AggregateException>(() => TCSupport.WaitForTaskCompletion(t2));
                Assert.IsType <IOException>(aggregatedException.InnerException);
            }
        }
Exemple #3
0
    public void Handshake_None()
    {
        using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
        {
            AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, STRING_SIZE_HANDSHAKE);
            Thread           t = new Thread(asyncWriteRndStr.WriteRndStr);

            int waitTime = 0;

            //Write a random string 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
                Thread.Sleep(50);
                waitTime += 50;
            }

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

            Assert.Equal(0, com.BytesToWrite);
        }
    }
Exemple #4
0
    public void BytesToWrite()
    {
        using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
        {
            AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, STRING_SIZE_BYTES_TO_WRITE);
            Thread           t = new Thread(asyncWriteRndStr.WriteRndStr);

            int waitTime = 0;

            Debug.WriteLine("Verifying BytesToWrite with one call to Write");
            com.Handshake = Handshake.RequestToSend;
            com.Open();
            com.WriteTimeout = 500;

            //Write a random string 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
                Thread.Sleep(50);
                waitTime += 50;
            }

            TCSupport.WaitForWriteBufferToLoad(com, STRING_SIZE_BYTES_TO_WRITE);

            //Wait for write method to timeout
            while (t.IsAlive)
            {
                Thread.Sleep(100);
            }
        }
    }
Exemple #5
0
    private bool BytesToWrite()
    {
        SerialPort       com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, STRING_SIZE_BYTES_TO_WRITE);

        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndStr.WriteRndStr));
        bool retValue             = true;
        int  numNewLineBytes;
        int  waitTime = 0;

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

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

        numNewLineBytes = com.Encoding.GetByteCount(com.NewLine.ToCharArray());

        //Write a random string 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 (STRING_SIZE_BYTES_TO_WRITE + numNewLineBytes > com.BytesToWrite && waitTime < 500)
        {
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        if (STRING_SIZE_BYTES_TO_WRITE + numNewLineBytes != com.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite={0} actual {1} after first write", STRING_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);
    }
        public void Handshake_None()
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, s_STRING_SIZE_HANDSHAKE);
                var t = new Task(asyncWriteRndStr.WriteRndStr);

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

                com.Open();
                t.Start();
                TCSupport.WaitForTaskCompletion(t);
                Assert.Equal(0, com.BytesToWrite);
            }
        }
Exemple #7
0
    public void BytesToWrite()
    {
        using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
        {
            AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, STRING_SIZE_BYTES_TO_WRITE);
            Thread           t = new Thread(asyncWriteRndStr.WriteRndStr);

            int numNewLineBytes;
            int waitTime;

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

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

            numNewLineBytes = com.Encoding.GetByteCount(com.NewLine.ToCharArray());

            //Write a random string 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
                Thread.Sleep(50);
                waitTime += 50;
            }

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

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

            //Wait for write method to timeout
            while (t.IsAlive)
            {
                Thread.Sleep(100);
            }
        }
    }
Exemple #8
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);
                }
            }
        }
Exemple #9
0
    public bool Handshake_None()
    {
        SerialPort       com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, STRING_SIZE_HANDSHAKE);

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

        //Write a random string asynchronously so we can verify some things while the write call is blocking
        Console.WriteLine("Case Handshake_None : 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);
    }
Exemple #10
0
    private void Verify_Handshake(Handshake handshake)
    {
        using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
            {
                AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com1, STRING_SIZE_HANDSHAKE);
                Thread           t = new Thread(asyncWriteRndStr.WriteRndStr);

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

                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);
                    Thread.Sleep(250);
                }

                //Write a random string 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
                    Thread.Sleep(50);
                    waitTime += 50;
                }

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

                //Verify that the correct number of bytes are in the buffer
                if (STRING_SIZE_HANDSHAKE != com1.BytesToWrite)
                {
                    Fail("ERROR!!! Expcted BytesToWrite={0} actual {1}", STRING_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)
                {
                    Thread.Sleep(100);
                }

                //Verify that the correct number of bytes are in the buffer
                if (0 != com1.BytesToWrite)
                {
                    Fail("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)
                {
                    Fail("ERROR!!! Expcted CtsHolding={0} actual {1}", true, com1.CtsHolding);
                }
            }
    }
Exemple #11
0
    public bool Verify_Handshake(Handshake handshake)
    {
        SerialPort       com1             = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        SerialPort       com2             = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName);
        AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com1, STRING_SIZE_HANDSHAKE);

        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncWriteRndStr.WriteRndStr));
        bool retValue             = true;

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

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

        int numNewLineBytes;
        int waitTime = 0;

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

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

        numNewLineBytes = com1.Encoding.GetByteCount(com1.NewLine.ToCharArray());

        //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 string 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 (STRING_SIZE_HANDSHAKE + numNewLineBytes > com1.BytesToWrite && waitTime < 500)
        {
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        //Verify that the correct number of bytes are in the buffer
        if (STRING_SIZE_HANDSHAKE + numNewLineBytes != com1.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite={0} actual {1}", STRING_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)
        {
            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.Write(XOnBuffer, 0, 1);
        }

        //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);
    }
Exemple #12
0
    public void BytesToWriteSuccessive()
    {
        using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
        {
            AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, STRING_SIZE_BYTES_TO_WRITE);
            var t1 = new Thread(asyncWriteRndStr.WriteRndStr);
            var t2 = new Thread(asyncWriteRndStr.WriteRndStr);

            int waitTime = 0;

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

            //Write a random string 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
                Thread.Sleep(50);
                waitTime += 50;
            }

            waitTime = 0;

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

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

            //Write a random string 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
                Thread.Sleep(50);
                waitTime += 50;
            }

            waitTime = 0;

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

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

            //Wait for both write methods to timeout
            while (t1.IsAlive || t2.IsAlive)
            {
                Thread.Sleep(100);
            }
        }
    }
Exemple #13
0
    private bool BytesToWriteSuccessive()
    {
        SerialPort       com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com, STRING_SIZE_BYTES_TO_WRITE);

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

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

        //Write a random string 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 (STRING_SIZE_BYTES_TO_WRITE > com.BytesToWrite && waitTime < 500)
        {
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

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

        //Write a random string 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 (STRING_SIZE_BYTES_TO_WRITE * 2 > com.BytesToWrite && waitTime < 500)
        {
            System.Threading.Thread.Sleep(50);
            waitTime += 50;
        }

        if (STRING_SIZE_BYTES_TO_WRITE * 2 != com.BytesToWrite)
        {
            retValue = false;
            Console.WriteLine("ERROR!!! Expcted BytesToWrite={0} actual {1} after second write", STRING_SIZE_BYTES_TO_WRITE * 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);
    }
Exemple #14
0
        private void Verify_Handshake(Handshake handshake)
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
                using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
                {
                    AsyncWriteRndStr asyncWriteRndStr = new AsyncWriteRndStr(com1, STRING_SIZE_HANDSHAKE);
                    var t = new Task(asyncWriteRndStr.WriteRndStr);

                    byte[] XOffBuffer = new byte[1];
                    byte[] 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.Write(XOffBuffer, 0, 1);
                        Thread.Sleep(250);
                    }

                    //Write a random string asynchronously so we can verify some things while the write call is blocking
                    t.Start();
                    TCSupport.WaitForTaskToStart(t);
                    TCSupport.WaitForExactWriteBufferLoad(com1, STRING_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!!! 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
                    TCSupport.WaitForTaskCompletion(t);

                    //Verify that the correct number of bytes are in the buffer
                    if (0 != com1.BytesToWrite)
                    {
                        Fail("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)
                    {
                        Fail("ERROR!!! Expcted CtsHolding={0} actual {1}", true, com1.CtsHolding);
                    }
                }
        }