Example #1
0
        /// <summary>
        /// posle prikaz na port, parametry jsou jen pro logovani cisla pokusu
        /// </summary>
        /// <param name="a1"></param>
        /// <param name="a2"></param>
        /// <returns></returns>
        private bool SendCommandBasic(int a1, int a2)
        {
            bool res;

            Logger.Debug($"+ attempt:{a1}.{a2}");
            //lock (lockobj)
            //{
            if (!_sp.IsOpen)
            {
                return(false);
            }

            try
            {
                //odeslat pripraveny command s parametry
                //_sp.Write(_inBuff, 0, BuffLength);

                var wtask = _sp.WriteAsync(_inBuff, BuffLength);
                wtask.Wait(_runConfig.SendCommandTimeOut);

                Thread.Sleep(7);

                Logger.Debug(" -w");

                //kontrola odeslání
                var task = _sp.ReadAsync(11);

                task.Wait(_runConfig.SendCommandTimeOut);

                if (!task.IsCompleted)
                {
                    Logger.Debug(" -timeout");
                    res = false;
                }
                else
                {
                    Logger.Debug(" -ok");
                    _outBuff = task.Result;
                    res      = true;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                res = false;
            }

            res = res && CheckSendOk();
            Logger.Debug($"-");

            return(res);
        }