Copied files from ErgometerUitlezer

This commit is contained in:
Aareschluchtje
2015-09-14 11:23:46 +02:00
parent f9b4eb9627
commit 54dfa7131b
20 changed files with 531 additions and 74 deletions
@@ -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 ErgometerApplication
{
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 "";
}
}
}
@@ -0,0 +1,207 @@
using System.IO.Ports;
namespace ErgometerApplication
{
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;
}
}
@@ -0,0 +1,165 @@
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 ErgometerApplication
{
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;
richTextBox1.Text = "";
}
}
}
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)
{
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
string[] temp = inputTextBox.Text.Split(':');
comPort.Write("PT " + temp[0] + temp[1]);
Console.WriteLine("PT " + temp[0] + temp[1]);
inputTextBox.Text = "";
comPort.Read();
}
private void distanceButton_Click(object sender, EventArgs e)
{
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
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)
{
comPort.Write("RS");
comPort.Read();
Thread.Sleep(200);
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();
}
}
}
}
@@ -46,11 +46,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="Meting.cs" />
<Compile Include="FormatHelper.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="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -1,39 +0,0 @@
namespace ErgometerApplication
{
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
}
}
@@ -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 ErgometerApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ErgometerApplication
{
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);
}
}
}
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ErgometerApplication
{
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;
}
}
}
@@ -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 ErgometerApplication
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new Ergometer());
}
}
}
@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
@@ -1 +1,9 @@
C:\Users\sander\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerApplication.exe.config
C:\Users\Remco\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerApplication.exe.config
C:\Users\Remco\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerApplication.exe
C:\Users\Remco\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\bin\Debug\ErgometerApplication.pdb
C:\Users\Remco\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.csprojResolveAssemblyReference.cache
C:\Users\Remco\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.Properties.Resources.resources
C:\Users\Remco\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.csproj.GenerateResource.Cache
C:\Users\Remco\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.exe
C:\Users\Remco\Documents\GitHub\ErgometerApplication\ErgometerApplication\ErgometerApplication\obj\Debug\ErgometerApplication.pdb