diff --git a/Configurator/Configurator.Net/CommsSession.cs b/Configurator/Configurator.Net/CommsSession.cs index dc9889ca03..04bac3bdde 100644 --- a/Configurator/Configurator.Net/CommsSession.cs +++ b/Configurator/Configurator.Net/CommsSession.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO.Ports; using System.Text; -using System.Threading; -using ArducopterConfigurator.PresentationModels; namespace ArducopterConfigurator { @@ -43,11 +41,14 @@ namespace ArducopterConfigurator { _sp.BaudRate = 115200; _sp.PortName = CommPort; + _sp.NewLine = "\n"; + _sp.Handshake = Handshake.None; try { _sp.Open(); _sp.ReadTimeout = 50000; + // start the reading BG thread _bgWorker = new BackgroundWorker(); @@ -64,6 +65,7 @@ namespace ArducopterConfigurator return true; } + public bool DisConnect() { @@ -76,19 +78,20 @@ namespace ArducopterConfigurator void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { // Thanks to BG worker, this should be raised on the UI thread - var lineReceived = e.UserState as string; - -// for (int i = 0; i < lineReceived.Length; i++) -// { -// var c = lineReceived[i]; -// Console.WriteLine("{0}] U+{1:x4} {2}", i, (int)c, (int)c); -// } -// -// -// + // TODO: POSSIBLE MONO ISSUE + // Weird thing happening with the serial port on mono; sometimes the first + // char is nulled. Work around for now is to drop it, and just send the remaining + // chars up the stack. This is of course exteremely bogus + if (lineReceived[0] == 0) + { + Console.WriteLine("Warning - received null first character. Dropping."); + lineReceived = lineReceived.Substring(1); + } + //Console.WriteLine("Processing Update: " + lineReceived); + if (LineOfDataReceived != null) LineOfDataReceived(lineReceived); } @@ -132,6 +135,4 @@ namespace ArducopterConfigurator _sp.Write(send); } } - - } diff --git a/Configurator/Configurator.Net/PresentationModels/ConfigWithPidsBase.cs b/Configurator/Configurator.Net/PresentationModels/ConfigWithPidsBase.cs index 6f936b1585..09d4002497 100644 --- a/Configurator/Configurator.Net/PresentationModels/ConfigWithPidsBase.cs +++ b/Configurator/Configurator.Net/PresentationModels/ConfigWithPidsBase.cs @@ -26,7 +26,6 @@ namespace ArducopterConfigurator.PresentationModels protected override void OnStringReceived(string strRx) { - Console.WriteLine("Badoosh strnig rxd"); PopulatePropsFromUpdate(strRx,true); } } diff --git a/Configurator/Configurator.Net/PresentationModels/FlightDataMonitorVm.cs b/Configurator/Configurator.Net/PresentationModels/FlightDataMonitorVm.cs index 38598dca48..05f0edff8f 100644 --- a/Configurator/Configurator.Net/PresentationModels/FlightDataMonitorVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/FlightDataMonitorVm.cs @@ -35,7 +35,7 @@ namespace ArducopterConfigurator.PresentationModels int val; if (!int.TryParse(s, out val)) { - Debug.WriteLine("Could not parse expected integer: " + s); + Debug.WriteLine("(Flight Data) Could not parse expected integer: " + s); return; } ints.Add(val); diff --git a/Configurator/Configurator.Net/PresentationModels/MainVm.cs b/Configurator/Configurator.Net/PresentationModels/MainVm.cs index 47a772f2b9..6d33398fae 100644 --- a/Configurator/Configurator.Net/PresentationModels/MainVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/MainVm.cs @@ -45,6 +45,15 @@ namespace ArducopterConfigurator.PresentationModels ConnectionState = SessionStates.Disconnected; AvailablePorts = new BindingList(); + + RefreshPorts(); + + // Initially have selected the last discovered com port. + // I think this is more likely to be the correct one, as + // the built in comports come first, then the usb/serial + // converter ports + if (AvailablePorts.Count > 0) + SelectedPort = AvailablePorts[AvailablePorts.Count-1]; } private void RefreshPorts() diff --git a/Configurator/Configurator.Net/PresentationModels/MonitorVm.cs b/Configurator/Configurator.Net/PresentationModels/MonitorVm.cs index 52357affa3..50542385f6 100644 --- a/Configurator/Configurator.Net/PresentationModels/MonitorVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/MonitorVm.cs @@ -87,12 +87,9 @@ namespace ArducopterConfigurator // property update order, and reflection to get the property type protected void PopulatePropsFromUpdate(string strRx, bool fireInpc) { - var strs = strRx.Split(','); - - if (PropsInUpdateOrder.Length!=strs.Length) { Console.WriteLine("Processing update with only " + strs.Length @@ -112,7 +109,7 @@ namespace ArducopterConfigurator float val; if (!float.TryParse(s, out val)) { - Console.WriteLine("Error parsing float: " + s); + Console.WriteLine("Error parsing float: {0}, VM: {1}" + s, Name); break; } value = val; @@ -122,7 +119,7 @@ namespace ArducopterConfigurator float val; if (!float.TryParse(s, out val)) { - Console.WriteLine("Error parsing float (bool): " + s); + Console.WriteLine("Error parsing float (bool): {0}, VM: {1}" + s, Name); break; } value = val != 0.0; @@ -133,7 +130,7 @@ namespace ArducopterConfigurator int val; if (!int.TryParse(s, out val)) { - Console.WriteLine("Error parsing int: " + s); + Console.WriteLine("Error parsing int:{0}, VM: {1}" + s, Name); break; } value = val; @@ -141,9 +138,6 @@ namespace ArducopterConfigurator prop.SetValue(this, value, null); - Console.WriteLine("Badoosh firing inpc"); - - if (fireInpc) FirePropertyChanged(PropsInUpdateOrder[i]); } diff --git a/Configurator/Configurator.Net/Views/StableConfigView.cs b/Configurator/Configurator.Net/Views/StableConfigView.cs index f7b644a802..204858ae88 100644 --- a/Configurator/Configurator.Net/Views/StableConfigView.cs +++ b/Configurator/Configurator.Net/Views/StableConfigView.cs @@ -22,11 +22,7 @@ namespace ArducopterConfigurator.Views StableModeConfigVmBindingSource.DataSource = model; if (Program.IsMonoRuntime) - model.PropertyChanged += (delegate - { - Console.WriteLine("Badoosh1"); - StableModeConfigVmBindingSource.ResetBindings(false); - }); + model.PropertyChanged += ((sender, e) => StableModeConfigVmBindingSource.ResetBindings(false)); } } diff --git a/Configurator/Configurator.Net/Views/mainForm.cs b/Configurator/Configurator.Net/Views/mainForm.cs index 2d2ea5ef7c..f7305882e4 100644 --- a/Configurator/Configurator.Net/Views/mainForm.cs +++ b/Configurator/Configurator.Net/Views/mainForm.cs @@ -93,7 +93,9 @@ namespace ArducopterConfigurator { _vm = model; mainVmBindingSource.DataSource = model; + availablePortsBindingSource.DataSource = model.AvailablePorts; + foreach (var monitorVm in _vm.MonitorVms) {