Merge pull request #1 from KettlerX7AvansA5/develop

Merge new version into master
This commit is contained in:
2015-09-05 21:47:15 +02:00
10 changed files with 261 additions and 73 deletions
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ErgometerSimulator
{
class ComPort
{
private SerialPort comPort;
private ErgometerSimulator ergs;
public ComPort(ErgometerSimulator ergs)
{
comPort = null;
this.ergs = ergs;
}
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.DataReceived += ComPort_DataReceived;
comPort.Open();
return comPort.IsOpen;
}
private void ComPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ergs.ReceivedCommand(Read());
}
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,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ErgometerSimulator
{
class CommandParser
{
private static Random rand = new Random();
public static string Parse(string input)
{
string response = "";
switch(input)
{
case "CM":
case "RS":
response = "ACK";
break;
case "ST":
response += rand.Next(90, 140) + "\t"; //Heartbeat
response += rand.Next(20, 40) + "\t"; //RPM
response += rand.Next(50, 350) + "\t"; //Speed
response += rand.Next(10, 999) + "\t"; //Distance
response += rand.Next(25, 400) + "\t"; //Power
response += rand.Next(5, 55) + "\t"; //Energy
response += rand.Next(0, 24) + ":" + rand.Next(0, 60) + "\t"; //Time
response += rand.Next(25, 400); //ActualPower
break;
default:
break;
}
return response;
}
}
}
@@ -0,0 +1,77 @@
using System.IO.Ports;
namespace ErgometerSimulator
{
partial class ErgometerSimulator
{
/// <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.connectButton = new System.Windows.Forms.Button();
this.ComPortBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// connectButton
//
this.connectButton.Location = new System.Drawing.Point(139, 12);
this.connectButton.Name = "connectButton";
this.connectButton.Size = new System.Drawing.Size(101, 27);
this.connectButton.TabIndex = 0;
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(new object[] {
"COM5",
"COM4"});
this.ComPortBox.Location = new System.Drawing.Point(12, 12);
this.ComPortBox.Name = "ComPortBox";
this.ComPortBox.Size = new System.Drawing.Size(121, 24);
this.ComPortBox.TabIndex = 1;
//
// ErgometerSimulator
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(351, 87);
this.Controls.Add(this.ComPortBox);
this.Controls.Add(this.connectButton);
this.Name = "ErgometerSimulator";
this.Text = "Ergometer Simulator";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button connectButton;
private System.Windows.Forms.ComboBox ComPortBox;
}
}
@@ -0,0 +1,54 @@
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 ErgometerSimulator
{
public partial class ErgometerSimulator : Form
{
ComPort comPort;
public ErgometerSimulator()
{
InitializeComponent();
comPort = new ComPort(this);
}
private void connectButton_Click(object sender, EventArgs e)
{
if (!comPort.IsOpen())
{
if (comPort.Connect(ComPortBox.Text))
{
connectButton.Text = "Disconnect";
ComPortBox.Enabled = false;
}
}
else
{
if (comPort.Disconnect())
{
connectButton.Text = "Connect";
ComPortBox.Enabled = true;
}
}
}
public void ReceivedCommand(string command)
{
string response = CommandParser.Parse(command);
string display = command + " :_: " + response;
Console.WriteLine(display);
comPort.Write(response);
}
}
}
@@ -46,16 +46,18 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="CommandParser.cs" />
<Compile Include="ComPort.cs" />
<Compile Include="ErgometerSimulator.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="ErgometerSimulator.Designer.cs">
<DependentUpon>ErgometerSimulator.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="ErgometerSimulator.resx">
<DependentUpon>ErgometerSimulator.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
-47
View File
@@ -1,47 +0,0 @@
namespace ErgometerSimulator
{
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.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(370, 253);
this.Name = "Form1";
this.Text = "Ergometer Simulator";
this.ResumeLayout(false);
}
#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 ErgometerSimulator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace ErgometerSimulator
{
@@ -16,7 +17,8 @@ namespace ErgometerSimulator
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new ErgometerSimulator());
}
}
}
+6
View File
@@ -0,0 +1,6 @@
# ErgometerSimulator
Simulator for the Ergometer used in the Remote Healthcare application
##Installatie
Om de simulator te laten werken moet je een virtuele comport opzetten. Om dit te doen kan je gebruik maken van com0com. Deze kan je hier downloaden: https://code.google.com/p/powersdr-iq/downloads/detail?name=setup_com0com_W7_x64_signed.exe&can=2&q=
Volg de setup helemaal en vink aan het einde "Start setup" aan. Verander in het geopende window de namen van de comporten naar degene die je in je simulator en uitlees applicatie gebruikt. Klik apply. Nu kan je gebruik maken van de virtuele seriele verbinding.