Beispiel #1
0
        private TwoStepProtocol WaitForResponse()
        {
            int             timeout  = Timeout;
            TwoStepProtocol result   = TwoStepProtocol.Timeout;
            char            response = (Char)TwoStepProtocol.Timeout;

            do
            {
                if (SerialPort.BufferCount() > 0)
                {
                    response =
                        (Char)(SerialPort.ReadChar().ToString(CultureInfo.InvariantCulture)[0]);
                    timeout = 0;
                }
                else
                {
                    Thread.Sleep(100);
                    timeout -= 100;
                }
            } while (timeout > 0);

            if (response == (Char)TwoStepProtocol.Acknowledge)
            {
                result = TwoStepProtocol.Acknowledge;
            }
            else
            {
                if (response == (Char)TwoStepProtocol.NegativeAcknowledge)
                {
                    result = TwoStepProtocol.NegativeAcknowledge;
                }
            }

            return(result);
        }