Пример #1
0
        protected virtual void FunctionInitialize()
        {
            FunctionSelected = new Dictionary <string, ProtocolFunc>();
            FunctionSelected[Resources.READ_CURRENT_TROUBLE_CODE] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);
                List <TroubleCode> codes = null;
                Task.Factory.StartNew(() =>
                {
                    Mikuni protocol = new Mikuni(Resources.Commbox, options);
                    codes           = protocol.ReadCurrentTroubleCode();
                }).ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
                    }
                    else
                    {
                        if (this is HJ125T_16APresenter)
                        {
                            Resources.ChangeTroubleCodeFor16A(codes);
                        }
                        else
                        {
                            Resources.ChangeTroubleCodeForNone16A(codes);
                        }
                        TCPresenter.TroubleCodeList = codes;
                        TCPresenter.Show();
                        DlgPresenter.Hide();
                    }
                });
            };

            FunctionSelected[Resources.READ_HISTORY_TROUBLE_CODE] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);
                List <TroubleCode> codes = null;

                Task.Factory.StartNew(() =>
                {
                    Mikuni protocol = new Mikuni(Resources.Commbox, options);
                    codes           = protocol.ReadHistoryTroubleCode();
                }).ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
                    }
                    else
                    {
                        if (this is HJ125T_16APresenter)
                        {
                            Resources.ChangeTroubleCodeFor16A(codes);
                        }
                        else
                        {
                            Resources.ChangeTroubleCodeForNone16A(codes);
                        }
                        TCPresenter.TroubleCodeList = codes;
                        TCPresenter.Show();
                        DlgPresenter.Hide();
                    }
                });
            };

            FunctionSelected[Resources.READ_DATA_STREAM] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);
                Resources.LiveDataVector = Database.GetLiveData("Mikuni");
                DSPresenter.Items        = Resources.LiveDataVector.Items;
                Mikuni protocol = null;

                DSPresenter.ProtocolTask = Task.Factory.StartNew(() =>
                {
                    protocol             = new Mikuni(Resources.Commbox, options);
                    DSPresenter.Protocol = protocol;
                    protocol.ReadDataStream(Resources.LiveDataVector);
                });

                DSPresenter.Show();
                DlgPresenter.Hide();

                DSPresenter.ProtocolTask.ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        if (DSPresenter.Protocol != null)
                        {
                            DSPresenter.Protocol.StopReadDataStream();
                            DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, (sender, e) =>
                            {
                                DSPresenter.Back();
                            });
                        }
                    }
                });
            };

            FunctionSelected[Resources.READ_ECU_VERSION] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);
                Mikuni.ChineseVersion version = new Mikuni.ChineseVersion();
                Task.Factory.StartNew(() =>
                {
                    Mikuni protocol = new Mikuni(Resources.Commbox, options);
                    string hex      = protocol.GetECUVersion();
                    version         = Mikuni.FormatECUVersionForChina(hex);
                }).ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
                    }
                    else
                    {
                        string text = version.Hardware + "\nV" + version.Software;
                        DlgPresenter.ShowFatalBox(text, null);
                    }
                });
            };

            FunctionSelected[Resources.TPS_IDLE_SETTING] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);

                Task.Factory.StartNew(() =>
                {
                    Mikuni protocol = new Mikuni(Resources.Commbox, options);
                    protocol.TPSIdleSetting();
                }).ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
                    }
                    else
                    {
                        DlgPresenter.ShowFatalBox(Resources.TPS_IDLE_SETTING_SUCCESS, null);
                    }
                });
            };

            FunctionSelected[Resources.LONG_TERM_LEARN_VALUE_ZONE_INITIALIZATION] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);

                Task.Factory.StartNew(() =>
                {
                    Mikuni protocol = new Mikuni(Resources.Commbox, options);
                    protocol.LongTermLearnValueZoneInitialization();
                }).ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
                    }
                    else
                    {
                        DlgPresenter.ShowFatalBox(Resources.LONG_TERM_LEARN_VALUE_ZONE_INITIALIZATION_SUCCESS, null);
                    }
                });
            };

            FunctionSelected[Resources.ISC_LEARN_VALUE_INITIALIZATION] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);

                Task.Factory.StartNew(() =>
                {
                    Mikuni protocol = new Mikuni(Resources.Commbox, options);
                    protocol.ISCLearnValueInitialize();
                }).ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
                    }
                    else
                    {
                        DlgPresenter.ShowFatalBox(Resources.ISC_LEARN_VALUE_INITIALIZATION_SUCCESS, null);
                    }
                });
            };
        }
Пример #2
0
        public GW250Presenter()
        {
            Items = new ObservableCollection <MenuItem>();
            Items.Add(new MenuItem(Core.Database.GetText("Read Current Trouble Code", "System"),
                                   "pack://application:,,,/Icons/Read Current Trouble Code.png",
                                   "pack://application:,,,/Icons/Read Current Trouble Code.png"));
            Items.Add(new MenuItem(Core.Database.GetText("Read History Trouble Code", "System"),
                                   "pack://application:,,,/Icons/Read History Trouble Code.png",
                                   "pack://application:,,,/Icons/Read History Trouble Code.png"));
            Items.Add(new MenuItem(Core.Database.GetText("Read Data Stream", "System"),
                                   "pack://application:,,,/Icons/Read Data Stream.png",
                                   "pack://application:,,,/Icons/Read Data Stream.png"));
            Items.Add(new MenuItem(Core.Database.GetText("Read ECU Version", "System"),
                                   "pack://application:,,,/Icons/Read ECU Version.png",
                                   "pack://application:,,,/Icons/Read ECU Version.png"));

            FunctionSelected = new Dictionary <string, ProtocolFunc>();
            FunctionSelected[Resources.READ_CURRENT_TROUBLE_CODE] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);
                List <TroubleCode> codes = null;

                Task.Factory.StartNew(() =>
                {
                    GW250 protocol = new GW250(Resources.Commbox);
                    codes          = protocol.ReadTroubleCode(false);
                }).ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
                    }
                    else
                    {
                        Resources.ChangeTroubleCodeForGW250(codes);
                        TCPresenter.TroubleCodeList = codes;
                        TCPresenter.Show();
                        DlgPresenter.Hide();
                    }
                });
            };

            FunctionSelected[Resources.READ_HISTORY_TROUBLE_CODE] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);
                List <TroubleCode> codes = null;

                Task.Factory.StartNew(() =>
                {
                    GW250 protocol = new GW250(Resources.Commbox);
                    codes          = protocol.ReadTroubleCode(true);
                }).ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
                    }
                    else
                    {
                        Resources.ChangeTroubleCodeForGW250(codes);
                        TCPresenter.TroubleCodeList = codes;
                        TCPresenter.Show();
                        DlgPresenter.Hide();
                    }
                });
            };

            FunctionSelected[Resources.READ_DATA_STREAM] = () =>
            {
                DlgPresenter.ShowStatus(Resources.COMMUNICATING);
                Resources.LiveDataVector = Database.GetLiveData("GW250");
                DSPresenter.Items        = Resources.LiveDataVector.Items;
                GW250 protocol = null;

                DSPresenter.ProtocolTask = Task.Factory.StartNew(() =>
                {
                    protocol             = new GW250(Resources.Commbox);
                    DSPresenter.Protocol = protocol;
                    protocol.ReadDataStream(Resources.LiveDataVector);
                });

                DSPresenter.Show();
                DlgPresenter.Hide();

                DSPresenter.ProtocolTask.ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        if (DSPresenter.Protocol != null)
                        {
                            DSPresenter.Protocol.StopReadDataStream();
                            DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, (sender, e) =>
                            {
                                DSPresenter.Back();
                            });
                        }
                    }
                });
            };
        }