Merge pull request #1 from KettlerX7AvansA5/develop

Merge working version into master
This commit is contained in:
2015-09-05 21:45:04 +02:00
10 changed files with 641 additions and 63 deletions
+65
View File
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ErgometerUitlezer
{
class ComPort
{
private SerialPort comPort;
public ComPort()
{
comPort = null;
}
public Boolean Connect(string port)
{
comPort = new SerialPort();
comPort.PortName = port;
comPort.DataBits = 8;
comPort.Parity = Parity.None;
comPort.StopBits = StopBits.One;
comPort.BaudRate = 9600;
comPort.Open();
return comPort.IsOpen;
}
public Boolean Disconnect()
{
comPort.Close();
return !comPort.IsOpen;
}
public Boolean IsOpen()
{
if (comPort != null)
return comPort.IsOpen;
else
return false;
}
public void Write(string input)
{
if(IsOpen())
{
comPort.WriteLine(input);
}
}
public string Read()
{
if (IsOpen())
{
return comPort.ReadLine();
}
return "";
}
}
}
+208
View File
@@ -0,0 +1,208 @@
using System.IO.Ports;
namespace ErgometerUitlezer
{
partial class Ergometer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.connectButton = new System.Windows.Forms.Button();
this.ComPortBox = new System.Windows.Forms.ComboBox();
this.statusButton = new System.Windows.Forms.Button();
this.resetButton = new System.Windows.Forms.Button();
this.updateTimer = new System.Windows.Forms.Timer(this.components);
this.timerStatus = new System.Windows.Forms.CheckBox();
this.inputTextBox = new System.Windows.Forms.TextBox();
this.powerButton = new System.Windows.Forms.Button();
this.timeButton = new System.Windows.Forms.Button();
this.energyButton = new System.Windows.Forms.Button();
this.distanceButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(13, 42);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.ReadOnly = true;
this.richTextBox1.Size = new System.Drawing.Size(203, 243);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// connectButton
//
this.connectButton.Location = new System.Drawing.Point(115, 291);
this.connectButton.Name = "connectButton";
this.connectButton.Size = new System.Drawing.Size(101, 26);
this.connectButton.TabIndex = 1;
this.connectButton.Text = "Connect";
this.connectButton.UseVisualStyleBackColor = true;
this.connectButton.Click += new System.EventHandler(this.connectButton_Click);
//
// ComPortBox
//
this.ComPortBox.FormattingEnabled = true;
this.ComPortBox.Items.AddRange(SerialPort.GetPortNames());
this.ComPortBox.Location = new System.Drawing.Point(12, 291);
this.ComPortBox.Name = "ComPortBox";
this.ComPortBox.Size = new System.Drawing.Size(97, 24);
this.ComPortBox.SelectedItem = 1;
//
// statusButton
//
this.statusButton.Enabled = false;
this.statusButton.Location = new System.Drawing.Point(127, 12);
this.statusButton.Name = "statusButton";
this.statusButton.Size = new System.Drawing.Size(89, 26);
this.statusButton.TabIndex = 3;
this.statusButton.Text = "Status";
this.statusButton.UseVisualStyleBackColor = true;
this.statusButton.Click += new System.EventHandler(this.statusButton_Click);
//
// resetButton
//
this.resetButton.Enabled = false;
this.resetButton.Location = new System.Drawing.Point(12, 12);
this.resetButton.Name = "resetButton";
this.resetButton.Size = new System.Drawing.Size(97, 26);
this.resetButton.TabIndex = 4;
this.resetButton.Text = "Reset";
this.resetButton.UseVisualStyleBackColor = true;
this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
//
// updateTimer
//
this.updateTimer.Interval = 1500;
this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick);
//
// timerStatus
//
this.timerStatus.AutoSize = true;
this.timerStatus.Enabled = false;
this.timerStatus.Location = new System.Drawing.Point(223, 12);
this.timerStatus.Name = "timerStatus";
this.timerStatus.Size = new System.Drawing.Size(113, 21);
this.timerStatus.TabIndex = 5;
this.timerStatus.Text = "Auto Refresh";
this.timerStatus.UseVisualStyleBackColor = true;
this.timerStatus.CheckedChanged += new System.EventHandler(this.timerStatus_CheckedChanged);
//
// inputTextBox
//
this.inputTextBox.Enabled = false;
this.inputTextBox.Location = new System.Drawing.Point(223, 42);
this.inputTextBox.Name = "inputTextBox";
this.inputTextBox.Size = new System.Drawing.Size(113, 22);
this.inputTextBox.TabIndex = 6;
//
// powerButton
//
this.powerButton.Enabled = false;
this.powerButton.Location = new System.Drawing.Point(223, 134);
this.powerButton.Name = "powerButton";
this.powerButton.Size = new System.Drawing.Size(113, 26);
this.powerButton.TabIndex = 7;
this.powerButton.Text = "Set Power";
this.powerButton.UseVisualStyleBackColor = true;
this.powerButton.Click += new System.EventHandler(this.powerButton_Click);
//
// timeButton
//
this.timeButton.Enabled = false;
this.timeButton.Location = new System.Drawing.Point(223, 70);
this.timeButton.Name = "timeButton";
this.timeButton.Size = new System.Drawing.Size(113, 26);
this.timeButton.TabIndex = 8;
this.timeButton.Text = "Set Time";
this.timeButton.UseVisualStyleBackColor = true;
this.timeButton.Click += new System.EventHandler(this.timeButton_Click);
//
// energyButton
//
this.energyButton.Enabled = false;
this.energyButton.Location = new System.Drawing.Point(223, 166);
this.energyButton.Name = "energyButton";
this.energyButton.Size = new System.Drawing.Size(113, 26);
this.energyButton.TabIndex = 9;
this.energyButton.Text = "Set Energy";
this.energyButton.UseVisualStyleBackColor = true;
this.energyButton.Click += new System.EventHandler(this.energyButton_Click);
//
// distanceButton
//
this.distanceButton.Enabled = false;
this.distanceButton.Location = new System.Drawing.Point(223, 102);
this.distanceButton.Name = "distanceButton";
this.distanceButton.Size = new System.Drawing.Size(113, 26);
this.distanceButton.TabIndex = 10;
this.distanceButton.Text = "Set Distance";
this.distanceButton.UseVisualStyleBackColor = true;
this.distanceButton.Click += new System.EventHandler(this.distanceButton_Click);
//
// Ergometer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(351, 328);
this.Controls.Add(this.distanceButton);
this.Controls.Add(this.energyButton);
this.Controls.Add(this.timeButton);
this.Controls.Add(this.powerButton);
this.Controls.Add(this.inputTextBox);
this.Controls.Add(this.timerStatus);
this.Controls.Add(this.resetButton);
this.Controls.Add(this.statusButton);
this.Controls.Add(this.ComPortBox);
this.Controls.Add(this.connectButton);
this.Controls.Add(this.richTextBox1);
this.MaximumSize = new System.Drawing.Size(369, 375);
this.MinimumSize = new System.Drawing.Size(369, 375);
this.Name = "Ergometer";
this.Text = "Ergometer";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button connectButton;
private System.Windows.Forms.ComboBox ComPortBox;
private System.Windows.Forms.Button statusButton;
private System.Windows.Forms.Button resetButton;
private System.Windows.Forms.Timer updateTimer;
private System.Windows.Forms.CheckBox timerStatus;
private System.Windows.Forms.TextBox inputTextBox;
private System.Windows.Forms.Button powerButton;
private System.Windows.Forms.Button timeButton;
private System.Windows.Forms.Button energyButton;
private System.Windows.Forms.Button distanceButton;
}
}
+156
View File
@@ -0,0 +1,156 @@
using System;
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;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ErgometerUitlezer
{
public partial class Ergometer : Form
{
private ComPort comPort;
public Ergometer()
{
InitializeComponent();
comPort = new ComPort();
}
private void connectButton_Click(object sender, EventArgs e)
{
if(!comPort.IsOpen())
{
if (comPort.Connect(ComPortBox.Text))
{
connectButton.Text = "Disconnect";
statusButton.Enabled = true;
resetButton.Enabled = true;
timerStatus.Enabled = true;
inputTextBox.Enabled = true;
timeButton.Enabled = true;
distanceButton.Enabled = true;
powerButton.Enabled = true;
energyButton.Enabled = true;
ComPortBox.Enabled = false;
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
comPort.Write("CM");
comPort.Read();
Thread.Sleep(200);
comPort.Write("ST");
string response = comPort.Read();
Console.WriteLine(response);
Meting test = FormatHelper.Status(response);
string test2 = test.ToString();
richTextBox1.Text = test2;
}
}
else
{
if(comPort.Disconnect())
{
connectButton.Text = "Connect";
timerStatus.Checked = false;
statusButton.Enabled = false;
resetButton.Enabled = false;
timerStatus.Enabled = false;
inputTextBox.Enabled = false;
timeButton.Enabled = false;
distanceButton.Enabled = false;
powerButton.Enabled = false;
energyButton.Enabled = false;
ComPortBox.Enabled = true;
}
}
}
private void statusButton_Click(object sender, EventArgs e)
{
comPort.Write("ST");
string response = comPort.Read();
Console.WriteLine(response);
richTextBox1.Text = FormatHelper.Status(response).ToString();
}
private void resetButton_Click(object sender, EventArgs e)
{
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
comPort.Write("CM");
comPort.Read();
}
private void updateTimer_Tick(object sender, EventArgs e)
{
if(timerStatus.Checked)
{
comPort.Write("ST");
string response = comPort.Read();
Console.WriteLine(response);
richTextBox1.Text = FormatHelper.Status(response).ToString();
}
}
private void timeButton_Click(object sender, EventArgs e)
{
string[] temp = inputTextBox.Text.Split(':');
int minutes = int.Parse(temp[0]);
int seconds = int.Parse(temp[1]);
comPort.Write("PT " + minutes.ToString() + seconds.ToString());
inputTextBox.Text = "";
comPort.Read();
}
private void distanceButton_Click(object sender, EventArgs e)
{
int temp = int.Parse(inputTextBox.Text);
comPort.Write("PD " + temp.ToString());
inputTextBox.Text = "";
comPort.Read();
}
private void powerButton_Click(object sender, EventArgs e)
{
int temp = int.Parse(inputTextBox.Text);
comPort.Write("PW " + temp.ToString());
inputTextBox.Text = "";
comPort.Read();
}
private void energyButton_Click(object sender, EventArgs e)
{
int temp = int.Parse(inputTextBox.Text);
comPort.Write("PE " + temp.ToString());
inputTextBox.Text = "";
comPort.Read();
}
private void timerStatus_CheckedChanged(object sender, EventArgs e)
{
if (timerStatus.Checked)
{
statusButton.Enabled = false;
updateTimer.Start();
}
else
{
statusButton.Enabled = true;
updateTimer.Stop();
}
}
}
}
+123
View File
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="updateTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
+9 -3
View File
@@ -46,14 +46,20 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="ComPort.cs" />
<Compile Include="Ergometer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="Ergometer.Designer.cs">
<DependentUpon>Ergometer.cs</DependentUpon>
</Compile>
<Compile Include="FormatHelper.cs" />
<Compile Include="Meting.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Ergometer.resx">
<DependentUpon>Ergometer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
-39
View File
@@ -1,39 +0,0 @@
namespace ErgometerUitlezer
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}
#endregion
}
}
-20
View File
@@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ErgometerUitlezer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
+32
View File
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ErgometerUitlezer
{
class FormatHelper
{
public static Meting Status(string input)
{
String[] status = input.Split('\t');
if (status.Length != 8)
return null;
int heartbeat = int.Parse(status[0]);
int rpm = int.Parse(status[1]);
double speed = double.Parse(status[2]) / 10;
double distance = double.Parse(status[3]) / 10;
int power = int.Parse(status[4]);
int energy = int.Parse(status[5]);
int actualpower = int.Parse(status[7]);
string[] temp = status[6].Split(':');
int seconds = (int.Parse(temp[0]) * 60) + (int.Parse(temp[1]));
return new Meting(heartbeat, rpm, speed, distance, power, energy, seconds, actualpower);
}
}
}
+46
View File
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ErgometerUitlezer
{
class Meting
{
public int HeartBeat { get; }
public int RPM { get; }
public double Speed { get; }
public double Distance { get; }
public int Power { get; }
public int Energy { get; }
public int Seconds { get; }
public int ActualPower { get; }
public Meting(int heartbeat, int rpm, double speed, double distance, int power, int energy, int seconds, int actualpower)
{
HeartBeat = heartbeat;
RPM = rpm;
Speed = speed;
Distance = distance;
Power = power;
Energy = energy;
Seconds = seconds;
ActualPower = actualpower;
}
public override string ToString()
{
string temp = "";
temp += "Heartbeat: " + HeartBeat + "\n";
temp += "RPM: " + RPM + "\n";
temp += "Speed: " + Speed + "\n";
temp += "Distance: " + Distance + "\n";
temp += "Power: " + Power + "\n";
temp += "Energy: " + Energy + "\n";
temp += "Seconds: " + Seconds + "\n";
temp += "ActualPower: " + ActualPower + "\n";
return temp;
}
}
}
+2 -1
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -16,7 +17,7 @@ namespace ErgometerUitlezer
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new Ergometer());
}
}
}