Example #1
0
        /// <summary>
        /// Metoda wywolywana aby uruchomic Ambi
        /// </summary>
        private void Action_Start()
        {
            if (serialDeviceController.DeviceConnected)                       // Jesli juz jestesmy podlaczeniu to chcemy uruchomic Ambi wczesniej skonfigurowane
            {
                ToggleButton_Start.Content   = "Stop";                        // Zmieniamy napis na guziku
                isRGBdataAqquireRunning      = true;                          // Zmieniamy status naszej flagi
                Stop_Data_Aqquire            = false;                         // Zmieniamy flage aby Ambi nie wysylalo danych
                TextBlock_StatusBar_1.Text   = " Connected | Running";
                ToggleButton_Start.IsEnabled = !ToggleButton_Start.IsEnabled; // Toggle button state
            }
            else
            {
                #region Jesli musimy wyszukac nasze urzadzenie
                if (String.IsNullOrEmpty(ApplicationProfile.LastCOMconnected))                    // Czy juz kiedys sie podlaczalismy do urzadzenia ?
                {
                    TextBlock_StatusBar_1.Text = "Searching for device...";                       // Wyswietl informacje ze szukamy urzadzenia

                    if (serialDeviceController.SearchForConnectedDevice("A1"))                    // Czy znalazles urzadzenie posrod wszystkich COM
                    {
                        TextBlock_StatusBar_1.Text = "Found! Connecting...";                      // Wyswietl informacje ze sie podlaczamy

                        ApplicationProfile.LastCOMconnected = serialDeviceController.ComPortName; // Zapisz pod jakim portem znalezlismy urzadzenie

                        AppProfileManager.Save_ApplicationProfile(ApplicationProfile);            // Zapisz profil
                    }
                    else
                    {
                        TextBlock_StatusBar_1.Text   = "Device not found!";           // Wyswietl informacje ze nie znalezlismy urzadzenia
                        ToggleButton_Start.Content   = "Start";
                        ToggleButton_Start.IsEnabled = !ToggleButton_Start.IsEnabled; // Toggle button state
                    }
                }
                #endregion

                #region Jesli znamy juz port COM pod ktorym bylo nasze urzadzenie
                else
                {
                    TextBlock_StatusBar_1.Text = "Searching for device...";     // Wyswietl informacje ze szukamy urzadzenia

                    // Jesli nie to musimy je wyszukac ....
                    // ... jesli znalezlismy nasze urzadzenie.....
                    if (serialDeviceController.CheckForConnectedDevice("A1"))   // Jesli udalo Ci sie polaczyc
                    {
                        TextBlock_StatusBar_1.Text = "Found! Connecting...";
                    }
                    else
                    {
                        ApplicationProfile.LastCOMconnected = "";                      // Wyczysc informacje o ostatnim porcie COM z profilu

                        AppProfileManager.Save_ApplicationProfile(ApplicationProfile); // Zapisz profil

                        TextBlock_StatusBar_1.Text = "Device not found!";              // Wyswietl informacje ze urzadzenie nie zostalo znalezione

                        ToggleButton_Start.Content = "Start";

                        ToggleButton_Start.IsEnabled = !ToggleButton_Start.IsEnabled;               // Toggle button state
                    }
                }
                #endregion

                #region Proces wyszukiwania zakonczony ... Podlaczamy sie

                if (serialDeviceController.DeviceFound)
                {
                    if (serialDeviceController.Initialize_Serial_Connection())
                    {
                        TextBlock_StatusBar_1.Text = "Connected";                                   // Wyswietl info ze jestesmy polaczeni
                        ToggleButton_Start.Content = "Stop";                                        // Zmien text na guziku tak zeby mozna bylo zatrzymac Ambi

                        if (tsk_RGBdata.Status == TaskStatus.Running)                               // Na wypadek disconnecta
                        {
                            Stop_Data_Aqquire = false;                                              // Wznow transmisje
                        }
                        else
                        {
                            tsk_RGBdata.Start();                                                        // Uruchom zadanie
                        }

                        isRGBdataAqquireRunning = true;                                             // Zmien wartosc zmiennej informujacej czy smigamy z Ambi

                        TextBlock_StatusBar_1.Text = " Connected | Running";

                        ToggleButton_Start.IsEnabled = !ToggleButton_Start.IsEnabled;               // Toggle button state
                    }
                    else
                    {
                        TextBlock_StatusBar_1.Text = "Failed to connect";                           // Wyswietl info ze jestesmy polaczeni
                        ToggleButton_Start.Content = "Start";                                       // Zmien text na guziku tak zeby mozna bylo zatrzymac Ambi

                        ToggleButton_Start.IsEnabled = !ToggleButton_Start.IsEnabled;               // Toggle button state
                    }
                }


                #endregion
            }
        }