コード例 #1
0
        private void OnDeviceDiscovered(ConnectionSearchResult connectionSearchResult)
        {
            DataGridViewRow row = new DataGridViewRow()
            {
                Tag = connectionSearchResult
            };

            row.CreateCells(m_Connections, AllowMultipleConnections, connectionSearchResult.DeviceDescriptor, connectionSearchResult.ConnectionInfo.ToString());

            m_Connections.Rows.Add(row);

            if (m_Connections.Rows.Count == 1)
            {
                m_Connections.ClearSelection();
                row.Selected = true;
            }

            if (connectionSearchResult.ConnectionType == NgimuApi.ConnectionType.Udp)
            {
                numberOfUdpConnections++;
            }
            else
            {
                numberOfSerialConnections++;
            }

            SetNumberOfConnectionsText();

            if (OpenConnectionToFirstDeviceFound == true)
            {
                Connect_Click(null, EventArgs.Empty);
            }
        }
コード例 #2
0
        private void AutoConnector_DeviceExpired(ConnectionSearchResult obj)
        {
            Debug.Log("Device Expired: " + obj.DeviceDescriptor);

            active.TryRemove(obj.ConnectionInfo.GetHashCode(), out _);

            Interlocked.Increment(ref operationId);
        }
コード例 #3
0
 private void AutoConnector_DeviceExpired(ConnectionSearchResult connectionSearchResult)
 {
     if (InvokeRequired == true)
     {
         BeginInvoke(new Action <ConnectionSearchResult>(OnDeviceExpired), connectionSearchResult);
     }
     else
     {
         OnDeviceExpired(connectionSearchResult);
     }
 }
コード例 #4
0
    private void ConnectionListItem_Selected(ConnectionListItem item, ConnectionSearchResult connectionSearchInfo)
    {
        NGIMUConnection connection = FindObjectOfType <NGIMUConnection>();

        if (connection == null)
        {
            Debug.LogError("No NGIMUConnection object could be found in the scene hierarchy.");

            return;
        }

        Deactivate();

        connection.ConnectTo(connectionSearchInfo);
    }
コード例 #5
0
    private void AutoConnector_DeviceExpired(ConnectionSearchResult obj)
    {
        Debug.Log("Device Expired: " + obj.DeviceDescriptor);

        lock (syncObject)
        {
            ConnectionListItemStub foundItem;

            if (foundConnections.TryGetValue(obj, out foundItem) == false)
            {
                return;
            }

            foundItem.ShouldRemove = true;
        }
    }
コード例 #6
0
        public void ConnectTo(ConnectionSearchResult info)
        {
            SelectTab(ConnectionTab.ModelView);
            ErrorsText.text = "No errors";

            reporter.Clear();

            Debug.Log($"ConnectTo ({info.DeviceDescriptor})");

            HeaderName.text    = info.DeviceDescriptor;
            HeaderDetails.text = info.ConnectionInfo.ToIDString();

            switch (info.ConnectionType)
            {
            case ConnectionType.Udp:
                UdpConnectionInfo udpInfo = info.ConnectionInfo as UdpConnectionInfo;

                Thread thread = new Thread(
                    delegate()
                {
                    try
                    {
                        Debug.Log("Configure unique UDP connection");

                        UdpConnectionInfo newInfo = Connection.ConfigureUniqueUdpConnection(udpInfo, reporter);

                        ConnectTo(newInfo);
                    }
                    catch (Exception ex)
                    {
                        reporter.OnException(this, new ExceptionEventArgs("The device could not be configured to use a unique connection. " + ex.Message, ex));
                    }
                }
                    );
                thread.Name = "Configure Unique UDP Connection";
                thread.Start();

                break;

            case ConnectionType.Serial:
                ConnectTo(info.ConnectionInfo as SerialConnectionInfo);
                break;

            default:
                break;
            }
        }
コード例 #7
0
        private void OnDeviceExpired(ConnectionSearchResult connectionSearchResult)
        {
            DataGridViewRow foundRow = null;

            foreach (DataGridViewRow row in m_Connections.Rows)
            {
                if (connectionSearchResult.Equals(row.Tag as ConnectionSearchResult) == false)
                {
                    continue;
                }

                foundRow = row;
            }

            if (foundRow == null)
            {
                return;
            }

            ConnectionSearchResults.Remove(connectionSearchResult);

            m_Connections.Rows.Remove(foundRow);

            if (foundRow.Selected == true)
            {
                if (m_Connections.Rows.Count > 0)
                {
                    m_Connections.ClearSelection();
                    m_Connections.Rows[0].Selected = true;
                }
            }

            if (connectionSearchResult.ConnectionType == NgimuApi.ConnectionType.Udp)
            {
                numberOfUdpConnections--;
            }
            else
            {
                numberOfSerialConnections--;
            }

            SetNumberOfConnectionsText();
        }
コード例 #8
0
    private void AutoConnector_DeviceDiscovered(ConnectionSearchResult obj)
    {
        Debug.Log("Device Discovered: " + obj.DeviceDescriptor);

        lock (syncObject)
        {
            ConnectionListItemStub foundItem;

            if (foundConnections.TryGetValue(obj, out foundItem) == false)
            {
                foundConnections.Add(obj, new ConnectionListItemStub()
                {
                    Info = obj
                });

                return;
            }

            foundItem.ShouldRemove = false;
        }
    }
コード例 #9
0
    public void ConnectTo(ConnectionSearchResult info)
    {
        reporter.Clear();

        Debug.Log("ConnectTo (ConnectionSearchInfo)");

        switch (info.ConnectionType)
        {
        case ConnectionType.Udp:
            UdpConnectionInfo udpInfo = info.ConnectionInfo as UdpConnectionInfo;

            Thread thread = new Thread(delegate()
            {
                try
                {
                    Debug.Log("Configure unique UDP connection");

                    UdpConnectionInfo newInfo = Connection.ConfigureUniqueUdpConnection(udpInfo, reporter);

                    ConnectTo(newInfo);
                }
                catch (Exception ex)
                {
                    reporter.OnException(this, new ExceptionEventArgs("The device could not be configured to use a unique connection. " + ex.Message, ex));
                }
            });
            thread.Name = "Configure Unique UDP Connection";
            thread.Start();

            break;

        case ConnectionType.Serial:
            ConnectTo(info.ConnectionInfo as SerialConnectionInfo);
            break;

        default:
            break;
        }
    }
コード例 #10
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.");
            }
        }
コード例 #11
0
        // TODO refactor this method to a helper / class of some kind
        private DialogResult ConnectToAllDevices(List <ConnectionSearchResult> connectionSearchResults, out List <Connection> resultConnections)
        {
            if (connectionSearchResults.Count == 0)
            {
                resultConnections = new List <Connection>();

                return(DialogResult.OK);
            }

            List <Connection> connections = new List <Connection>();

            DialogResult result = System.Windows.Forms.DialogResult.Cancel;

            // Begin
            ProgressDialog progress = new ProgressDialog();

            progress.Text  = "Connecting";
            progress.Style = ProgressBarStyle.Continuous;

            progress.ProgressMessage = "";
            progress.Progress        = 0;
            progress.ProgressMaximum = (connectionSearchResults.Count * 4) - 1;

            Reporter reporter = new Reporter();

            bool canceled        = false;
            int  currentProgress = 0;

            string currentConnectionString = "";

            Thread connectingToMultipleConnections = new Thread(() =>
            {
                progress.OnCancel += (o, args) =>
                {
                    canceled = true;
                };

                EventHandler <MessageEventArgs> reportInfo = (o, args) =>
                {
                    progress.UpdateProgress(currentProgress, currentConnectionString + args.Message);
                };

                reporter.Info += reportInfo;

                try
                {
                    progress.UpdateProgress(0);

                    for (int i = 0; i < connectionSearchResults.Count; i++)
                    {
                        if (canceled == true)
                        {
                            progress.UpdateProgress(currentProgress, string.Empty);

                            return;
                        }

                        ConnectionSearchResult autoConnectionInfo = connectionSearchResults[i];

                        currentConnectionString = "Connecting to " + autoConnectionInfo.DeviceDescriptor + ". ";

                        progress.UpdateProgress(currentProgress++, autoConnectionInfo.DeviceDescriptor);

                        Connection connection = null;

                        if (autoConnectionInfo.ConnectionType == ConnectionType.Udp)
                        {
                            #region Configure Unique Connection

                            bool retryThis = true;

                            do
                            {
                                try
                                {
                                    UdpConnectionInfo udpConnectionInfo =
                                        NgimuApi.Connection.ConfigureUniqueUdpConnection(
                                            autoConnectionInfo.ConnectionInfo as UdpConnectionInfo, reporter);

                                    connection = new Connection(udpConnectionInfo);

                                    break;
                                }
                                catch (Exception ex)
                                {
                                    StringBuilder fullMessageString = new StringBuilder();

                                    fullMessageString.AppendLine("Error while connecting to " + autoConnectionInfo.DeviceDescriptor + ".");
                                    fullMessageString.AppendLine();

                                    fullMessageString.Append("Could not configure a unique UDP connection.");

                                    switch (this.InvokeShowError(fullMessageString.ToString(), MessageBoxButtons.AbortRetryIgnore))
                                    {
                                    case DialogResult.Abort:
                                        CloseAllConnections(connections);

                                        progress.DialogResult = DialogResult.Cancel;

                                        return;

                                    case DialogResult.Retry:
                                        break;

                                    case DialogResult.Ignore:
                                        retryThis = false;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }while (retryThis == true);

                            #endregion
                        }
                        else
                        {
                            connection = new Connection(autoConnectionInfo);
                        }

                        if (connection == null)
                        {
                            currentProgress += 3;
                            progress.UpdateProgress(currentProgress);

                            continue;
                        }

                        progress.UpdateProgress(currentProgress++);

                        if (canceled == true)
                        {
                            progress.UpdateProgress(currentProgress);

                            return;
                        }

                        #region Read Settings

                        try
                        {
                            connection.Connect();

                            progress.UpdateProgress(currentProgress++);


                            bool retryThis = false;

                            do
                            {
                                if (connection.Settings.Read(reporter) != CommunicationProcessResult.Success)
                                {
                                    bool allValuesFailed;
                                    bool allValuesSucceeded;

                                    string messageString =
                                        Settings.GetCommunicationFailureString(connection.Settings.Values, 20,
                                                                               out allValuesFailed, out allValuesSucceeded);

                                    StringBuilder fullMessageString = new StringBuilder();

                                    fullMessageString.AppendLine("Error while connecting to " + autoConnectionInfo.DeviceDescriptor + ".");
                                    fullMessageString.AppendLine();

                                    if (allValuesFailed == true)
                                    {
                                        fullMessageString.Append("Failed to read all settings.");
                                    }
                                    else
                                    {
                                        fullMessageString.Append("Failed to read the following settings:" + messageString);
                                    }

                                    switch (this.InvokeShowError(fullMessageString.ToString(), MessageBoxButtons.AbortRetryIgnore))
                                    {
                                    case DialogResult.Abort:
                                        connection.Dispose();

                                        CloseAllConnections(connections);

                                        progress.DialogResult = DialogResult.Cancel;

                                        return;

                                    case DialogResult.Retry:
                                        retryThis = true;
                                        break;

                                    case DialogResult.Ignore:
                                        retryThis = false;
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                connections.Add(connection);
                            }while (retryThis);
                        }
                        catch (Exception ex)
                        {
                            connection?.Dispose();
                        }

                        #endregion

                        progress.UpdateProgress(currentProgress++);
                    }

                    progress.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                finally
                {
                    reporter.Info -= reportInfo;
                }
            });

            connectingToMultipleConnections.Name = "Connecting to multiple connections";
            connectingToMultipleConnections.Start();

            result = progress.ShowDialog(this);

            resultConnections = new List <Connection>(connections);

            return(result);
        }
コード例 #12
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);
        }
コード例 #13
0
        public void ConnectTo(ConnectionSearchResult searchResult)
        {
            connection.ConnectTo(searchResult);

            ShowPanel(Panel.Connected);
        }