private void OnMikuniProtocol()
        {
            status = DialogManager.ShowStatus(this, Database.GetText("Communicating", "System"));
            Manager.LiveDataVector = Database.GetLiveData("QingQi");
            for (int i = 0; i < Manager.LiveDataVector.Count; i++)
            {
                if ((Manager.LiveDataVector[i].ShortName == "TS")
                    || (Manager.LiveDataVector[i].ShortName == "ERF")
                    || (Manager.LiveDataVector[i].ShortName == "IS"))
                {
                    Manager.LiveDataVector[i].Enabled = false;
                }
            }
            Core.LiveDataVector vec = Manager.LiveDataVector;
            vec.DeployEnabledIndex();
            vec.DeployShowedIndex();
            task = Task.Factory.StartNew(() =>
            {
                if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                {
                    throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                }
                Diag.MikuniOptions options = new Diag.MikuniOptions();
                options.Parity = Diag.MikuniParity.Even;
                Mikuni protocol = new Mikuni(Manager.Commbox, options);
                protocol.StaticDataStream(vec);
            });

            task.ContinueWith((t) =>
            {
                ShowResult(t);
            });
        }
 protected override void MenuItemInitialize()
 {
     DlgPresenter.ShowStatus(Resources.COMMUNICATING);
     Mikuni.ChineseVersion version = new Mikuni.ChineseVersion();
     
     Task.Factory.StartNew(() => 
     {
         Mikuni protocol = new Mikuni(Resources.Commbox, options);
         string temp = protocol.GetECUVersion();
         version = Mikuni.FormatECUVersionForChina(temp);
     }).ContinueWith((t) => 
     {
         if (t.IsFaulted)
         {
             DlgPresenter.ShowFatalBox(t.Exception.InnerException.Message, null);
             Back();
         }
         else
         {
             DlgPresenter.Hide();
             Items = new ObservableCollection<MenuItem>();
             Items.Add(new MenuItem(Resources.READ_CURRENT_TROUBLE_CODE,
                 READ_CURRENT_TROUBLE_CODE_ICON,
                 READ_CURRENT_TROUBLE_CODE_ICON_S));
             Items.Add(new MenuItem(Resources.READ_HISTORY_TROUBLE_CODE,
                 READ_HISTORY_TROUBLE_CODE_ICON,
                 READ_HISTORY_TROUBLE_CODE_ICON_S));
             Items.Add(new MenuItem(Resources.READ_DATA_STREAM,
                 READ_DATA_STREAM_ICON,
                 READ_DATA_STREAM_ICON_S));
             Items.Add(new MenuItem(Resources.READ_ECU_VERSION,
                 READ_ECU_VERSION_ICON,
                 READ_ECU_VERSION_ICON_S));
             Items.Add(new MenuItem(Resources.TPS_IDLE_SETTING,
                 TPS_IDLE_SETTING_ICON,
                 TPS_IDLE_SETTING_ICON_S));
             if (version.Hardware.Equals("ECU200-A001D") ||
                 version.Hardware.Equals("ECU200-A002") ||
                 version.Software.Equals("ECU200-A003"))
             {
                 Items.Add(new MenuItem(Resources.LONG_TERM_LEARN_VALUE_ZONE_INITIALIZATION,
                     LONG_TERM_LEARNING_VALUE_INITIALIZATION_ICON,
                     LONG_TERM_LEARNING_VALUE_INITIALIZATION_ICON_S));
                 Items.Add(new MenuItem(Resources.ISC_LEARN_VALUE_INITIALIZATION,
                     ISC_LEARN_VALUE_INITIALIZATION_ICON,
                     ISC_LEARN_VALUE_INITIALIZATION_ICON_S));
             }
         }
     });
 }
        private void OnMikuniProtocol()
        {
            List<string> arrays = new List<string>();
            arrays.Add(StaticString.beforeBlank + Database.GetText("Read Trouble Code", "System"));
            arrays.Add(StaticString.beforeBlank + Database.GetText("Clear Trouble Code", "System"));
            arrays.Add(StaticString.beforeBlank + Database.GetText("Read Data Stream", "System"));
            //arrays.Add(StaticString.beforeBlank + Database.GetText("Static Data Stream", "System"));
            //            arrays.Add(Database.GetText("Activity Test"));
            arrays.Add(StaticString.beforeBlank + Database.GetText("TPS Idle Adjustment", "Mikuni"));
            arrays.Add(StaticString.beforeBlank + Database.GetText("ISC Learn Value Initialize", "Mikuni"));
            arrays.Add(StaticString.beforeBlank + Database.GetText("Long Term Learn Value Zone Initialization", "Mikuni"));
            arrays.Add(StaticString.beforeBlank + Database.GetText("ECU Version", "System"));

            funcs = new Dictionary<string, ProtocolFunc>();
            funcs.Add(Database.GetText("Read Trouble Code", "System"), () =>
            {
                Intent intent = new Intent(this, typeof(TroubleCodeActivity));
                intent.PutExtra("Model", model);
                StartActivity(intent);
            }
            ); // Read Trouble Code

            funcs.Add(Database.GetText("Clear Trouble Code", "System"), () =>
            {
                ProgressDialog status = DialogManager.ShowStatus(this, Database.GetText("Clearing Trouble Code, Please Wait", "System")); ;
                AlertDialog fatal;

                Task task = Task.Factory.StartNew(() =>
                {
                    if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                    {
                        throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                    }
                    Diag.MikuniOptions options = new Diag.MikuniOptions();
                    options.Parity = Diag.MikuniParity.Even;
                    Mikuni protocol = new Mikuni(Diag.BoxFactory.Instance.Commbox, options);
                    protocol.ClearTroubleCode();
                });

                task.ContinueWith((t) =>
                {
                    RunOnUiThread(() =>
                    {
                        status.Dismiss();
                        if (t.IsFaulted)
                        {
                            fatal = DialogManager.ShowFatal(this, t.Exception.InnerException.Message, null);
                        }
                        else
                        {
                            fatal = DialogManager.ShowFatal(this, Database.GetText("Clear Trouble Code Finish", "System"), null);
                        }
                    });
                });

            }
            ); // Clear Trouble Code

            funcs.Add(Database.GetText("Read Data Stream", "System"), () =>
            {
                Intent intent = new Intent(this, typeof(DataStreamSelectedActivity));
                intent.PutExtra("Model", model);
                StartActivity(intent);
            }
            ); // Read Data Stream

            //funcs.Add(StaticString.beforeBlank + Database.GetText("Static Data Stream", "System"), () =>
            //{
            //    Manager.LiveDataVector = Database.GetLiveData("Mikuni");
            //    Intent intent = new Intent(this, typeof(StaticDataStreamActivity));
            //    intent.PutExtra("Model", model);
            //    StartActivity(intent);
            //});

            funcs.Add(Database.GetText("Activity Test", "System"), () =>
            {

            }
            ); // Activity Test

            funcs.Add(Database.GetText("ECU Version", "System"), () =>
            {
                ProgressDialog status = DialogManager.ShowStatus(this, Database.GetText("Reading ECU Version, Please Wait", "System"));
                AlertDialog fatal;
                Mikuni.ChineseVersion version = new Mikuni.ChineseVersion();
                Task task = Task.Factory.StartNew(() =>
                {
                    if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                    {
                        throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                    }
                    Diag.MikuniOptions options = new Diag.MikuniOptions();
                    options.Parity = Diag.MikuniParity.Even;
                    Mikuni protocol = new Mikuni(Diag.BoxFactory.Instance.Commbox, options);
                    version = Mikuni.FormatECUVersionForChina(protocol.GetECUVersion());
                });

                task.ContinueWith((t) =>
                {
                    RunOnUiThread(() =>
                    {
                        status.Dismiss();
                        string text = "";
                        if (t.IsFaulted)
                        {
                            fatal = DialogManager.ShowFatal(this, t.Exception.InnerException.Message, null);
                        }
                        else
                        {
							if (model == (Database.GetText("QM200GY-F", "QingQi")))
							{
                                text = "M16-02\n";
                            }
                            else if (model == (Database.GetText("QM200J-3L", "QingQi")))
							{
                                text = "M16-01\n";
							}
                            else if (model == (Database.GetText("QM200-3D", "QingQi")))
							{
                                text = "M16-03\n";
							}
                            text += version.Hardware + "\nV" + version.Software;
                            fatal = DialogManager.ShowFatal(this, text, null);
                        }
                        
                    });
                });
            }
            ); // ECU Version

            funcs.Add(Database.GetText("TPS Idle Adjustment", "Mikuni"), () =>
            {
                ProgressDialog status = DialogManager.ShowStatus(this, Database.GetText("Communicating", "System"));
                AlertDialog fatal;

                Task task = Task.Factory.StartNew(() =>
                {
                    if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                    {
                        throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                    }
                    Diag.MikuniOptions options = new Diag.MikuniOptions();
                    options.Parity = Diag.MikuniParity.Even;
                    Mikuni protocol = new Mikuni(Diag.BoxFactory.Instance.Commbox, options);
                    protocol.TPSIdleSetting();
                });

                task.ContinueWith((t) =>
                {
                    RunOnUiThread(() =>
                    {
                        status.Dismiss();
                        if (t.IsFaulted)
                        {
                            fatal = DialogManager.ShowFatal(this, t.Exception.InnerException.Message, null);
                        }
                        else
                        {
                            fatal = DialogManager.ShowFatal(this, Database.GetText("TPS Idle Setting Success", "Mikuni"), null);
                        }
                    });
                });
            }
            ); // TPS Idle

            funcs.Add(Database.GetText("Long Term Learn Value Zone Initialization", "Mikuni"), () =>
            {
                ProgressDialog status = DialogManager.ShowStatus(this, Database.GetText("Communicating", "System"));
                AlertDialog fatal;

                Task task = Task.Factory.StartNew(() =>
                {
                    if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                    {
                        throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                    }
                    Diag.MikuniOptions options = new Diag.MikuniOptions();
                    options.Parity = Diag.MikuniParity.Even;
                    Mikuni protocol = new Mikuni(Diag.BoxFactory.Instance.Commbox, options);
                    protocol.LongTermLearnValueZoneInitialization();
                });

                task.ContinueWith((t) =>
                {
                    RunOnUiThread(() =>
                    {
                        status.Dismiss();
                        if (t.IsFaulted)
                        {
                            fatal = DialogManager.ShowFatal(this, t.Exception.InnerException.Message, null);
                        }
                        else
                        {
                            fatal = DialogManager.ShowFatal(this, Database.GetText("Long Term Learn Value Zone Initialization Success", "Mikuni"), null);
                        }
                    });
                });
            }
            ); // Long Term

            funcs.Add(Database.GetText("ISC Learn Value Initialize", "Mikuni"), () =>
            {
                ProgressDialog status = DialogManager.ShowStatus(this, Database.GetText("Communicating", "System"));
                AlertDialog fatal;

                Task task = Task.Factory.StartNew(() =>
                {
                    if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                    {
                        throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                    }
                    Diag.MikuniOptions options = new Diag.MikuniOptions();
                    options.Parity = Diag.MikuniParity.Even;
                    Mikuni protocol = new Mikuni(Diag.BoxFactory.Instance.Commbox, options);
                    protocol.ISCLearnValueInitialize();
                });

                task.ContinueWith((t) =>
                {
                    RunOnUiThread(() =>
                    {
                        status.Dismiss();
                        if (t.IsFaulted)
                        {
                            fatal = DialogManager.ShowFatal(this, t.Exception.InnerException.Message, null);
                        }
                        else
                        {
                            fatal = DialogManager.ShowFatal(this, Database.GetText("ISC Learn Value Initialization Success", "Mikuni"), null);
                        }
                    });
                });
            }
            ); // ISC Learn


            ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, arrays);
            ListView.ItemClick += OnItemClick;
        }
        private void OnMikuniProtocol()
        {
            string[] arrays = new string[2];
            arrays[0] = StaticString.beforeBlank + Database.GetText("Read Current Trouble Code", "System");
            arrays[1] = StaticString.beforeBlank + Database.GetText("Read History Trouble Code", "System");
            ListView.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, arrays);
            ListView.SetSelection(currentIndex);
            funcs = new Dictionary<string, ProtocolFunc>();
            funcs[arrays[0].TrimStart(' ')] = () =>
            {
                status = DialogManager.ShowStatus(this, Database.GetText("Communicating", "System"));
                Task task = Task.Factory.StartNew(() =>
                {
                    if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                    {
                        throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                    }
                    Diag.MikuniOptions options = new Diag.MikuniOptions();
                    options.Parity = Diag.MikuniParity.Even;
                    Mikuni protocol = new Mikuni(Diag.BoxFactory.Instance.Commbox, options);
                    codes = protocol.ReadCurrentTroubleCode("QingQi");
                });

				task.ContinueWith((t) => {ShowResult(t, null);});
            };

            funcs[arrays[1].TrimStart(' ')] = () =>
            {
                status = DialogManager.ShowStatus(this, Database.GetText("Communicating", "System"));

                Task task = Task.Factory.StartNew(() =>
                {
                    if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                    {
                        throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                    }
                    Diag.MikuniOptions options = new Diag.MikuniOptions();
                    options.Parity = Diag.MikuniParity.Even;
                    Mikuni protocol = new Mikuni(Diag.BoxFactory.Instance.Commbox, options);
                    codes = protocol.ReadHistoryTroubleCode("QingQi");
                });

				task.ContinueWith((t) => {ShowResult(t, null);});
            };

            ListView.ItemClick += OnItemClickMikuni;
        }
Beispiel #5
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);
                    }
                });
            };
        }
        private void OnMikuniProtocol()
        {
            status = DialogManager.ShowStatus(this, Database.GetText("Communicating", "System"));

            task = Task.Factory.StartNew(() =>
            {
                Manager.LiveDataVector = Database.GetLiveData("QingQi");
                for (int i = 0; i < Manager.LiveDataVector.Count; i++)
                {
                    if ((Manager.LiveDataVector[i].ShortName == "TS")
                        || (Manager.LiveDataVector[i].ShortName == "ERF")
                        || (Manager.LiveDataVector[i].ShortName == "IS"))
                    {
                        Manager.LiveDataVector[i].Enabled = false;
                    }
                }
                PreparePage();
                if (!Manager.Commbox.Close() || !Manager.Commbox.Open())
                {
                    throw new IOException(Database.GetText("Open Commbox Fail", "System"));
                }
                Diag.MikuniOptions options = new Diag.MikuniOptions();
                options.Parity = Diag.MikuniParity.Even;
                mikuni = new Mikuni(Diag.BoxFactory.Instance.Commbox, options);
                mikuni.ReadDataStream(Manager.LiveDataVector);
            });

            task.ContinueWith(ShowFault);
        }