Changed something
This commit is contained in:
Binary file not shown.
@@ -1,65 +0,0 @@
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using ErgometerLibrary;
|
||||
|
||||
namespace ErgometerApplication
|
||||
{
|
||||
@@ -55,7 +56,7 @@ namespace ErgometerApplication
|
||||
string response = comPort.Read();
|
||||
Console.WriteLine(response);
|
||||
|
||||
Meting m = FormatHelper.Status(response);
|
||||
Meting m = Meting.Parse(response);
|
||||
SaveData(m);
|
||||
richTextBox1.Text = m.ToString();
|
||||
}
|
||||
@@ -90,7 +91,7 @@ namespace ErgometerApplication
|
||||
comPort.Write("ST");
|
||||
string response = comPort.Read();
|
||||
Console.WriteLine(response);
|
||||
Meting m = FormatHelper.Status(response);
|
||||
Meting m = Meting.Parse(response);
|
||||
SaveData(m);
|
||||
richTextBox1.Text = m.ToString();
|
||||
|
||||
@@ -113,7 +114,7 @@ namespace ErgometerApplication
|
||||
comPort.Write("ST");
|
||||
string response = comPort.Read();
|
||||
Console.WriteLine(response);
|
||||
Meting m = FormatHelper.Status(response);
|
||||
Meting m = Meting.Parse(response);
|
||||
SaveData(m);
|
||||
richTextBox1.Text = m.ToString();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ErgometerLibrary">
|
||||
<HintPath>..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@@ -50,9 +53,6 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Meting.cs" />
|
||||
<Compile Include="FormatHelper.cs" />
|
||||
<Compile Include="Comport.cs" />
|
||||
<Compile Include="Ergometer.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -87,6 +87,9 @@
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Service References\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
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, (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ErgometerApplication
|
||||
{
|
||||
public class Meting
|
||||
{
|
||||
public int HeartBeat { get; set; }
|
||||
public int RPM { get; set; }
|
||||
public double Speed { get; set; }
|
||||
public double Distance { get; set; }
|
||||
public int Power { get; set; }
|
||||
public int Energy { get; set; }
|
||||
public int Seconds { get; set; }
|
||||
public int ActualPower { get; set; }
|
||||
public double TimeStamp { get; }
|
||||
|
||||
public Meting(int heartbeat, int rpm, double speed, double distance, int power, int energy, int seconds, int actualpower, double timestamp)
|
||||
{
|
||||
HeartBeat = heartbeat;
|
||||
RPM = rpm;
|
||||
Speed = speed;
|
||||
Distance = distance;
|
||||
Power = power;
|
||||
Energy = energy;
|
||||
Seconds = seconds;
|
||||
ActualPower = actualpower;
|
||||
TimeStamp = timestamp;
|
||||
}
|
||||
public Meting()
|
||||
{
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user