public void Start()
        {
            Stop();

            inError      = false;
            errorMessage = string.Empty;

            try
            {
                autoConnector = new SearchForConnections();

                autoConnector.DeviceDiscovered += AutoConnector_DeviceDiscovered;
                autoConnector.DeviceExpired    += AutoConnector_DeviceExpired;

                autoConnector.BeginSearch();
                searching = true;
            }
            catch (Exception ex)
            {
                inError      = true;
                errorMessage = ex.Message;

                Interlocked.Increment(ref operationId);

                throw;
            }
        }
Пример #2
0
    private void Stop()
    {
        if (autoConnector != null)
        {
            try
            {
                Debug.Log("Stop searching for connections.");

                autoConnector.DeviceDiscovered -= AutoConnector_DeviceDiscovered;
                autoConnector.DeviceExpired    -= AutoConnector_DeviceExpired;

                autoConnector.EndSearch();
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            finally
            {
                autoConnector.Dispose();
                autoConnector = null;
            }
        }

        ManageListItems(true);
    }
Пример #3
0
    private void OnDestroy()
    {
        Stop();

        if (autoConnector != null)
        {
            autoConnector.Dispose();
            autoConnector = null;
        }

        Instance = null;
    }
        public void Stop()
        {
            autoConnector?.Dispose();

            autoConnector = null;

            active.Clear();

            operationId = long.MinValue;

            searching = false;
        }
Пример #5
0
        private void SearchingForConnectionsDialog_Load(object sender, EventArgs e)
        {
            SetNumberOfConnectionsText();

            Selected.Visible = AllowMultipleConnections;

            autoConnector = new SearchForConnections(ConnectionSearchType);

            autoConnector.DeviceDiscovered += AutoConnector_DeviceDiscovered;
            autoConnector.DeviceExpired    += AutoConnector_DeviceExpired;

            ellipseAnimationTimer.Enabled = true;

            autoConnector.BeginSearch();
        }
Пример #6
0
    private void Start()
    {
        Stop();

        try
        {
            autoConnector = new SearchForConnections();

            autoConnector.DeviceDiscovered += AutoConnector_DeviceDiscovered;
            autoConnector.DeviceExpired    += AutoConnector_DeviceExpired;

            autoConnector.BeginSearch();
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }
Пример #7
0
        private void ConfigureWirelessSettingsViaUSBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ProgressDialog progress = new ProgressDialog
            {
                Text  = "Configuring NGIMU Wireless Settings",
                Style = ProgressBarStyle.Marquee,
                CancelButtonEnabled = true,
                ProgressMessage     = "",
                Progress            = 0,
                ProgressMaximum     = 1,
                DialogResult        = DialogResult.Cancel,
            };

            ManualResetEvent contiueResetEvent = new ManualResetEvent(false);

            bool hasBeenCanceled = false;

            progress.OnCancel += delegate(object s, FormClosingEventArgs fce)
            {
                hasBeenCanceled = true;
                contiueResetEvent.Set();
            };

            progress.FormClosed += delegate(object s, FormClosedEventArgs fce)
            {
                contiueResetEvent.Set();
            };

            Thread configureWirelessSettingsViaUSBThread = new Thread(() =>
            {
                progress.UpdateProgress(0, "Searching for USB connection.");

                bool found = false;
                ConnectionSearchResult foundConnectionSearchResult = null;

                // search for serial only connections
                using (SearchForConnections searchForConnections = new SearchForConnections(ConnectionSearchTypes.Serial))
                {
                    searchForConnections.DeviceDiscovered += delegate(ConnectionSearchResult connectionSearchResult)
                    {
                        found = true;
                        foundConnectionSearchResult = connectionSearchResult;
                        contiueResetEvent.Set();
                    };

                    contiueResetEvent.Reset();

                    searchForConnections.BeginSearch();

                    contiueResetEvent.WaitOne();

                    searchForConnections.EndSearch();
                }

                if (hasBeenCanceled == true)
                {
                    return;
                }

                if (foundConnectionSearchResult == null)
                {
                    return;
                }

                string deviceDescriptor = foundConnectionSearchResult.DeviceDescriptor;

                // open connection to first device found
                progress.UpdateProgress(0, $"Found device {deviceDescriptor}.");

                using (Connection connection = new Connection(foundConnectionSearchResult))
                {
                    connection.Connect();

                    progress.UpdateProgress(0, $"Restoring default settings.");
                    connection.SendCommand(Command.Default);

                    connection.Settings.WifiMode.Value                  = WifiMode.Client;
                    connection.Settings.WifiClientSSID.Value            = MainForm.DefaultWifiClientSSID;
                    connection.Settings.WifiClientKey.Value             = MainForm.DefaultWifiClientKey;
                    connection.Settings.WifiReceivePort.Value           = MainForm.SynchronisationMasterPort;
                    connection.Settings.SynchronisationMasterPort.Value = MainForm.SynchronisationMasterPort;
                    connection.Settings.SendRateRssi.Value              = MainForm.DefaultSendRateRssi;

                    progress.UpdateProgress(0, $"Writing wireless settings.");
                    this.WriteSettingsWithExistingProgress(progress, new List <ConnectionRow>(), true, new[] { connection.Settings });
                }

                progress.DialogResult = DialogResult.OK;

                Invoke(new MethodInvoker(() => { progress.Close(); }));
            });

            configureWirelessSettingsViaUSBThread.Name = "Configure Wireless Settings Via USB";
            configureWirelessSettingsViaUSBThread.Start();

            if (progress.ShowDialog(this) == DialogResult.OK)
            {
                this.ShowInformation($@"Configuration of device complete.");
            }
        }
Пример #8
0
        private void ConfigureWirelessSettingsViaUSBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //using (WifiSettingsDialog dialog = new WifiSettingsDialog())
            //{
            //    if (dialog.ShowDialog(this) != DialogResult.OK)
            //    {
            //        return;
            //    }
            //}

            ProgressDialog progress = new ProgressDialog
            {
                Text  = "Configure Wireless Settings Via USB",
                Style = ProgressBarStyle.Marquee,
                CancelButtonEnabled = true,
                ProgressMessage     = "",
                Progress            = 0,
                ProgressMaximum     = 1
            };

            ManualResetEvent contiueResetEvent = new ManualResetEvent(false);

            bool hasBeenCanceled = false;

            progress.OnCancel += delegate(object s, FormClosingEventArgs fce)
            {
                hasBeenCanceled = true;
                contiueResetEvent.Set();
            };

            progress.FormClosed += delegate(object s, FormClosedEventArgs fce)
            {
                contiueResetEvent.Set();
            };

            Thread configureWirelessSettingsViaUSBThread = new Thread(() =>
            {
                while (hasBeenCanceled == false)
                {
                    progress.UpdateProgress(0, "Connect next NGIMU to be configured.");

                    bool found = false;
                    ConnectionSearchResult foundConnectionSearchResult = null;

                    // search for serial only connections
                    using (SearchForConnections searchForConnections = new SearchForConnections(ConnectionSearchTypes.Serial))
                    {
                        searchForConnections.DeviceDiscovered += delegate(ConnectionSearchResult connectionSearchResult)
                        {
                            found = true;
                            foundConnectionSearchResult = connectionSearchResult;
                            contiueResetEvent.Set();
                        };

                        contiueResetEvent.Reset();

                        searchForConnections.BeginSearch();

                        contiueResetEvent.WaitOne();

                        searchForConnections.EndSearch();
                    }

                    if (hasBeenCanceled == true)
                    {
                        break;
                    }

                    if (foundConnectionSearchResult == null)
                    {
                        break;
                    }

                    string deviceDescriptor = foundConnectionSearchResult.DeviceDescriptor;

                    // open connection to first device found
                    progress.UpdateProgress(0, $"Found device {deviceDescriptor}.");

                    using (Connection connection = new Connection(foundConnectionSearchResult))
                    {
                        connection.Connect();

                        connection.Settings.WifiMode.Value       = WifiMode.Client;
                        connection.Settings.WifiClientSSID.Value = DefaultWifiClientSSID;
                        //connection.Settings.WifiClientKey.Value = DefaultWifiClientPassword;
                        connection.Settings.SendRateRssi.Value = DefaultSendRateRssi;

                        progress.UpdateProgress(0, $"Writing settings to device {deviceDescriptor}.");

                        this.WriteSettingsWithExistingProgress(progress, connectionsRows, true, new[] { connection.Settings });
                    }

                    //if (hasBeenCanceled == true)
                    //{
                    //    break;
                    //}

                    this.InvokeShowInformation($@"Configuration of ""{deviceDescriptor}"" complete.{Environment.NewLine}{Environment.NewLine}Disconnect the device then click OK");
                }

                Invoke(new MethodInvoker(() => { progress.Close(); }));
            });

            configureWirelessSettingsViaUSBThread.Name = "Configure Wireless Settings Via USB";
            configureWirelessSettingsViaUSBThread.Start();

            progress.ShowDialog(this);
        }