示例#1
0
 private bool SuccessRun()
 {
     PublicData.write_info($"OK PASS [{display}]");
     logger.Trace($"Reader Started! (isStopReader=false)");
     Thread.Sleep(200);
     return(true);
 }
示例#2
0
 public static SerialPort WriteRestart(this SerialPort serial, byte[] send, Func <SerialPort> funcInitializer)
 {
     try
     {
         serial.Write(send, 0, send.Length);
     }
     catch (Exception ex)
     {
         logger.Info($"Ошибка={ex.Message}");
         PublicData.write_info($"Завис порт: {ex.Message}");
         bool isRestart = false;
         try
         {
             isRestart = ComRestart();
         } catch (Exception ex2)
         {
             logger.Error(ex2, $"throw {ex2.Message}");
             throw;
         }
         serial = funcInitializer();
         Thread.Sleep(100);
         serial = serial.OpenRestart(funcInitializer);
         serial.Write(send, 0, send.Length);
     }
     return(serial);
 }
示例#3
0
        private void Save()
        {
            if (numericUpDown1.Text != "")
            {
                int size = Convert.ToInt32(numericUpDown1.Text);
                mainForm.changeFontListView(size);

                var set = new SavingManager();
                set.Key(Setting.FontListView).ValueInt = size;
                set.Key(Setting.FileEndProg).Value     = "." + textBoxFileEnd.Text.Trim(' ', '.', '"');
                set.Save();
            }

            IniFile ini = new IniFile(PublicData.configFile);

            if (txtConfigPath.Text.Length == 0)
            {
                ini.RemoveSection(PublicData.configSection);
                PublicData.CustomRootPath = null;
            }
            string oldPath = PublicData.ReadFromFileRootPath();

            if (oldPath == null)
            {
                oldPath = "";
            }
            if (ini.ForceRenameKey(PublicData.configSection, oldPath, txtConfigPath.Text))
            {
                PublicData.CustomRootPath = txtConfigPath.Text;
            }
            ini.SaveShowMessage();
        }
示例#4
0
 private void write(byte[] send)
 {
     if (PublicData.port1)
     {
         if (!port.IsOpen)
         {
             try { port.Open(); }
             catch (Exception ex) { MessageBox.Show(ex.Message + "\n(открываем закрытый порт)"); }
         }
         try
         {
             port.Write(send, 0, send.Length);
             string str = "";
             for (int i = 0; i < send.Length; i++)
             {
                 str += send[i].ToString("X2") + " ";
             }
             PublicData.write_pc(str);
             //File.AppendAllText("log hex.txt", ">>> " + str + Environment.NewLine);
         }
         catch (UnauthorizedAccessException) { PublicData.AutoStart = false; }
         catch (InvalidOperationException) { PublicData.AutoStart = false; }
         catch (Exception ex) { throw; }
     }
 }
示例#5
0
        public FormNewChoice(string pathRoot = null, string pathDisplay = null)
        {
            InitializeComponent();
            this.Text = PublicData.GetVersionProject();

            UpdateFromPath(pathRoot, pathDisplay);
        }
示例#6
0
        public static void Log(this Exception ex, string msg = null)
        {
            string result = ex.Message.prefix(msg);

            logger.ErrorStack(ex, result);
            PublicData.write_info(result);
        }
示例#7
0
        public static bool tcl_usbtest()
        {
            Code.port.DiscardInBuffer();
            Code.port.ReadTimeout = 1500;
            string fail1   = "AB 05 0A DF 4E AB 06 18 01 58 F2";
            string success = "AB 05 0A DF 4E AB 06 18 00 48 D3";

            byte[] answer     = new byte[11];
            string str_answer = "";

            Code.tcl_usbtest();

            Thread.Sleep(300);

            try
            {
                for (int i = 0; i < 11; i++)
                {
                    int bit = Code.port.ReadByte();
                    str_answer += bit.ToString("X2") + " ";
                }
            }
            catch (TimeoutException)
            {
                PublicData.write_tv(" НЕТ ОТВЕТА USB");
                PublicData.write_tv(" Перезагрузите ТВ");
                return(false);
            }

            str_answer = str_answer.Trim();
            PublicData.write_tv(str_answer);

            if (str_answer == success)
            {
                PublicData.write_tv("USB OK");
                Thread.Sleep(300);
                return(true);
            }

            string mes = "USB undefined answer";

            if (str_answer == fail1)
            {
                mes = "USB НЕ ОБНАРУЖЕН";
            }

            string ask   = "USB TEST FAIL.\nПовторить тест?";
            string hz    = "Предупреждение";
            var    otvet = MessageBox.Show(ask, hz, MessageBoxButtons.RetryCancel, MessageBoxIcon.Stop);

            if (otvet == DialogResult.Retry)
            {
                return(tcl_usbtest());
            }
            else
            {
                PublicData.write_tv(mes);
                return(false);
            }
        }
示例#8
0
 public static SerialPort OpenRestart(this SerialPort serial, Func <SerialPort> funcInitializer)
 {
     try
     {
         if (!serial.IsOpen)
         {
             serial.Open();
             logger.Trace($"Успешно открыт {serial.PortName}");
         }
     }
     catch (Exception ex)
     {
         logger.Info($"Ошибка={ex.Message}");
         PublicData.write_info($"{serial.PortName} Error: {ex.Message}");
         bool isRestart = false;
         try
         {
             isRestart = ComRestart();
         } catch (Exception ex2)
         {
             logger.Error(ex2, $"{ex2.Message}");
             throw;
         }
         if (isRestart)
         {
             serial = funcInitializer();
             Thread.Sleep(100);
             serial.Open();
         }
     }
     return(serial);
 }
示例#9
0
        private void btnCreateWBFile_Click(object sender, EventArgs e)
        {
            string fileEnd  = new SavingManager().Key(Setting.FileEndOptions).Value;
            string fileName = "WBSettings" + fileEnd;
            string fullPath = Path.Combine(PublicData.FolderConfigPath, fileName);

            try
            {
                File.CreateText(fullPath).Close();
            }
            catch (Exception ex)
            {
                PublicData.ShowMessage(ex, "Ошибка. Не удалось создать файл.");
                return;
            }
            try
            {
                var set = new SavingManager(Where.custom, fullPath, "WBSettings");
                set.Key(Setting.CoolX);
                set.Key(Setting.CoolY);
                set.Key(Setting.StandartX);
                set.Key(Setting.StandartY);
                set.Key(Setting.WarmX);
                set.Key(Setting.WarmY);
                set.Key(Setting.ToleranceXY);
                set.Key(Setting.Average);
                set.Key(Setting.Green128Below);
                set.Save();
                Process.Start(fullPath);
            }
            catch (Exception ex)
            {
                PublicData.ShowMessage(ex, "Ошибка. Не удалось открыть файл.");
            }
        }
示例#10
0
 private static void Connect_Minolta_0()
 {
     if (PublicData.m_ICa200 == null)
     {
         MessageBox.Show("Не установлен драйвер для Minolta CA-210.\nБаланс белого не будет доступен.",
                         "Driver Minolta CA210 not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
         isConnectedMinolta = false;
         return;
     }
     PublicData.write_info("Подключение к Minolta. Ожидайте...");
     try
     {
         m_ICa200.AutoConnect();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error! Check USB connection please.\n" + ex.Info(),
                         "Can't connect USB CA210", MessageBoxButtons.OK, MessageBoxIcon.Error);
         //this.buttonConnectUSB.Enabled = true;
         isConnectedMinolta = false;
         return;
     }
     Thread.Sleep(50);
     uPowerStatus       = true;
     isConnectedMinolta = true;
     m_ICas             = (ICas)m_ICa200.Cas;
     m_ICa     = (ICa)m_ICas.get_ItemOfNumber(1);
     m_IProbe  = (IProbe)m_ICa.SingleProbe;
     m_IMemory = (IMemory)m_ICa.Memory;
     Thread.Sleep(50);
     loopInit_CA210();
     PublicData.write_info("Подключение Minolta завершенно.");
 }
示例#11
0
        public bool Run()
        {
            bool FirstSelected = false;

            foreach (var todo in ListActionsValues)
            {
                if (ListStringToTest.ContainsKey(todo.Key))
                {
                    bool result = ListStringToTest[todo.Key](todo.Value);
                    if (!result)
                    {
                        return(false);
                    }
                }
                else
                {
                    PublicData.write_pc(string.Format("{0}: \"{1}\" - программа не знает такого пункта. (F4 редактировать - \"{2}\")", display, todo.Key, section.Name));
                    if (!FirstSelected)
                    {
                        PublicData.SetFokusListView(this);
                    }
                    FirstSelected = true;
                }
            }
            PublicData.stopread = false;
            return(true);
        }
示例#12
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);
        }
示例#13
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();
            }
        }
示例#14
0
 public static void write_genr(byte[] send)
 {
     if (PublicData.isPort2)
     {
         genr.Write(send, 0, send.Length);
         PublicData.write_genr(HexStrToStrTxt(HexByteToStrHex(send)));
     }
 }
示例#15
0
        private bool OkCmd(string msg = null)
        {
            string result = Extensions.prefix(msg, "OK", 0);

            if (msg != null)
            {
                PublicData.write_info(result);
            }
            return(true);
        }
示例#16
0
 public static void write(byte[] send)
 {
     if (PublicData.isPort1)
     {
         port = port.OpenRestart(InitializePort1);
         port = port.WriteRestart(send, InitializePort1);
         logger.Trace($"Успешно {port.PortName} port.WriteRestart()");
         PublicData.write_pc(HexByteToStrHex(send) + Environment.NewLine);
     }
 }
示例#17
0
        private static void CreateLog(string incPath, string msg)
        {
            LogUser log  = new LogUser();
            string  path = PublicData.PathDeacreaseByFolder(PublicData.LogsCheckPassPath);

            path = CreatePath(path, incPath, PublicData.placeNumber);
            string fullPath    = Path.Combine(path, DateTime.Now.ToString("yyyy.MM.dd; HH.mm.ss"));
            string contentFile = string.Empty;

            File.WriteAllText(fullPath, string.Format("{1}{0}{0}{2}", Environment.NewLine, msg, contentFile));
            log.Out();
        }
示例#18
0
        static string GetStrForGenerator(string inc, string defaultTim, string defaultPat)
        {
            string section     = "Generator";
            string filend      = new SavingManager().Key(Setting.FileEndOptions).Value;
            var    fileOptions = PublicData.FindFileInTreeBySection(section);

            if (fileOptions == null)
            {
                fileOptions = Path.Combine(PublicData.RootPath, "options" + filend);
                try
                {
                    File.CreateText(fileOptions).Close();
                }
                catch (Exception ex) { ex.Show( ); }
            }

            IniFile ini = new IniFile();

            ini.Load(fileOptions);
            string tim = "";
            string pat = "";

            try
            {
                tim = ini.GetSection(section).GetAddKey(inc + ".tim").Value;
                pat = ini.GetSection(section).GetAddKey(inc + ".pat").Value;
            }
            catch
            {
                var add = ini.AddSection(section);
                add.AddKey(inc + ".tim");
                add.AddKey(inc + ".pat");
                ini.SaveShowMessage(fileOptions);
            }

            if (tim == null || tim == "")
            {
                tim = defaultTim;//81
                ini.SetKeyValue(section, inc + ".tim", defaultTim);
                ini.SaveShowMessage(fileOptions);
            }
            if (pat == null || pat == "")
            {
                pat = defaultPat;//3501
                ini.SetKeyValue(section, inc + ".pat", defaultPat);
                ini.SaveShowMessage(fileOptions);
            }

            string str = "load tim " + tim + ";load pat " + pat + ";run;";

            return(str);
        }
示例#19
0
        private bool FailRun()
        {
            string outputMsg = $"[{display}] - Fail".prefix(failMsg);

            logger.Trace($"{nameof(isTestAutoStart)}={isTestAutoStart}");
            if (!isTestAutoStart)
            {
                PublicData.write_info(outputMsg);
                Ex.Show(outputMsg);
            }
            Thread.Sleep(200);
            return(false);
        }
示例#20
0
        private void buttonOpenFirstTest_Click(object sender, EventArgs e)
        {
            var test = PublicData.GetTest(0);

            if (test != null)
            {
                Process.Start((test).FilePath);
            }
            else
            {
                Ex.Show("Тест не является внешним.\n(или просто не найден)");
            }
        }
示例#21
0
        private bool FailCmd(string incmsg = null)
        {
            if (string.IsNullOrEmpty(failMsg))
            {
                failMsg = incmsg;
            }
            string chat = (incmsg == null) ? "" : (incmsg + Environment.NewLine);

            if (!isTestAutoStart)
            {
                PublicData.write_info(chat);
            }
            return(false);
        }
示例#22
0
 bool Port1_Hex(string str)
 {
     try
     {
         byte[] send = Code.StrToByte(str);
         Code.write(send);
         return(true);
     }
     catch (Exception ex)
     {
         PublicData.write_pc(string.Format("{0}: {1} (F4 редактировать - \"{2}\")", display, ex.Message, section.Name));
         return(false);
     }
 }
示例#23
0
        public static bool tcl_starton()
        {
            Code.port.ReadTimeout = 2000;
            Code.port.DiscardInBuffer();
            string fail1   = "49 6E 70 75 74";
            string fail2   = "AA 5E 46 5E 50";
            string success = "AB 05 0A DF 4E";

            byte[] answer = new byte[5];
            Code.tcl_ps_on();
            Thread.Sleep(200);
            string str_answer = "";

            try
            {
                Code.port.Read(answer, 0, 5);
            }
            catch (TimeoutException)
            {
                PublicData.write_tv(" НЕТ ОТВЕТА StartON. ");
                PublicData.write_tv(" Перезагрузите ТВ");
                PublicData.errormsg("Перезагрузите телевизор  (замените VGA-кабель)",
                                    "Проблема в Телевизоре / VGA-кабеле / программаторе");
                return(false);
            }

            foreach (var bit in answer)
            {
                str_answer += bit.ToString("X2") + " ";
            }

            str_answer = str_answer.Trim();
            PublicData.write_tv(str_answer);

            if (str_answer == fail1 || str_answer == fail2)
            {
                Code.tcl_cmd_on();
                Thread.Sleep(200);
                return(tcl_starton());
            }
            else if (str_answer != success)
            {
                PublicData.write_tv("StartON FAIL");
                return(false);
            }
            Code.tcl_volume(SoundVolumeAdjust());
            Thread.Sleep(300);
            return(true);
        }
示例#24
0
        public static string FindFileInTreeBySection(string section)
        {
            var path = PublicData.FolderConfigPath;

            while (path.Contains(PublicData.RootPath))
            {
                string found = FindFileInFolderBySection(section, path);
                if (found != null)
                {
                    return(found);
                }
                path = PublicData.PathDeacreaseByFolder(path);
            }
            return(null);
        }
示例#25
0
        public static string FindFileInTreeByName(string fileName)
        {
            var path = PublicData.FolderConfigPath;

            while (path.Contains(PublicData.RootPath))
            {
                var found = FindFileInFolderByName(fileName, path);
                if (found != null)
                {
                    return(found);
                }
                path = PublicData.PathDeacreaseByFolder(path);
            }
            return(null);
        }
示例#26
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($"Синхронизация конфигов завершена.");
        }
示例#27
0
 private static bool RestartRedratDevice()
 {
     try
     {
         DeviceManagerApi.ToogleRedRat(false);
         Thread.Sleep(100);
         DeviceManagerApi.ToogleRedRat(true);
         Thread.Sleep(50);
         return(true);
     } catch (Exception ex)
     {
         logger.Error(ex, ex.Message);
         PublicData.write_info($"Не удалось перезапустить Redrat - придется сделать это вручную.\n{ex.Message}");
         return(false);
     }
 }
示例#28
0
        public static IniFileList.IniSectionList FindSectionInTreeBySection
            (string section, bool duplicate = false)
        {
            var path = PublicData.FolderConfigPath;

            while (path.Contains(PublicData.RootPath))
            {
                IniFileList.IniSectionList found = FindSectionInFolderBySection(section, path, true);
                if (found != null)
                {
                    return(found);
                }
                path = PublicData.PathDeacreaseByFolder(path);
            }
            return(null);
        }
示例#29
0
        public static bool sound(string fileName)
        {
            PlayerSound.Stop();
            string file = PublicData.FindFileInTreeByName(fileName);

            try
            {
                PlayerSound = new System.Media.SoundPlayer(file);
                PlayerSound.Play();
                return(true);
            }
            catch
            {
                Ex.Show("Не найден файл " + fileName);
                return(false);
            }
        }
示例#30
0
 private static bool ComRestart(SerialPort serial)
 {
     try
     {
         serial.Close();
         DeviceManagerApi.ToogleComPortDevice(serial, false);
         Thread.Sleep(100);
         DeviceManagerApi.ToogleComPortDevice(serial, true);
         Thread.Sleep(100);
         return(true);
     } catch (Exception ex)
     {
         logger.Error(ex, $"{serial.PortName}: {ex.Message}");
         PublicData.write_info($"Не удалось перезапустить порт {serial.PortName} ({ex.Message}) - придется сделать это вручную.");
         return(false);
     }
 }