Exemplo n.º 1
0
        public void ReceivedEvent_Chars()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
                using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
                {
                    ReceivedEventHandler rcvEventHandler = new ReceivedEventHandler(com1);

                    Debug.WriteLine("Verifying ReceivedChars event");

                    com1.Open();
                    com2.Open();
                    com1.DataReceived += rcvEventHandler.HandleEvent;

                    for (int i = 0; i < NUM_TRYS; i++)
                    {
                        com2.Write(new byte[com1.ReceivedBytesThreshold], 0, com1.ReceivedBytesThreshold);
                        rcvEventHandler.WaitForEvent(MAX_TIME_WAIT, 1);

                        rcvEventHandler.Validate(SerialData.Chars, com1.ReceivedBytesThreshold);

                        if (0 != rcvEventHandler.NumberOfOccurencesOfType(SerialData.Eof))
                        {
                            Fail("Err_21087qpua!!! Unexpected EofReceived event fireed {0}", i);
                        }

                        if (0 != rcvEventHandler.NumberOfOccurencesOfType(SerialData.Chars))
                        {
                            Fail("Err_32417!!! Unexpected EofReceived event fireed {0}", i);
                        }

                        com1.DiscardInBuffer();
                    }
                }
        }
Exemplo n.º 2
0
    public bool ReceivedEvent_Chars()
    {
        SerialPort           com1            = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        SerialPort           com2            = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName);
        ReceivedEventHandler rcvEventHandler = new ReceivedEventHandler(com1);
        bool   retValue = true;
        Random rndGen   = new Random(-55);

        Console.WriteLine("Verifying ReceivedChars event");

        com1.Open();
        com2.Open();
        com1.DataReceived += new SerialDataReceivedEventHandler(rcvEventHandler.HandleEvent);

        for (int i = 0; i < NUM_TRYS; i++)
        {
            com2.Write(new byte[com1.ReceivedBytesThreshold], 0, com1.ReceivedBytesThreshold);
            rcvEventHandler.WaitForEvent(MAX_TIME_WAIT, 1);

            if (!rcvEventHandler.Validate(SerialData.Chars, com1.ReceivedBytesThreshold))
            {
                Console.WriteLine("Err_2097asd!!! ReceivedChars Event not fired {0}", i);
                retValue = false;
            }

            if (0 != rcvEventHandler.NumberOfOccurencesOfType(SerialData.Eof))
            {
                Console.WriteLine("Err_21087qpua!!! Unexpected EofReceived event fireed {0}", i);
                retValue = false;
            }

            if (0 != rcvEventHandler.NumberOfOccurencesOfType(SerialData.Chars))
            {
                Console.WriteLine("Err_32417!!! Unexpected EofReceived event fireed {0}", i);
                retValue = false;
            }

            com1.DiscardInBuffer();
        }

        if (!retValue)
        {
            Console.WriteLine("Err_002!!! Verifying ReceivedChars event FAILED");
        }

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

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

        return(retValue);
    }
Exemplo n.º 3
0
        public void ReceivedEvent_CharsEof()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
                using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
                {
                    ReceivedEventHandler rcvEventHandler = new ReceivedEventHandler(com1);

                    byte[] xmitBytes = new byte[3];

                    Debug.WriteLine("Verifying EofReceived event");

                    com1.Open();
                    com2.Open();
                    com1.DataReceived += rcvEventHandler.HandleEvent;

                    //EOF char
                    xmitBytes[0] = 56;
                    xmitBytes[1] = 26;
                    xmitBytes[2] = 55;

                    for (int i = 0; i < NUM_TRYS; i++)
                    {
                        com2.Write(xmitBytes, 0, xmitBytes.Length);
                        rcvEventHandler.WaitForEvent(MAX_TIME_WAIT, SerialData.Eof);

                        rcvEventHandler.Validate(SerialData.Eof, i * xmitBytes.Length);

                        rcvEventHandler.Validate(SerialData.Chars, (i * xmitBytes.Length) + com1.ReceivedBytesThreshold);

                        if (0 != rcvEventHandler.NumberOfOccurencesOfType(SerialData.Eof))
                        {
                            Fail("Err_20712asdfhow!!! Unexpected EofReceived event fired {0} iteration:{1}",
                                 rcvEventHandler.NumberOfOccurencesOfType(SerialData.Eof), i);
                        }

                        rcvEventHandler.Clear();
                    }
                }
        }
Exemplo n.º 4
0
        public void ReceivedEvent_Eof()
        {
            using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
                using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
                {
                    ReceivedEventHandler rcvEventHandler = new ReceivedEventHandler(com1);

                    byte[] xmitBytes = new byte[1];

                    Debug.WriteLine("Verifying EofReceived event");
                    com1.Open();
                    com2.Open();
                    com1.DataReceived += rcvEventHandler.HandleEvent;

                    //EOF char
                    xmitBytes[0] = 26;

                    for (int i = 0; i < NUM_TRYS; i++)
                    {
                        com2.Write(xmitBytes, 0, xmitBytes.Length);
                        rcvEventHandler.WaitForEvent(MAX_TIME_WAIT, 2);

                        rcvEventHandler.Validate(SerialData.Eof, i);

                        rcvEventHandler.Validate(SerialData.Chars, i + com1.ReceivedBytesThreshold);

                        if (0 != rcvEventHandler.NumberOfOccurencesOfType(SerialData.Eof))
                        {
                            Fail("Err_01278qaods!!! Unexpected EofReceived event fireed {0}", i);
                        }

                        if (1 < rcvEventHandler.NumberOfOccurencesOfType(SerialData.Chars))
                        {
                            Fail("Err_2972qoypa!!! Unexpected ReceivedChars event fireed {0}", i);
                        }
                    }
                }
        }
Exemplo n.º 5
0
    public bool ReceivedEvent_CharsEof()
    {
        SerialPort           com1            = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        SerialPort           com2            = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName);
        ReceivedEventHandler rcvEventHandler = new ReceivedEventHandler(com1);
        bool retValue = true;

        byte[] xmitBytes = new byte[3];

        Console.WriteLine("Verifying EofReceived event");

        com1.Open();
        com2.Open();
        com1.DataReceived += new SerialDataReceivedEventHandler(rcvEventHandler.HandleEvent);

        //EOF char
        xmitBytes[0] = 56;
        xmitBytes[1] = 26;
        xmitBytes[2] = 55;

        for (int i = 0; i < NUM_TRYS; i++)
        {
            com2.Write(xmitBytes, 0, xmitBytes.Length);
            rcvEventHandler.WaitForEvent(MAX_TIME_WAIT, SerialData.Eof);

            if (!rcvEventHandler.Validate(SerialData.Eof, i * xmitBytes.Length))
            {
                Console.WriteLine("Err_09727ahsp!!!EOF Event not fired {0}", i);
                retValue = false;
            }

            if (!rcvEventHandler.Validate(SerialData.Chars, (i * xmitBytes.Length) + com1.ReceivedBytesThreshold))
            {
                Console.WriteLine("Err_27928adshs !!!ReceivedChars Event not fired {0}", i);
                retValue = false;
            }

            if (0 != rcvEventHandler.NumberOfOccurencesOfType(SerialData.Eof))
            {
                Console.WriteLine("Err_20712asdfhow!!! Unexpected EofReceived event fired {0} iteration:{1}",
                                  rcvEventHandler.NumberOfOccurencesOfType(SerialData.Eof), i);
                retValue = false;
            }

            rcvEventHandler.Clear();
        }

        if (!retValue)
        {
            Console.WriteLine("Err_3468eadhs!!! Verifying CharsReceived and EofReceived event FAILED");
        }

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

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

        return(retValue);
    }
Exemplo n.º 6
0
    public bool ReceivedEvent_Eof()
    {
        SerialPort           com1            = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        SerialPort           com2            = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName);
        ReceivedEventHandler rcvEventHandler = new ReceivedEventHandler(com1);
        bool retValue = true;

        byte[] xmitBytes = new byte[1];

        Console.WriteLine("Verifying EofReceived event");
        com1.Open();
        com2.Open();
        com1.DataReceived += new SerialDataReceivedEventHandler(rcvEventHandler.HandleEvent);

        //EOF char
        xmitBytes[0] = 26;

        for (int i = 0; i < NUM_TRYS; i++)
        {
            com2.Write(xmitBytes, 0, xmitBytes.Length);
            rcvEventHandler.WaitForEvent(MAX_TIME_WAIT, 2);

            if (!rcvEventHandler.Validate(SerialData.Eof, i))
            {
                Console.WriteLine("Err_1048apqa!!! EofReceived Event not fired {0}", i);
                retValue = false;
            }

            if (!rcvEventHandler.Validate(SerialData.Chars, i + com1.ReceivedBytesThreshold))
            {
                Console.WriteLine("Err_16489qayas!!! ReceivedChars Event not fired {0}", i);
                retValue = false;
            }

            if (0 != rcvEventHandler.NumberOfOccurencesOfType(SerialData.Eof))
            {
                Console.WriteLine("Err_01278qaods!!! Unexpected EofReceived event fireed {0}", i);
                retValue = false;
            }

            if (1 < rcvEventHandler.NumberOfOccurencesOfType(SerialData.Chars))
            {
                Console.WriteLine("Err_2972qoypa!!! Unexpected ReceivedChars event fireed {0}", i);
                retValue = false;
            }
        }

        if (!retValue)
        {
            Console.WriteLine("Err_002!!! Verifying EofReceived event FAILED");
        }

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

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

        return(retValue);
    }