//lineNum = -1 - искать во всех командах
        //lineNum = x - искать в команде на определенной стоке базы
        public static bool FindCommand(int _pos, int lineNum = -1)
        {
            //reset all result values
            ClearCommand();

            if (sourceData.Count < _pos + 1)
            {
                return(false);
            }
            //check if it's a command or reply
            if (sourceData[_pos] == frameStartSign)
            {
                CSVColumns.CommandParameterSize  = 1;
                CSVColumns.CommandParameterType  = 2;
                CSVColumns.CommandParameterValue = 3;
                CSVColumns.CommandDescription    = 4;
                itIsReply = false;
                if (sourceData.Count < _pos + 3)
                {
                    return(false);
                }
            }
            else if (sourceData[_pos] == ackSign || sourceData[_pos] == nackSign)
            {
                itIsReply = true;
                if (sourceData[_pos] == nackSign)
                {
                    itIsReplyNACK = true;
                }
                CSVColumns.CommandParameterSize  = 5;
                CSVColumns.CommandParameterType  = 6;
                CSVColumns.CommandParameterValue = 7;
                CSVColumns.CommandDescription    = 8;
                if (sourceData.Count < _pos + 4)
                {
                    return(false);
                }
                _pos++;
            }
            else
            {
                return(false);
            }

            //select data frame
            commandFrameLength = 0;
            if (sourceData[_pos] == frameStartSign)
            {
                commandFrameLength = sourceData[_pos + 1];
                commandFrameLength = commandFrameLength + sourceData[_pos + 2] * 256;
                _pos += 3;
            }
            else
            {
                return(false);
            }

            //check if "commandFrameLength" less than "sourcedata". note the last byte of "sourcedata" is CRC.
            if (sourceData.Count < _pos + commandFrameLength + 1)
            {
                commandFrameLength = sourceData.Count - _pos;
                lengthIncorrect    = true;
            }

            //find command
            var i = 0;

            if (lineNum != -1)
            {
                i = lineNum;
            }
            if (sourceData.Count < _pos + 1)
            {
                return(false);                             //check if it doesn't go over the last symbol
            }
            for (; i < commandDataBase.Rows.Count; i++)
            {
                if (commandDataBase.Rows[i][CSVColumns.CommandName].ToString() != "")
                {
                    if (sourceData[_pos] ==
                        Accessory.ConvertHexToByte(commandDataBase.Rows[i][CSVColumns.CommandName].ToString())
                        )                                //if command matches
                    {
                        if (lineNum < 0 || lineNum == i) //if string matches
                        {
                            commandName          = commandDataBase.Rows[i][CSVColumns.CommandName].ToString();
                            commandDbLineNum     = i;
                            commandDesc          = commandDataBase.Rows[i][CSVColumns.CommandDescription].ToString();
                            commandFramePosition = _pos;
                            //get CRC of the frame
                            //check length of sourceData
                            int calculatedCRC =
                                Q3xf_CRC(sourceData.GetRange(_pos - 2, commandFrameLength + 2).ToArray(),
                                         commandFrameLength + 2);
                            int sentCRC = sourceData[_pos + commandFrameLength];
                            if (calculatedCRC != sentCRC)
                            {
                                crcFailed = true;
                            }
                            else
                            {
                                crcFailed = false;
                            }
                            //check command height - how many rows are occupated
                            var i1 = 0;
                            while (commandDbLineNum + i1 + 1 < commandDataBase.Rows.Count &&
                                   commandDataBase.Rows[commandDbLineNum + i1 + 1][CSVColumns.CommandName].ToString() ==
                                   "")
                            {
                                i1++;
                            }
                            commandDbHeight = i1;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }