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.IO.Ports;
using System.Text;
using System.Threading;
using ArducopterConfigurator.PresentationModels;
namespace ArducopterConfigurator
{
@ -43,12 +41,15 @@ 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();
_bgWorker.DoWork += bgWorker_DoWork;
@ -65,6 +66,7 @@ namespace ArducopterConfigurator
}
public bool DisConnect()
{
_bgWorker.CancelAsync();
@ -76,18 +78,19 @@ 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;
// 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++)
// {
// var c = lineReceived[i];
// Console.WriteLine("{0}] U+{1:x4} {2}", i, (int)c, (int)c);
// }
//
//
//
//Console.WriteLine("Processing Update: " + lineReceived);
if (LineOfDataReceived != null)
LineOfDataReceived(lineReceived);
@ -132,6 +135,4 @@ namespace ArducopterConfigurator
_sp.Write(send);
}
}
}

View File

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

View File

@ -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);

View File

@ -45,6 +45,15 @@ namespace ArducopterConfigurator.PresentationModels
ConnectionState = SessionStates.Disconnected;
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()

View File

@ -88,11 +88,8 @@ namespace ArducopterConfigurator
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]);
}

View File

@ -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));
}
}

View File

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