Ver Fonte

added comport selector

Karel van Waveren há 10 anos atrás
pai
commit
9ccca5acee

+ 1 - 1
Proftaak Remote Healthcare/FietsSimulator/Program.cs

@@ -12,7 +12,7 @@ namespace FietsSimulator
     {
         static void Main(string[] args)
         {
-            new FietsSimulator("COM6");
+            new FietsSimulator("COM4");
             while(true)
             {
                 Thread.Sleep(10);

+ 2 - 1
Proftaak Remote Healthcare/Fietsclient/AppGlobal.cs

@@ -29,11 +29,12 @@ namespace Fietsclient
 
         public void startComPort()
         {
-            startComPort("COM5");
+            startComPort("COM3");
         }
 
         public void startComPort(string portname)
         {
+            Console.WriteLine(portname);
             _bikeComm.initComm(portname);
         }
 

+ 4 - 1
Proftaak Remote Healthcare/Fietsclient/Fietsclient.csproj

@@ -5,7 +5,7 @@
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <ProjectGuid>{49668592-ED5D-4907-9EA7-2DF70AB96271}</ProjectGuid>
-    <OutputType>WinExe</OutputType>
+    <OutputType>Exe</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Fietsclient</RootNamespace>
     <AssemblyName>Fietsclient</AssemblyName>
@@ -32,6 +32,9 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup>
+    <StartupObject />
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />

+ 12 - 0
Proftaak Remote Healthcare/Fietsclient/MainForm.Designer.cs

@@ -32,6 +32,7 @@
             this.textBox1 = new System.Windows.Forms.TextBox();
             this.button2 = new System.Windows.Forms.Button();
             this.button3 = new System.Windows.Forms.Button();
+            this.cmbComport = new System.Windows.Forms.ComboBox();
             this.SuspendLayout();
             // 
             // button1
@@ -75,12 +76,22 @@
             this.button3.UseVisualStyleBackColor = true;
             this.button3.Click += new System.EventHandler(this.button3_Click);
             // 
+            // cmbComport
+            // 
+            this.cmbComport.FormattingEnabled = true;
+            this.cmbComport.Location = new System.Drawing.Point(188, 12);
+            this.cmbComport.Name = "cmbComport";
+            this.cmbComport.Size = new System.Drawing.Size(121, 21);
+            this.cmbComport.TabIndex = 4;
+            this.cmbComport.SelectionChangeCommitted += new System.EventHandler(this.cmbComport_SelectionChangeCommitted);
+            // 
             // MainForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.AutoScroll = true;
             this.ClientSize = new System.Drawing.Size(830, 343);
+            this.Controls.Add(this.cmbComport);
             this.Controls.Add(this.button3);
             this.Controls.Add(this.button2);
             this.Controls.Add(this.textBox1);
@@ -98,6 +109,7 @@
         private System.Windows.Forms.TextBox textBox1;
         private System.Windows.Forms.Button button2;
         private System.Windows.Forms.Button button3;
+        private System.Windows.Forms.ComboBox cmbComport;
     }
 }
 

+ 22 - 1
Proftaak Remote Healthcare/Fietsclient/MainForm.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
+using System.IO.Ports;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -14,16 +15,26 @@ namespace Fietsclient
     public partial class MainForm : Form
     {
         private readonly AppGlobal _global;
+        private SerialPort ComPort;
+        string port;
+
         public MainForm(AppGlobal global)
         {
             InitializeComponent();
             _global = global;
             KettlerBikeComm.IncomingDataEvent += HandleBikeData;
+            foreach (String item in getComports())
+            {
+                cmbComport.Items.Add(item);
+            }
+
         }
 
+
         private void button1_Click(object sender, EventArgs e)
         {
-            _global.startComPort();
+            _global.startComPort(port);
+
         }
 
         private void HandleBikeData(string[] data)
@@ -52,5 +63,15 @@ namespace Fietsclient
         {
             _global.closeComPort();
         }
+
+        private String[] getComports()
+        {
+            return SerialPort.GetPortNames();
+        }
+
+        private void cmbComport_SelectionChangeCommitted(object sender, EventArgs e)
+        {
+            port = cmbComport.SelectedItem.ToString();
+        }
     }
 }