public void SuccessiveReadTimeoutWithWriteSucceeding()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                Random         rndGen         = new Random(-55);
                AsyncEnableRts asyncEnableRts = new AsyncEnableRts();
                var            t = new Task(asyncEnableRts.EnableRTS);

                com1.WriteTimeout = rndGen.Next(minRandomTimeout, maxRandomTimeout);
                com1.Handshake    = Handshake.RequestToSend;
                com1.Encoding     = new UTF8Encoding();

                Debug.WriteLine("Verifying WriteTimeout={0} with successive call to write method with the write succeeding sometime before its timeout", com1.WriteTimeout);
                com1.Open();

                //Call EnableRTS asynchronously this will enable RTS in the middle of the following write call allowing it to succeed
                //before the timeout is reached
                t.Start();
                TCSupport.WaitForTaskToStart(t);

                try
                {
                    com1.Write(new char[CHAR_SIZE_TIMEOUT], 0, CHAR_SIZE_TIMEOUT);
                }
                catch (TimeoutException)
                {
                }

                asyncEnableRts.Stop();

                TCSupport.WaitForTaskCompletion(t);

                VerifyTimeout(com1);
            }
        }
Example #2
0
    public bool SuccessiveReadTimeoutWithWriteSucceeding()
    {
        SerialPort     com1           = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        Random         rndGen         = new Random(-55);
        AsyncEnableRts asyncEnableRts = new AsyncEnableRts();

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

        com1.WriteTimeout = rndGen.Next(minRandomTimeout, maxRandomTimeout);
        com1.Handshake    = Handshake.RequestToSend;
        com1.Encoding     = new System.Text.UTF8Encoding();

        Console.WriteLine("Verifying WriteTimeout={0} with successive call to write method with the write succeeding sometime before it's timeout", com1.WriteTimeout);
        com1.Open();

        //Call EnableRTS asynchronously this will enable RTS in the middle of the following write call allowing it to succeed
        //before the timeout is reached
        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;
        }

        try
        {
            com1.BaseStream.WriteByte(DEFAULT_BYTE);
        }
        catch (System.TimeoutException)
        {
        }
        catch (System.Exception e)
        {
            Console.WriteLine("The following exception was thrown: {0}", e.GetType());
            retValue = false;
        }

        asyncEnableRts.Stop();

        while (t.IsAlive)
        {
            System.Threading.Thread.Sleep(100);
        }

        retValue &= VerifyTimeout(com1);

        if (!retValue)
        {
            Console.WriteLine("Err_006!!! Verifying WriteTimeout with  successive call to write method FAILED");
            return(false);
        }

        return(true);
    }
Example #3
0
        public void SuccessiveWriteTimeoutSomeData_WriteByte()
        {
            using (var com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var asyncEnableRts = new AsyncEnableRts();
                var t = new Thread(asyncEnableRts.EnableRTS);

                int waitTime;

                com1.Open();
                com1.Handshake = Handshake.RequestToSend;
                Stream stream = com1.BaseStream;
                stream.WriteTimeout = SUCCESSIVE_WriteTimeout_SOMEDATA;

                Debug.WriteLine(
                    "Verifying WriteTimeout={0} with successive call to WriteByte() and some data being received in the first call",
                    stream.WriteTimeout);

                // Call EnableRTS asynchronously this will enable RTS in the middle of the following write call allowing it to succeed
                // before the timeout is reached
                t.Start();
                waitTime = 0;

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

                try
                {
                    stream.WriteByte(DEFAULT_WRITE_BYTE);
                }
                catch (TimeoutException)
                {
                }

                asyncEnableRts.Stop();

                // Wait for the thread to finish
                while (t.IsAlive)
                {
                    Thread.Sleep(50);
                }

                // Make sure there is no bytes in the buffer so the next call to write will timeout
                com1.DiscardInBuffer();

                VerifyTimeout(WriteByte, stream);
            }
        }
Example #4
0
    public bool SuccessiveWriteTimeoutSomeData_WriteByte()
    {
        SerialPort     com1           = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        AsyncEnableRts asyncEnableRts = new AsyncEnableRts();

        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(asyncEnableRts.EnableRTS));
        bool   retValue           = true;
        Stream stream;
        int    waitTime = 0;

        com1.Open();
        com1.Handshake      = Handshake.RequestToSend;
        stream              = com1.BaseStream;
        stream.WriteTimeout = SUCCESSIVE_WriteTimeout_SOMEDATA;

        Console.WriteLine("Verifying WriteTimeout={0} with successive call to WriteByte() and some data being received in the first call", stream.WriteTimeout);

        //Call EnableRTS asynchronously this will enable RTS in the middle of the following write call allowing it to succeed
        //before the timeout is reached
        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;
        }

        try
        {
            stream.WriteByte(DEFAULT_WRITE_BYTE);
        }
        catch (TimeoutException) { }

        asyncEnableRts.Stop();

        //Wait for the thread to finish
        while (t.IsAlive)
        {
            System.Threading.Thread.Sleep(50);
        }

        //Make sure there is no bytes in the buffer so the next call to write will timeout
        com1.DiscardInBuffer();

        retValue &= Eval(VerifyTimeout(new WriteMethodDelegate(WriteByte), stream),
                         "Err_44458ahbp!!! Verifying with with successive call to write method and some data being received in the first call FAILED");

        com1.Close();

        return(retValue);
    }
Example #5
0
        public void SuccessiveReadTimeoutWithWriteSucceeding()
        {
            using (var com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var rndGen         = new Random(-55);
                var asyncEnableRts = new AsyncEnableRts();
                var t = new Thread(asyncEnableRts.EnableRTS);

                int waitTime;

                com1.WriteTimeout = rndGen.Next(minRandomTimeout, maxRandomTimeout);
                com1.Handshake    = Handshake.RequestToSend;
                com1.Encoding     = new UTF8Encoding();

                Debug.WriteLine(
                    "Verifying WriteTimeout={0} with successive call to write method with the write succeeding sometime before it's timeout",
                    com1.WriteTimeout);
                com1.Open();

                // Call EnableRTS asynchronously this will enable RTS in the middle of the following write call allowing it to succeed
                // before the timeout is reached
                t.Start();
                waitTime = 0;

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

                try
                {
                    com1.BaseStream.WriteByte(DEFAULT_BYTE);
                }
                catch (TimeoutException)
                {
                }

                asyncEnableRts.Stop();

                while (t.IsAlive)
                {
                    Thread.Sleep(100);
                }

                VerifyTimeout(com1);
            }
        }
Example #6
0
        public void SuccessiveWriteTimeoutSomeData_WriteByte()
        {
            using (var com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                var asyncEnableRts = new AsyncEnableRts();
                var t = new Task(asyncEnableRts.EnableRTS);

                com1.Open();
                com1.Handshake = Handshake.RequestToSend;
                Stream stream = com1.BaseStream;
                stream.WriteTimeout = SUCCESSIVE_WriteTimeout_SOMEDATA;

                Debug.WriteLine(
                    "Verifying WriteTimeout={0} with successive call to WriteByte() and some data being received in the first call",
                    stream.WriteTimeout);

                // Call EnableRTS asynchronously this will enable RTS in the middle of the following write call allowing it to succeed
                // before the timeout is reached
                t.Start();
                TCSupport.WaitForTaskToStart(t);
                try
                {
                    stream.WriteByte(DEFAULT_WRITE_BYTE);
                }
                catch (TimeoutException)
                {
                }

                asyncEnableRts.Stop();

                TCSupport.WaitForTaskCompletion(t);

                // Make sure there is no bytes in the buffer so the next call to write will timeout
                com1.DiscardInBuffer();

                VerifyTimeout(WriteByte, stream);
            }
        }