public void FlashDevice(DeviceTicket Ticket, CanPort port, FirmwaringProgressViewModel GlobalProgress, FirmwaringProgressViewModel LocalProgress)
        {
            _logger.Info("-----");
            _logger.Info("Подключаемся к {0}", Ticket);
            PostProgress(GlobalProgress,
                         string.Format("Подключение к модулю (№{0}/{1})...", Ticket.BlockSerialNumber, Ticket.Channel));

            using (CanProg session = CanProg.Connect(port, Ticket))
            {
                _logger.Info("Подключились и начинаем передачу прошивки на {0}", Ticket);
                PostProgress(GlobalProgress, "Передача прошивки {0:P0}", 0);

                var updater = new ComponentUpdater(
                    session);
                updater.SynchronizeComponent(Component, Information, GlobalProgress, LocalProgress);
                PostProgress(GlobalProgress, "Применение изменений...");
                SubmitAckStatus submitStatus = session.Submit(SubmitStatus.Submit);
                _logger.Info("Завершили программирование {0}, статус: {1}", Ticket, submitStatus);
                if (submitStatus != SubmitAckStatus.SubmitSuccessed)
                    throw new SubmitFailsException();
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            CanProg.Logs = new List<ICanProgLog>() { new ConsoleLogger(ConsoleColor.Yellow), new FileLogger("log.txt") };
            //try
            //{

            CanProg.Logs.PushTextEvent("----- STARTED ------");

            using (var appidev = Communications.Appi.Winusb.WinusbAppiDev.GetDevices().First().OpenDevice(true))
            {
                var p = appidev.CanPorts[Communications.Appi.AppiLine.Can1];
                p.Received += p_Recieved;

                //Console.WriteLine("ТЫ ГОТОВ???");
                //Console.ReadLine();
                //var vokak = Enumerable.Range(5, 1000).Select(i => Communications.Can.CanFrame.NewWithId(0x14, BitConverter.GetBytes(i))).ToList();
                //p.Send(vokak);
                //Console.WriteLine("ВОТ ТАК ДА!!!!");
                //Console.ReadLine();
                //return;

                //Console.ReadLine();

                #region Autodetect
                var dt = new DeviceTicket();
                var devices = DeviceLocator.LocateDevices(dt, p);
                ConsoleLogger.Print(() =>
                    {
                        Console.WriteLine("Обнаружено {0} устройств:", devices.Count);
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        foreach (var устройство in devices)
                            Console.WriteLine("    {0}", устройство);
                        Console.ResetColor();
                    });

                //var ticket = devices.First();
                #endregion

                // !!!!!!!!!!!!!!!!!!!!!!!
                var ticket =
                    new DeviceTicket(
                        BlockId: 3,
                        Modification: 1,
                        Module: 1,
                        Channel: 1,
                        BlockSerialNumber: 10056);

                using (var flow = new Communications.Can.CanFlow(p, CanProg.FuDev, CanProg.FuInit, CanProg.FuProg))
                {
                    try
                    {
                        flow.Clear();
                        var progger = CanProg.Connect(flow, ticket);

                        PrintFileList(progger);
                        PrintProperties(progger);

                        //progger.Erase();
                        //System.Threading.Thread.Sleep(4000);

                        DirectoryInfo flashdir = new DirectoryInfo("flash");
                        if (flashdir.Exists)
                        {
                            var firmware = flashdir
                                        .EnumerateFiles("*." + FirmwarePacking.FirmwarePackage.FirmwarePackageExtension)
                                        .Select(f => FirmwarePacking.FirmwarePackage.Open(f))
                                        .Where(fw => fw.Components.SelectMany(c => c.Targets).Any(t => ComponentUpdater.CanApply(t, ticket)))
                                        .OrderByDescending(fw => fw.Information.FirmwareVersion)
                                        .FirstOrDefault();

                            if (firmware != null)
                            {
                                var component = firmware.Components.First(c => c.Targets.Any(t => ComponentUpdater.CanApply(t, ticket)));

                                var updater = new ComponentUpdater(progger, new ConsoleLogger(ConsoleColor.Blue));
                                DateTime t1 = DateTime.Now;
                                updater.SynchronizeComponent(component, firmware.Information);
                                var deltaT = (DateTime.Now - t1);
                                ConsoleLogger.Print(() =>
                                    {
                                        Console.ForegroundColor = ConsoleColor.Yellow;
                                        Console.WriteLine();
                                        Console.WriteLine("Время передачи: {0:F3} сек.", deltaT.TotalSeconds);
                                        Console.WriteLine("Скорость: {0:N0} Б/сек", component.Files.Sum(fl => fl.Content.Length) / deltaT.TotalSeconds);
                                        Console.ResetColor();
                                    });
                            }
                        }
                        PrintFileList(progger);
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine("Готово");
                        Console.ResetColor();
                    }
                    catch (CanProgLimitConnectException connectionLimitException)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(connectionLimitException.Message);
                        Console.ResetColor();
                    }
                    //catch (Exception ex)
                    //{
                    //    Console.ForegroundColor = ConsoleColor.Red;
                    //    Console.WriteLine(ex.Message);
                    //    Console.ResetColor();
                    //}
                }
            }
            //}
            //catch (Exception exc)
            //{
            //    Console.ForegroundColor = ConsoleColor.Red;
            //    Console.WriteLine(exc.Message);
            //    Console.ResetColor();
            //}

            Console.WriteLine();
            Console.WriteLine("Нажмите любую клавишу для завершения...");
            Console.Read();
        }