예제 #1
0
        /// <summary>
        /// Считать строки
        /// </summary>
        public override List<string> ReadLines(int timeout, Connection.TextStopCondition stopCond, 
            out bool stopReceived, out string logText)
        {
            try
            {
                List<string> lines = new List<string>();
                stopReceived = false;

                DateTime nowDT = DateTime.Now;
                DateTime startDT = nowDT;
                DateTime stopDT = startDT.AddMilliseconds(timeout);
                SerialPort.ReadTimeout = 0;

                while (!stopReceived && startDT <= nowDT && nowDT <= stopDT)
                {
                    string line;
                    try { line = SerialPort.ReadLine().Trim(); }
                    catch (TimeoutException) { line = ""; }

                    if (line != "")
                    {
                        lines.Add(line);
                        stopReceived = stopCond.CheckCondition(lines, line);
                    }

                    // накопление входных данных в буфере порта
                    if (!stopReceived)
                        Thread.Sleep(DataAccumThreadDelay);

                    nowDT = DateTime.Now;
                }

                logText = BuildReadLinesLogText(lines);
                return lines;
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(CommPhrases.ReadLinesError + ": " + ex.Message, ex);
            }
        }