From 58f97915368802983027d3557f8155f42deb0cfc Mon Sep 17 00:00:00 2001 From: Bob Long Date: Wed, 25 Sep 2024 21:51:59 +1000 Subject: [PATCH 1/2] ConfigDroneCAN: allow disconnect --- GCSViews/ConfigurationView/ConfigDroneCAN.cs | 24 ++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/GCSViews/ConfigurationView/ConfigDroneCAN.cs b/GCSViews/ConfigurationView/ConfigDroneCAN.cs index 3065b71769..452ec55a14 100644 --- a/GCSViews/ConfigurationView/ConfigDroneCAN.cs +++ b/GCSViews/ConfigurationView/ConfigDroneCAN.cs @@ -466,6 +466,7 @@ private void SetupSLCanPort(ICommsSerial port) private TcpListener listener; private bool mavlinkCANRun; private byte BusInUse; + private bool isConnected = false; private void myDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { @@ -649,6 +650,12 @@ private void GetParameters(byte nodeID) } public void Deactivate() + { + Disconnect(); + timer?.Stop(); + } + + public void Disconnect() { mavlinkCANRun = false; try @@ -663,7 +670,11 @@ public void Deactivate() listener = null; can?.Stop(chk_canonclose.Checked); can = null; - timer?.Stop(); + + cmb_interfacetype.Enabled = true; + cmb_networkinterface.Enabled = true; + but_connect.Text = "Connect"; + isConnected = false; } private void myDataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) @@ -1593,6 +1604,12 @@ private void StartmcastCAN(byte bus = 0, NetworkInterface inter = null) private void but_connect_Click(object sender, EventArgs e) { + if (isConnected) + { + Disconnect(); + return; + } + mavlinkCANRun = false; var selected = cmb_interfacetype.SelectedValue; @@ -1603,7 +1620,10 @@ private void but_connect_Click(object sender, EventArgs e) return; } - but_connect.Enabled = false; + cmb_interfacetype.Enabled = false; + cmb_networkinterface.Enabled = false; + but_connect.Text = "Disconnect"; + isConnected = true; var type = (ConnectionTypes)selected; From fb1afb0dd402058950c2bfd332a23767bb967356 Mon Sep 17 00:00:00 2001 From: Bob Long Date: Wed, 25 Sep 2024 21:52:39 +1000 Subject: [PATCH 2/2] ConfigDroneCAN: reset grid view on connect --- GCSViews/ConfigurationView/ConfigDroneCAN.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GCSViews/ConfigurationView/ConfigDroneCAN.cs b/GCSViews/ConfigurationView/ConfigDroneCAN.cs index 452ec55a14..08b33c3c76 100644 --- a/GCSViews/ConfigurationView/ConfigDroneCAN.cs +++ b/GCSViews/ConfigurationView/ConfigDroneCAN.cs @@ -1620,6 +1620,9 @@ private void but_connect_Click(object sender, EventArgs e) return; } + // Reset the table of nodes + myDataGridView1.Rows.Clear(); + cmb_interfacetype.Enabled = false; cmb_networkinterface.Enabled = false; but_connect.Text = "Disconnect";