Configurator.Net: Mono tweaks, Port list is populated on startup

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1565 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
mandrolic 2011-01-27 15:58:32 +00:00
parent cedcd47073
commit bf3b5c2f7c
7 changed files with 31 additions and 30 deletions

View File

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO.Ports; using System.IO.Ports;
using System.Text; using System.Text;
using System.Threading;
using ArducopterConfigurator.PresentationModels;
namespace ArducopterConfigurator namespace ArducopterConfigurator
{ {
@ -43,12 +41,15 @@ namespace ArducopterConfigurator
{ {
_sp.BaudRate = 115200; _sp.BaudRate = 115200;
_sp.PortName = CommPort; _sp.PortName = CommPort;
_sp.NewLine = "\n";
_sp.Handshake = Handshake.None;
try try
{ {
_sp.Open(); _sp.Open();
_sp.ReadTimeout = 50000; _sp.ReadTimeout = 50000;
// start the reading BG thread // start the reading BG thread
_bgWorker = new BackgroundWorker(); _bgWorker = new BackgroundWorker();
_bgWorker.DoWork += bgWorker_DoWork; _bgWorker.DoWork += bgWorker_DoWork;
@ -65,6 +66,7 @@ namespace ArducopterConfigurator
} }
public bool DisConnect() public bool DisConnect()
{ {
_bgWorker.CancelAsync(); _bgWorker.CancelAsync();
@ -76,18 +78,19 @@ namespace ArducopterConfigurator
void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{ {
// Thanks to BG worker, this should be raised on the UI thread // Thanks to BG worker, this should be raised on the UI thread
var lineReceived = e.UserState as string; var lineReceived = e.UserState as string;
// 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);
}
// for (int i = 0; i < lineReceived.Length; i++) //Console.WriteLine("Processing Update: " + lineReceived);
// {
// var c = lineReceived[i];
// Console.WriteLine("{0}] U+{1:x4} {2}", i, (int)c, (int)c);
// }
//
//
//
if (LineOfDataReceived != null) if (LineOfDataReceived != null)
LineOfDataReceived(lineReceived); LineOfDataReceived(lineReceived);
@ -132,6 +135,4 @@ namespace ArducopterConfigurator
_sp.Write(send); _sp.Write(send);
} }
} }
} }

View File

@ -26,7 +26,6 @@ namespace ArducopterConfigurator.PresentationModels
protected override void OnStringReceived(string strRx) protected override void OnStringReceived(string strRx)
{ {
Console.WriteLine("Badoosh strnig rxd");
PopulatePropsFromUpdate(strRx,true); PopulatePropsFromUpdate(strRx,true);
} }
} }

View File

@ -35,7 +35,7 @@ namespace ArducopterConfigurator.PresentationModels
int val; int val;
if (!int.TryParse(s, out 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; return;
} }
ints.Add(val); ints.Add(val);

View File

@ -45,6 +45,15 @@ namespace ArducopterConfigurator.PresentationModels
ConnectionState = SessionStates.Disconnected; ConnectionState = SessionStates.Disconnected;
AvailablePorts = new BindingList<string>(); AvailablePorts = new BindingList<string>();
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() private void RefreshPorts()

View File

@ -88,11 +88,8 @@ namespace ArducopterConfigurator
protected void PopulatePropsFromUpdate(string strRx, bool fireInpc) protected void PopulatePropsFromUpdate(string strRx, bool fireInpc)
{ {
var strs = strRx.Split(','); var strs = strRx.Split(',');
if (PropsInUpdateOrder.Length!=strs.Length) if (PropsInUpdateOrder.Length!=strs.Length)
{ {
Console.WriteLine("Processing update with only " + strs.Length Console.WriteLine("Processing update with only " + strs.Length
@ -112,7 +109,7 @@ namespace ArducopterConfigurator
float val; float val;
if (!float.TryParse(s, out val)) if (!float.TryParse(s, out val))
{ {
Console.WriteLine("Error parsing float: " + s); Console.WriteLine("Error parsing float: {0}, VM: {1}" + s, Name);
break; break;
} }
value = val; value = val;
@ -122,7 +119,7 @@ namespace ArducopterConfigurator
float val; float val;
if (!float.TryParse(s, out 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; break;
} }
value = val != 0.0; value = val != 0.0;
@ -133,7 +130,7 @@ namespace ArducopterConfigurator
int val; int val;
if (!int.TryParse(s, out val)) if (!int.TryParse(s, out val))
{ {
Console.WriteLine("Error parsing int: " + s); Console.WriteLine("Error parsing int:{0}, VM: {1}" + s, Name);
break; break;
} }
value = val; value = val;
@ -141,9 +138,6 @@ namespace ArducopterConfigurator
prop.SetValue(this, value, null); prop.SetValue(this, value, null);
Console.WriteLine("Badoosh firing inpc");
if (fireInpc) if (fireInpc)
FirePropertyChanged(PropsInUpdateOrder[i]); FirePropertyChanged(PropsInUpdateOrder[i]);
} }

View File

@ -22,11 +22,7 @@ namespace ArducopterConfigurator.Views
StableModeConfigVmBindingSource.DataSource = model; StableModeConfigVmBindingSource.DataSource = model;
if (Program.IsMonoRuntime) if (Program.IsMonoRuntime)
model.PropertyChanged += (delegate model.PropertyChanged += ((sender, e) => StableModeConfigVmBindingSource.ResetBindings(false));
{
Console.WriteLine("Badoosh1");
StableModeConfigVmBindingSource.ResetBindings(false);
});
} }
} }

View File

@ -93,8 +93,10 @@ namespace ArducopterConfigurator
{ {
_vm = model; _vm = model;
mainVmBindingSource.DataSource = model; mainVmBindingSource.DataSource = model;
availablePortsBindingSource.DataSource = model.AvailablePorts; availablePortsBindingSource.DataSource = model.AvailablePorts;
foreach (var monitorVm in _vm.MonitorVms) foreach (var monitorVm in _vm.MonitorVms)
{ {
var tp = new TabPage(monitorVm.Name) {Tag = monitorVm}; var tp = new TabPage(monitorVm.Name) {Tag = monitorVm};