コード例 #1
0
        private void dataLoggerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataLogger != null)
            {
                dataLogger.Show();

                return;
            }

            dataLogger             = new DataLoggerWindow();
            dataLogger.FormClosed += DataLogger_FormClosed;

            foreach (ConnectionRow row in connectionsRows)
            {
                dataLogger?.ActiveConnections.Add(row.Connection);
            }

            dataLogger?.UpdateConnections();
            dataLogger.Show();
        }
コード例 #2
0
        private void searchForConnectionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            disconnectAllToolStripMenuItem_Click(sender, e);

            DialogResult result;

            using (SearchingForConnectionsDialog searchDialog = new SearchingForConnectionsDialog()
            {
                ConnectionSearchType = ConnectionSearchTypes.Udp,
                AllowMultipleConnections = true
            })
            {
                if (searchDialog.ShowDialog(this) == DialogResult.Cancel)
                {
                    return;
                }

                List <Connection> newConnections;

                result = ConnectToAllDevices(searchDialog.ConnectionSearchResults, out newConnections);

                foreach (Connection connection in newConnections)
                {
                    ConnectionRow connectionRow = new ConnectionRow();

                    connectionRow.Connection = connection;

                    connectionsRows.Add(connectionRow);

                    dataLogger?.ActiveConnections.Add(connection);
                    sendRates?.ActiveConnections.Add(connectionRow);

                    connection.Message += Connection_Message;

                    object[]   cells      = new object[Enum.GetNames(typeof(ColumnIndex)).Length];
                    DateTime[] timestamps = new DateTime[cells.Length];

                    StringBuilder nameBuilder = new StringBuilder();

                    nameBuilder.AppendLine(connection.Settings.DeviceInformation.DeviceName.Value);
                    nameBuilder.AppendLine(connection.Settings.DeviceInformation.SerialNumber.Value);

                    cells[(int)ColumnIndex.Device] = nameBuilder.ToString().Trim();

                    cells[(int)ColumnIndex.Master]           = connectionRow.Connection.Settings.SynchronisationMasterEnabled.Value;
                    cells[(int)ColumnIndex.MessagesReceived] = "Unknown";
                    cells[(int)ColumnIndex.MessagesSent]     = "Unknown";
                    cells[(int)ColumnIndex.Battery]          = new DataGridViewProgressValue()
                    {
                        Value = 0, Text = "Unknown"
                    };
                    cells[(int)ColumnIndex.Signal] = new DataGridViewProgressValue()
                    {
                        Value = 0, Text = "Unknown"
                    };
                    cells[(int)ColumnIndex.Identify] = "Identify";

                    timestamps[(int)ColumnIndex.Device]           = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.Master]           = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.MessagesReceived] = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.MessagesSent]     = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.Battery]          = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.Signal]           = DateTime.UtcNow;
                    timestamps[(int)ColumnIndex.Identify]         = DateTime.UtcNow;

                    connectionRow.Timestamps = timestamps;
                    connectionRow.Cells      = cells;
                    connectionRow.Row        = dataGridView1.Rows[dataGridView1.Rows.Add(cells)];
                    connectionRow.Row.Tag    = connectionRow;

                    connectionRow.Information = new IconInfo()
                    {
                        Image = icons[(int)ConnectionIcon.Information], Message = "", MessageIcon = MessageBoxIcon.Information, Visible = false
                    };
                    connectionRow.Warning = new IconInfo()
                    {
                        Image = icons[(int)ConnectionIcon.Warning], Message = "", MessageIcon = MessageBoxIcon.Warning, Visible = false
                    };
                    connectionRow.Error = new IconInfo()
                    {
                        Image = icons[(int)ConnectionIcon.Error], Message = "", MessageIcon = MessageBoxIcon.Error, Visible = false
                    };

                    (connectionRow.Row.Cells[(int)ColumnIndex.Device] as TextAndIconCell).Add(connectionRow.Information);
                    (connectionRow.Row.Cells[(int)ColumnIndex.Device] as TextAndIconCell).Add(connectionRow.Warning);
                    (connectionRow.Row.Cells[(int)ColumnIndex.Device] as TextAndIconCell).Add(connectionRow.Error);

                    connectionRow.Connection.DeviceError.Received += (s, args) =>
                    {
                        StringBuilder stringBuilder = new StringBuilder();

                        stringBuilder.AppendLine("Error message received:");
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine(connectionRow.Connection.DeviceError.Message);

                        connectionRow.SetInformation(stringBuilder.ToString());
                    };

                    connectionRow.Connection.Battery.Received += (s, arg) =>
                    {
                        string text = String.Format("{0}%" + Environment.NewLine, connectionRow.Connection.Battery.Percentage.ToString("F0", CultureInfo.InvariantCulture));

                        if (connectionRow.Connection.Battery.IsChargerConnected == true)
                        {
                            text += String.IsNullOrEmpty(connectionRow.Connection.Battery.ChargerState) == false ? connectionRow.Connection.Battery.ChargerState : String.Empty;
                        }
                        else
                        {
                            text += NgimuApi.Helper.TimeSpanToString(connectionRow.Connection.Battery.TimeToEmpty, TimeSpanStringFormat.Shorthand) + " remaining";
                        }

                        connectionRow.Timestamps[(int)ColumnIndex.Battery] = DateTime.UtcNow;
                        connectionRow.Cells[(int)ColumnIndex.Battery]      = new DataGridViewProgressValue()
                        {
                            Value = (int)connectionRow.Connection.Battery.Percentage, Text = text
                        };
                    };

                    connectionRow.Connection.Rssi.Received += (s, arg) =>
                    {
                        string text = String.Format("{0}%" + Environment.NewLine, connectionRow.Connection.Rssi.Percentage.ToString("F0", CultureInfo.InvariantCulture));
                        text += connectionRow.Connection.Rssi.Power.ToString("F2", CultureInfo.InvariantCulture) + " dBm";

                        connectionRow.Timestamps[(int)ColumnIndex.Signal] = DateTime.UtcNow;
                        connectionRow.Cells[(int)ColumnIndex.Signal]      = new DataGridViewProgressValue()
                        {
                            Value = (int)connectionRow.Connection.Rssi.Percentage, Text = text
                        };
                    };
                }
            }

            sendRates?.UpdateColumns();
            dataLogger?.UpdateConnections();

            if (result == DialogResult.Cancel)
            {
                DisconnectAll();
                return;
            }

            if (connectionsRows.Count == 0)
            {
                DisconnectAll();
                return;
            }

            sendCommandToolStripMenuItem.Enabled = true;

            SetTitle();

            VerifyConfiguration();

            CreateSynchronisationMasterListener();

            ApplySort();
        }