From dd008ec97f93aed5fa3ca14f860c9d88c9c76bd4 Mon Sep 17 00:00:00 2001 From: mandrolic Date: Mon, 28 Feb 2011 20:11:44 +0000 Subject: [PATCH] Configurator.Net: Added BaudRate option git-svn-id: https://arducopter.googlecode.com/svn/trunk@1733 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- .../ArducopterConfigurator.csproj | 2 +- Configurator/Configurator.Net/CommsSession.cs | 7 +++- .../Configurator.Net/FakeCommsSession.cs | 3 ++ .../PresentationModels/MainVm.cs | 26 ++++++++++++-- .../Configurator.Net/Test/MockComms.cs | 6 ++++ .../Views/mainForm.Designer.cs | 36 +++++++++++++++---- .../Configurator.Net/Views/mainForm.resx | 10 ++++-- 7 files changed, 78 insertions(+), 12 deletions(-) diff --git a/Configurator/Configurator.Net/ArducopterConfigurator.csproj b/Configurator/Configurator.Net/ArducopterConfigurator.csproj index 94ceaecc5c..866c225108 100644 --- a/Configurator/Configurator.Net/ArducopterConfigurator.csproj +++ b/Configurator/Configurator.Net/ArducopterConfigurator.csproj @@ -33,7 +33,7 @@ true index.htm false - 7 + 8 1.0.0.%2a false true diff --git a/Configurator/Configurator.Net/CommsSession.cs b/Configurator/Configurator.Net/CommsSession.cs index 2b1bdd85c3..2c9a9a15cd 100644 --- a/Configurator/Configurator.Net/CommsSession.cs +++ b/Configurator/Configurator.Net/CommsSession.cs @@ -11,6 +11,7 @@ namespace ArducopterConfigurator event Action LineOfDataReceived; string CommPort { get; set; } bool IsConnected { get; } + int BaudRate { get; set; } IEnumerable ListCommPorts(); void Send(string send); bool Connect(); @@ -37,9 +38,11 @@ namespace ArducopterConfigurator public string CommPort { get; set; } + public int BaudRate { get; set; } + public bool Connect() { - _sp.BaudRate = 115200; + _sp.BaudRate = BaudRate; _sp.PortName = CommPort; _sp.NewLine = "\n"; _sp.Handshake = Handshake.None; @@ -125,6 +128,8 @@ namespace ArducopterConfigurator get { return _sp.IsOpen; } } + + public IEnumerable ListCommPorts() { return SerialPort.GetPortNames(); diff --git a/Configurator/Configurator.Net/FakeCommsSession.cs b/Configurator/Configurator.Net/FakeCommsSession.cs index 9ecc6e9934..a801190dc9 100644 --- a/Configurator/Configurator.Net/FakeCommsSession.cs +++ b/Configurator/Configurator.Net/FakeCommsSession.cs @@ -32,6 +32,9 @@ namespace ArducopterConfigurator get { return _connected; } } + public int BaudRate { get; set; } + + public IEnumerable ListCommPorts() { return new[] {"FakePort1", "FakePort2"}; diff --git a/Configurator/Configurator.Net/PresentationModels/MainVm.cs b/Configurator/Configurator.Net/PresentationModels/MainVm.cs index c83023e074..7aeabc1bf7 100644 --- a/Configurator/Configurator.Net/PresentationModels/MainVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/MainVm.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using Timer=System.Windows.Forms.Timer; @@ -10,6 +11,7 @@ namespace ArducopterConfigurator.PresentationModels private bool _isConnected; private IPresentationModel _selectedVm; private string _selectedPort; + private int _selectedBaudRate; private string _apmVersion; private Timer _connectionAttemptsTimer; @@ -54,7 +56,10 @@ namespace ArducopterConfigurator.PresentationModels ConnectionState = SessionStates.Disconnected; AvailablePorts = new BindingList(); - + + AvailableBaudRates = new BindingList() {115200, 57600, 38400, 9600}; + SelectedBaudRate = 115200; + RefreshPorts(); // Initially have selected the last discovered com port. @@ -131,6 +136,8 @@ namespace ArducopterConfigurator.PresentationModels public BindingList AvailablePorts { get; private set; } + public BindingList AvailableBaudRates { get; private set; } + public enum SessionStates { Disconnected, @@ -178,11 +185,26 @@ namespace ArducopterConfigurator.PresentationModels } } } + + + public int SelectedBaudRate + { + get { return _selectedBaudRate; } + set + { + if (_selectedBaudRate != value) + { + _selectedBaudRate = value; + FirePropertyChanged("SelectedBaudRate"); + } + } + } public void Connect() { _comms.CommPort = SelectedPort; - + _comms.BaudRate = SelectedBaudRate; + // Todo: check the status of this call success/failure if (!_comms.Connect()) { diff --git a/Configurator/Configurator.Net/Test/MockComms.cs b/Configurator/Configurator.Net/Test/MockComms.cs index 14e4516281..c1b2392848 100644 --- a/Configurator/Configurator.Net/Test/MockComms.cs +++ b/Configurator/Configurator.Net/Test/MockComms.cs @@ -16,6 +16,12 @@ namespace ArducopterConfiguratorTest get { return _isConnected; } } + public int BaudRate + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + public IEnumerable ListCommPorts() { return new[] {"MockComport1"}; diff --git a/Configurator/Configurator.Net/Views/mainForm.Designer.cs b/Configurator/Configurator.Net/Views/mainForm.Designer.cs index 7659e47f45..87da37b47f 100644 --- a/Configurator/Configurator.Net/Views/mainForm.Designer.cs +++ b/Configurator/Configurator.Net/Views/mainForm.Designer.cs @@ -39,12 +39,15 @@ namespace ArducopterConfigurator this.button4 = new System.Windows.Forms.Button(); this.btnConnect = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.label1 = new System.Windows.Forms.Label(); this.cmboComPorts = new System.Windows.Forms.ComboBox(); this.lblConnectionStatus = new System.Windows.Forms.Label(); + this.availableBaudRatesBindingSource = new System.Windows.Forms.BindingSource(this.components); ((System.ComponentModel.ISupportInitialize)(this.mainVmBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.availablePortsBindingSource)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.availableBaudRatesBindingSource)).BeginInit(); this.SuspendLayout(); // // tabCtrlMonitorVms @@ -95,7 +98,7 @@ namespace ArducopterConfigurator this.btnConnect.Cursor = System.Windows.Forms.Cursors.Arrow; this.btnConnect.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.mainVmBindingSource, "ConnectCommand", true)); this.btnConnect.Image = ((System.Drawing.Image)(resources.GetObject("btnConnect.Image"))); - this.btnConnect.Location = new System.Drawing.Point(96, 407); + this.btnConnect.Location = new System.Drawing.Point(165, 408); this.btnConnect.Name = "btnConnect"; this.btnConnect.Size = new System.Drawing.Size(26, 26); this.btnConnect.TabIndex = 6; @@ -108,17 +111,29 @@ namespace ArducopterConfigurator this.button1.Cursor = System.Windows.Forms.Cursors.Arrow; this.button1.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.mainVmBindingSource, "DisconnectCommand", true)); this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image"))); - this.button1.Location = new System.Drawing.Point(127, 407); + this.button1.Location = new System.Drawing.Point(196, 408); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(26, 26); this.button1.TabIndex = 7; this.toolTip.SetToolTip(this.button1, "Disconnect"); this.button1.UseVisualStyleBackColor = true; // + // comboBox1 + // + this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.mainVmBindingSource, "SelectedBaudRate", true)); + this.comboBox1.DataSource = this.availableBaudRatesBindingSource; + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(80, 411); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(79, 21); + this.comboBox1.TabIndex = 15; + this.toolTip.SetToolTip(this.comboBox1, "Baud Rate"); + // // linkLabel1 // this.linkLabel1.AutoSize = true; - this.linkLabel1.Location = new System.Drawing.Point(346, 415); + this.linkLabel1.Location = new System.Drawing.Point(355, 423); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(84, 13); this.linkLabel1.TabIndex = 13; @@ -129,7 +144,7 @@ namespace ArducopterConfigurator // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(346, 399); + this.label1.Location = new System.Drawing.Point(355, 407); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(89, 13); this.label1.TabIndex = 14; @@ -143,7 +158,7 @@ namespace ArducopterConfigurator this.cmboComPorts.FormattingEnabled = true; this.cmboComPorts.Location = new System.Drawing.Point(11, 410); this.cmboComPorts.Name = "cmboComPorts"; - this.cmboComPorts.Size = new System.Drawing.Size(79, 21); + this.cmboComPorts.Size = new System.Drawing.Size(63, 21); this.cmboComPorts.TabIndex = 5; this.cmboComPorts.DropDown += new System.EventHandler(this.cmboComPorts_DropDown); // @@ -151,17 +166,23 @@ namespace ArducopterConfigurator // this.lblConnectionStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.lblConnectionStatus.AutoSize = true; - this.lblConnectionStatus.Location = new System.Drawing.Point(159, 418); + this.lblConnectionStatus.Location = new System.Drawing.Point(228, 419); this.lblConnectionStatus.Name = "lblConnectionStatus"; this.lblConnectionStatus.Size = new System.Drawing.Size(112, 13); this.lblConnectionStatus.TabIndex = 8; this.lblConnectionStatus.Text = "connection string here"; // + // availableBaudRatesBindingSource + // + this.availableBaudRatesBindingSource.DataMember = "AvailableBaudRates"; + this.availableBaudRatesBindingSource.DataSource = this.mainVmBindingSource; + // // mainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(554, 445); + this.Controls.Add(this.comboBox1); this.Controls.Add(this.label1); this.Controls.Add(this.lblConnectionStatus); this.Controls.Add(this.button1); @@ -179,6 +200,7 @@ namespace ArducopterConfigurator this.SizeChanged += new System.EventHandler(this.mainForm_SizeChanged); ((System.ComponentModel.ISupportInitialize)(this.mainVmBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.availablePortsBindingSource)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.availableBaudRatesBindingSource)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -198,6 +220,8 @@ namespace ArducopterConfigurator private System.Windows.Forms.ComboBox cmboComPorts; private System.Windows.Forms.Button button1; private System.Windows.Forms.Label lblConnectionStatus; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.BindingSource availableBaudRatesBindingSource; } } diff --git a/Configurator/Configurator.Net/Views/mainForm.resx b/Configurator/Configurator.Net/Views/mainForm.resx index 193abc66c1..d98930bc87 100644 --- a/Configurator/Configurator.Net/Views/mainForm.resx +++ b/Configurator/Configurator.Net/Views/mainForm.resx @@ -120,6 +120,9 @@ 7, 19 + + 7, 19 + 170, 20 @@ -130,8 +133,8 @@ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALBgAA - CwYBZDTpJAAABLRJREFUWEftVm1Mk1cYJVn8NxPjD7Nl2YeAWWJCliWbYxuwDzIdYDHIpgiKG9IBqYVR + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALBAAA + CwQBG8oqrQAABLRJREFUWEftVm1Mk1cYJVn8NxPjD7Nl2YeAWWJCliWbYxuwDzIdYDHIpgiKG9IBqYVR UEuFgu8AKZ+1CGg7ZUBhDtdYMykMaPmmxSJfwoAhTuwYCBuEIIgMPOu9TnRY2rVz4Y8/Tpomvfec8zzn eXrtANitJlaVnBh/KsDqCmxVeGCjzB52Yrt/4GXZRrxT7GasqnWZslqAk9wJv6EHbYvV0C6qULNwAao/ z6FhsQwvFjn8/wLWSdei854GknkBUuaiIZzhgjfNhnpRCbu8Z1DT3GqVCLMVICVdI1kDQkqwVvos/Wxd @@ -210,6 +213,9 @@ IEcrx3nZquyh7NsISVnw5bFgit2/J/uPz/w7PYg4GfFdEjIAAAAASUVORK5CYII= + + 466, 20 + AAABAAgAAAAAAAEAIACJiQAAhgAAAICAAAABACAAKAgBAA+KAABISAAAAQAgAIhUAAA3kgEAQEAAAAEA