Ejemplo n.º 1
0
        private HexString ReadPortIncomes()
        {
            Thread.Sleep(200);
            int gotbytes = 0;

            Ex.Try(() =>
                   { gotbytes = Code.port.BytesToRead; });
            logger.Trace($"gotbytes={gotbytes}");
            var gotPortIncome = new HexString();

            try
            {
                for (int i = 0; i < gotbytes; i++)
                {
                    int bit = Code.port.ReadByte();
                    gotPortIncome.AddByte(bit);
                }
            }
            catch (TimeoutException ex)
            { logger.Error(ex, ex.Message); }
            catch (Exception ex)
            { logger.Error(ex, ex.Message); }

            if (!isTestAutoStart)
            {
                PublicData.write_tv("text =  " + gotPortIncome.TxtNiceDisplay);
                PublicData.write_tv("code =  " + gotPortIncome.HexNiceDisplay);
            }
            logger.Trace($"COM Read Txt: {gotPortIncome.TxtNiceDisplay}");
            logger.Trace($"COM Read Bin: {gotPortIncome.HexNiceDisplay}");
            UsePrevRead    = true;
            LastPortIncome = gotPortIncome;
            return(gotPortIncome);
        }
Ejemplo n.º 2
0
        private static void CheckTestsPass_CopyWithError(string file, string oldPath, string msg)
        {
            LogUser log = new LogUser();

            try
            {
                string newPath = PublicData.PathDeacreaseByFolder(PublicData.LogsCheckPassPath);
                newPath = Path.Combine(newPath, "#Fails_checkpass");
                newPath = Path.Combine(newPath, PublicData.placeNumber);
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                newPath = Path.Combine(newPath, file);
                string contentFile = string.Empty;
                Ex.Try(() =>
                {
                    File.Copy(oldPath, newPath, true);
                    contentFile = File.ReadAllText(newPath);
                });
                File.WriteAllText(newPath, string.Format("{1}{0}{0}{2}", Environment.NewLine, msg, contentFile));
            }
            finally
            {
                log.Out();
            }
        }
Ejemplo n.º 3
0
        private static bool CheckReadyToWork()
        {
            bool repeat = true;

            while (repeat)
            {
                repeat = false;
                //TaskEx.Delay(300);
                Thread.Sleep(300);
                Ex.Try(() =>
                {
                    Measure();
                });
                if (!measureSuccess)
                {
                    if (LastPortAnswer == "") //no responce, cuz wait for calibration
                    {
                        MessageBox.Show("Нет ответа. Возможно нужно провести калибровку.\n\nПереключите пробник в режим \"0-CAL\"",
                                        "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        if (Cal0())
                        {
                            repeat = true;
                            continue;
                        }
                    }
                    if (LastPortAnswer.Contains("4532320d"))  //E22 Too Dark, 0-Cal enabled
                    {
                        DialogResult answer = MessageBox.Show("Слишком темно. Переключите пробник в режим измерения \"MEAS\"",
                                                              "Ошибка яркости", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                        if (answer == DialogResult.OK)
                        {
                            repeat = true;
                        }
                    }
                    if (LastPortAnswer.Contains("4f4b30300d")) //ok.
                    {
                        DialogResult answer = MessageBox.Show("Переключите пробник в режим измерения \"MEAS\"",
                                                              "Ошибка режима измерения", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                        if (answer == DialogResult.OK)
                        {
                            repeat = true;
                        }
                    }
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        public static async Task UpdateFromNetToLocalConfig()
        {
            if (string.IsNullOrEmpty(PublicData.CustomRootPath))
            {
                return;
            }
            if (!Directory.Exists(PublicData.CustomRootPath))
            {
                var msg = $"Указанный путь не существует: {PublicData.CustomRootPath}";
                Ex.Show(msg);
                PublicData.write_info(msg);
                return;
            }
            PublicData.write_info($"Началась синхронизация конфигов...");
            //copy from network to local
            string localRoot = Environment.CurrentDirectory;
            var    fromCopy  = Directory.EnumerateFiles(PublicData.CustomRootPath, "*", SearchOption.AllDirectories);
            await TaskEx.Run(() => Parallel.ForEach(fromCopy, tab =>
            {
                var where = tab.Replace(PublicData.CustomRootPath, localRoot);
                var dir   = new FileInfo(where).DirectoryName;
                Ex.Try(() =>
                {
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    File.Copy(tab, where, true);
                });
            }));

            //delete local tests
            var pathLocalTests  = Path.Combine(localRoot, testsFolder);
            var pathNetTests    = Path.Combine(PublicData.CustomRootPath, testsFolder);
            var filesLocalTests = Directory.EnumerateFiles(pathLocalTests, "*", SearchOption.AllDirectories);
            var filesNetTests   = Directory.EnumerateFiles(pathNetTests, "*", SearchOption.AllDirectories);
            var whereToFind     = new List <string>(filesNetTests);
            await TaskEx.Run(() => Parallel.ForEach(filesLocalTests, localFile =>
            {
                var fileToFind = localFile.Replace(localRoot, PublicData.CustomRootPath);
                if (!whereToFind.Contains(fileToFind))
                {
                    Ex.Try(() => File.Delete(localFile));
                }
            }));

            PublicData.write_info($"Синхронизация конфигов завершена.");
        }
Ejemplo n.º 5
0
        private void ReadPortIncomesAsync(string find)
        {
            SerialDataReceivedEventHandler eventName;
            var incomePortMethod = new HexString();

            eventName = (o, e) =>
            {
                int gotbytes = 0;
                Ex.Try(() =>
                       { gotbytes = Code.port.BytesToRead; });
                logger.Trace($"gotbytes={gotbytes}");
                var incomePortEvent = new HexString();
                try
                {
                    for (int i = 0; i < gotbytes; i++)
                    {
                        int bit = Code.port.ReadByte();
                        incomePortEvent.AddByte(bit);
                    }
                }
                catch (Exception ex)
                { ex.Log(); }
                if (!isTestAutoStart)
                {
                    PublicData.write_tv("text =  " + incomePortEvent.TxtNiceDisplay);
                    PublicData.write_tv("code =  " + incomePortEvent.HexNiceDisplay);
                }
                logger.Trace($"COM Read Txt: {incomePortEvent.TxtNiceDisplay}");
                logger.Trace($"COM Read Bin: {incomePortEvent.HexNiceDisplay}");
                UsePrevRead      = true;
                incomePortMethod = incomePortEvent;
            };
            try
            {
                Code.port.DataReceived += eventName;
            }
            finally
            {
                Code.port.DataReceived -= eventName;
            }
        }
Ejemplo n.º 6
0
        //private static Task PortReaderThread = Ex.TaskEmpty;
        public static async Task PortReaderOld()
        {
            while (!PublicData.isStopReader)
            {
                if (port.IsOpen)
                {
                    int gotbytes = 0;
                    Ex.Try(() =>
                           { gotbytes = Code.port.BytesToRead; });
                    try
                    {
                        if (gotbytes > 0)
                        {
                            await TaskEx.Run(() =>
                            {
                                logger.Trace($"gotbytes (to read) = {gotbytes}");
                                string hex = "";
                                string txt = "";
                                for (int i = 0; i < gotbytes; i++)
                                {
                                    int bit = Code.port.ReadByte();
                                    txt    += ((char)bit).ToString();
                                    hex    += bit.ToString("X2") + " ";
                                }
                                string hexanswer = hex;
                                string answer    = PublicData.pred_answer + hex;
                                logger.Trace($"got answer(txt)={txt}");
                                logger.Trace($"got answer(hex)={hex.trySubstring(30)}");
                                #region TCL
                                if (answer.Length >= 15)
                                {
                                    if (find(answer, "AB 05 0A DF 4E", hex, out hex))
                                    {
                                        PublicData.write_tv("PASS comand" + Environment.NewLine + Environment.NewLine);
                                    }
                                    if (find(answer, "AB 05 0E 9F CA", hex, out hex))
                                    {
                                        PublicData.write_tv("NOT Correct comand" + Environment.NewLine + Environment.NewLine);
                                    }
                                    if (find(answer, "AB 05 0F 8F EB", hex, out hex))
                                    {
                                        PublicData.write_tv("CRC16 FAILED" + Environment.NewLine + Environment.NewLine);
                                    }
                                }

                                if (answer.Length >= 18)
                                {
                                    if (find(answer, "AB 06 77 00 53 C7", hex, out hex))
                                    {
                                        PublicData.set_key("Power"); //Power
                                    }
                                    if (find(answer, "AB 06 77 01 43 E6", hex, out hex))
                                    {
                                        PublicData.set_key("Menu"); //Menu
                                    }
                                    if (find(answer, "AB 06 77 02 73 85", hex, out hex))
                                    {
                                        PublicData.set_key("Vol+"); //Vol+
                                    }
                                    if (find(answer, "AB 06 77 03 63 A4", hex, out hex))
                                    {
                                        PublicData.set_key("Vol-"); //Vol-
                                    }
                                    if (find(answer, "AB 06 77 04 13 43", hex, out hex))
                                    {
                                        PublicData.set_key("P+"); //P+
                                    }
                                    if (find(answer, "AB 06 77 05 03 62", hex, out hex))
                                    {
                                        PublicData.set_key("P-"); //P-
                                    }
                                    if (find(answer, "AB 06 77 06 33 01", hex, out hex))
                                    {
                                        PublicData.set_key("OK"); //OK
                                    }
                                    if (find(answer, "AB 07 C3 01 01 DA", hex, out hex))
                                    {
                                        PublicData.write_tv("CLONE SUCCESS");
                                    }
                                    if (find(answer, "AB 07 C3 01 00 CA", hex, out hex))
                                    {
                                        PublicData.write_tv("CLONE FAIL");
                                    }
                                }

                                if (answer.Length >= 27)
                                {
                                    if (find(answer, "4E 6F 20 75 73 62 20 64 69", hex, out hex))
                                    {
                                        PublicData.cancel_keyform();
                                    }
                                    if (find(answer, "63 75 73 74 6f 6d 20 36 30", hex, out hex))
                                    {
                                        Code.tcl_tv();
                                    }
                                }
                                #endregion
                                #region Blaupunkt

                                if (answer.Length >= 18)
                                {
                                    if (find(answer, "EE 05 FD 04 00 FA", hex, out hex))
                                    {
                                        PublicData.set_key("vol-"); //Vol-
                                    }
                                    if (find(answer, "EE 05 26 01 00 D4", hex, out hex))
                                    {
                                        PublicData.set_key("vol+"); //Vol+
                                    }
                                    if (find(answer, "EE 05 26 02 00 D3", hex, out hex))
                                    {
                                        PublicData.set_key("ch-"); //Ch-
                                    }
                                    if (find(answer, "EE 05 26 03 00 D2", hex, out hex))
                                    {
                                        PublicData.set_key("ch+"); //Ch+
                                    }
                                    if (find(answer, "EE 05 FD 01 00 FD", hex, out hex))
                                    {
                                        PublicData.set_key("menu"); //Menu
                                    }
                                    if (find(answer, "EE 05 26 04 00 D1", hex, out hex))
                                    {
                                        PublicData.set_key("source"); //Source
                                    }
                                    if (find(answer, "EE 05 FD 03 00 FB", hex, out hex))
                                    {
                                        PublicData.set_key("power"); //Power
                                    }
                                }
                                #endregion
                                #region ktc Buttons
                                if (find(answer, "65 65 30 35 32 36 30 34 30 30 64 31 0D 0A", hex, out hex))
                                {
                                    PublicData.set_key("source"); //source
                                }
                                if (find(answer, "65 65 30 35 32 36 30 34 30 30 64 32 0D 0A", hex, out hex))
                                {
                                    PublicData.set_key("ch+"); //ch+
                                }
                                if (find(answer, "65 65 30 35 32 36 30 34 30 30 64 33 0D 0A", hex, out hex))
                                {
                                    PublicData.set_key("ch-"); //ch-
                                }
                                if (find(answer, "65 65 30 35 66 64 30 31 30 30 66 34 0D 0A", hex, out hex))
                                {
                                    PublicData.set_key("vol+"); //vol+
                                }
                                if (find(answer, "65 65 30 35 66 64 30 31 30 30 66 61 0D 0A", hex, out hex))
                                {
                                    PublicData.set_key("vol-"); //vol-
                                }
                                if (find(answer, "65 65 30 35 66 64 30 31 30 30 66 64 0D 0A", hex, out hex))
                                {
                                    PublicData.set_key("menu"); //menu
                                }
                                if (find(answer, "65 65 30 35 66 64 30 33 30 30 66 62 0D 0A", hex, out hex))
                                {
                                    PublicData.set_key("power"); //power
                                }
                                #endregion
                                #region KTC Remote
                                if (find(answer, "0d 0a 30 78 42 28", hex, out hex))
                                {
                                    PublicData.set_key("вверх"); //up
                                }
                                if (find(answer, "0d 0a 30 78 44 28", hex, out hex))
                                {
                                    PublicData.set_key("OK"); //ok
                                }
                                if (find(answer, "0d 0a 30 78 45 28", hex, out hex))
                                {
                                    PublicData.set_key("Вниз"); //down
                                }
                                if (find(answer, "75 38 4f 70 4e 75 6d 28", hex, out hex))
                                {
                                    PublicData.set_key("вверх"); //up
                                }
                                #endregion
                                PublicData.pred_answer = hex;

                                //if (hexanswer.Length > 105)
                                //    hexanswer = hexanswer.Substring(0, 105);
                                hexanswer.trySubstring(0, 105);
                                PublicData.write_tv("text = " + txt + Environment.NewLine);
                                PublicData.write_tv("code = " + hexanswer + Environment.NewLine);
                            });
                        }
                    }
                    catch { }
                }
                await TaskEx.Delay(500);
            }
        }
Ejemplo n.º 7
0
        bool CheckTestsPass(string str)
        {
            string funcName = $"<{nameof(CheckTestsPass)}>";

            if (PublicData.IDDataTV == null)
            {
                return(FailCmd("Нет записанных данных в память программы"));
            }
            if (!Directory.Exists(PublicData.LogsCheckPassPath))
            {
                return(FailCmd("Не доступна папка логов тестов."));
            }
            //PublicData.IDDataTV = "13test";
            string file = "ps" + PublicData.IDDataTV + ".txt";
            string path = Path.Combine(PublicData.LogsCheckPassPath, file);

            try
            {
                string name           = funcReadBetween(str, "[", "]");
                var    keysWhatToFind = section.IniFile.GetSection(name).Keys;

                if (!File.Exists(path))
                {
                    string msg = $"Файл не найден \"{path}\"";
                    CheckTestsPass_CopyWithError(file, path, msg);
                    return(FailCmd(funcName + msg));
                }
                var iniWhereToFind = new IniFile(path);
                foreach (IniFileList.IniSectionList.IniKey keyToFind in keysWhatToFind)
                {
                    string pass = iniWhereToFind.GetKeyValue(PublicData.IDDataTV.Txt, keyToFind.Name); //.Trim().ToLower();
                    pass = pass?.ToLower();                                                            //.Trim();
                    if (pass != "ok")
                    {
                        Ex.Try((Action)(() =>
                        {
                            logger.Trace($"1) pass != 'ok' = {pass?.ToString() ?? "null"}");
                            logger.Trace($"start search at inBuiltTests");
                            var funcToFind = Form1.InBuiltTests[keyToFind.Name];
                            var keysWhereToFind = iniWhereToFind.GetSection(PublicData.IDDataTV.Txt).Keys;

                            foreach (IniFile.IniSection.IniKey logkey in keysWhereToFind)
                            {
                                bool found = false;
                                Ex.Try(() =>
                                {
                                    if (funcToFind == Form1.InBuiltTests[logkey.Name])
                                    {
                                        pass = logkey.Value.ToLower();
                                        found = true;
                                    }
                                });
                                if (found)
                                {
                                    break;
                                }
                            }
                        }));
                        if (pass != "ok")
                        {
                            logger.Trace($"2) pass != 'ok' = {pass?.ToString() ?? "null"}");
                            logger.Trace($"after inBuiltTests search");
                            string msg1    = "";
                            string display = "";
                            if (Form1.InBuiltTests.ContainsKey(keyToFind.Name))
                            {
                                display = Form1.InBuiltTests[keyToFind.Name].DisplayName;
                            }
                            if (Form1.CreatedDisplays.ContainsKey(keyToFind.Name))
                            {
                                display = Form1.CreatedDisplays[keyToFind.Name];
                            }
                            msg1 = (pass == null)
                                ? $"\"{display}\" not found!{Environment.NewLine}<{keyToFind.Name}>"
                                : $"\"{display}\" = Fail.{Environment.NewLine}<{keyToFind.Name}>";
                            logger.Trace(msg1);
                            CheckTestsPass_CopyWithError(file, path, msg1);
                            return(FailCmd(funcName + msg1));
                        }
                    }
                }
                return(OkCmd(funcName));
            }
            catch (Exception ex)
            {
                return(FailCmd(ex, funcName));
            }
            finally
            {
                Ex.Try(() => File.Delete(path));
                PublicData.IDDataTV = null;
            }
        }