Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
Binary file not shown.
@@ -73,9 +73,7 @@ namespace ErgometerApplication
|
||||
// ComPortBox
|
||||
//
|
||||
this.ComPortBox.FormattingEnabled = true;
|
||||
this.ComPortBox.Items.AddRange(new object[] {
|
||||
"COM8",
|
||||
"COM9"});
|
||||
this.ComPortBox.Items.AddRange(SerialPort.GetPortNames());
|
||||
this.ComPortBox.Location = new System.Drawing.Point(12, 290);
|
||||
this.ComPortBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.ComPortBox.Name = "ComPortBox";
|
||||
|
||||
@@ -13,6 +13,10 @@ using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using ErgometerLibrary;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Timers;
|
||||
using ErgometerLibrary;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
namespace ErgometerApplication
|
||||
{
|
||||
@@ -21,14 +25,15 @@ namespace ErgometerApplication
|
||||
private ComPort comPort;
|
||||
private List<Meting> _data;
|
||||
private int i = 0;
|
||||
int sessionID;
|
||||
NetCommand command;
|
||||
private ServerCommunicator communicator = new ServerCommunicator();
|
||||
List<Meting> readFile = new List<Meting>();
|
||||
public Ergometer()
|
||||
{
|
||||
InitializeComponent();
|
||||
comPort = new ComPort();
|
||||
_data = new List<Meting>();
|
||||
communicator.data = _data;
|
||||
}
|
||||
|
||||
private void connectButton_Click(object sender, EventArgs e)
|
||||
@@ -61,7 +66,7 @@ namespace ErgometerApplication
|
||||
|
||||
Meting m = Meting.Parse(response);
|
||||
SaveData(m);
|
||||
richTextBox1.Text = m.ToString();
|
||||
// richTextBox1.Text = m.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -85,7 +90,16 @@ namespace ErgometerApplication
|
||||
|
||||
}
|
||||
}
|
||||
sessionID = int.Parse(ReadServer());
|
||||
IPAddress ipAddress; //= IPAddress.Parse("127.0.0.1");
|
||||
|
||||
bool ipIsOk = IPAddress.TryParse("127.0.0.1", out ipAddress); //GetIp()
|
||||
if (!ipIsOk) { Console.WriteLine("ip adres kan niet geparsed worden."); Environment.Exit(1); }
|
||||
communicator.client = new TcpClient();
|
||||
communicator.client.Connect("127.0.0.1", 8888);
|
||||
communicator.reader = new StreamReader(communicator.client.GetStream(), Encoding.Unicode);
|
||||
communicator.writer = new StreamWriter(communicator.client.GetStream(), Encoding.Unicode);
|
||||
Thread thread = new Thread(ServerCommunication);
|
||||
thread.Start(communicator);
|
||||
}
|
||||
|
||||
private void statusButton_Click(object sender, EventArgs e)
|
||||
@@ -93,14 +107,37 @@ namespace ErgometerApplication
|
||||
comPort.Write("ST");
|
||||
string response = comPort.Read();
|
||||
Console.WriteLine(response);
|
||||
Meting m = Meting.Parse(response);
|
||||
Meting m = Meting.Parse(response, '\t');
|
||||
Console.WriteLine(m);
|
||||
SaveData(m);
|
||||
command = new NetCommand(m, sessionID);
|
||||
WriteServer(command.ToString());
|
||||
communicator.data.Add(m);
|
||||
command = new NetCommand(m, communicator.sessionId);
|
||||
communicator.writer.WriteLine(command.ToString());
|
||||
richTextBox1.Text = m.ToString();
|
||||
WriteFile();
|
||||
}
|
||||
|
||||
static void ServerCommunication(object obj)
|
||||
{
|
||||
ServerCommunicator communicator = obj as ServerCommunicator;
|
||||
communicator.reader = new StreamReader(communicator.client.GetStream(), Encoding.Unicode);
|
||||
communicator.writer = new StreamWriter(communicator.client.GetStream(), Encoding.Unicode);
|
||||
int sessionId = 0;
|
||||
communicator.writer.WriteLine("5»ses?");
|
||||
communicator.writer.Flush();
|
||||
string session = communicator.reader.ReadLine();
|
||||
if (session != null)
|
||||
{
|
||||
session = session.Remove(0, 5);
|
||||
sessionId = int.Parse(session);
|
||||
communicator.sessionId = sessionId;
|
||||
}
|
||||
NetCommand command = new NetCommand("name", false, sessionId);
|
||||
communicator.writer.WriteLine(command.ToString());
|
||||
communicator.writer.Flush();
|
||||
communicator.reader.ReadLine();
|
||||
}
|
||||
|
||||
private void resetButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
comPort.Write("RS");
|
||||
@@ -119,9 +156,13 @@ namespace ErgometerApplication
|
||||
Console.WriteLine(response);
|
||||
Meting m = Meting.Parse(response);
|
||||
SaveData(m);
|
||||
command = new NetCommand(m, sessionID);
|
||||
WriteServer(command.ToString());
|
||||
communicator.data.Add(m);
|
||||
command = new NetCommand(m, communicator.sessionId);
|
||||
communicator.writer.WriteLine(command.ToString());
|
||||
richTextBox1.Text = m.ToString();
|
||||
command = new NetCommand(communicator.data[0], communicator.sessionId);
|
||||
communicator.writer.WriteLine(command.ToString());
|
||||
communicator.writer.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,8 +224,6 @@ namespace ErgometerApplication
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void readButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
ReadFile();
|
||||
@@ -257,20 +296,5 @@ namespace ErgometerApplication
|
||||
readFile = null;
|
||||
}
|
||||
}
|
||||
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
|
||||
private String ReadServer()
|
||||
{
|
||||
|
||||
StreamReader reader = new StreamReader(client.GetStream(), Encoding.ASCII);
|
||||
String b = reader.ReadLine();
|
||||
return b;
|
||||
}
|
||||
private void WriteServer(String Send)
|
||||
{
|
||||
|
||||
StreamWriter stream = new StreamWriter(client.GetStream(), Encoding.ASCII);
|
||||
stream.WriteLine(Send);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,4 +123,10 @@
|
||||
<metadata name="writeTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>147, 19</value>
|
||||
</metadata>
|
||||
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>276, 19</value>
|
||||
</metadata>
|
||||
<metadata name="timer2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>377, 19</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -53,6 +53,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ServerCommunicator.cs" />
|
||||
<Compile Include="DataSaving.cs" />
|
||||
<Compile Include="Ergometer.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ErgometerLibrary;
|
||||
|
||||
namespace ErgometerApplication
|
||||
{
|
||||
class ServerCommunicator
|
||||
{
|
||||
public TcpClient client { get; set; }
|
||||
public StreamWriter writer { get; set; }
|
||||
public StreamReader reader { get; set; }
|
||||
public int sessionId { get; set; }
|
||||
public List<Meting> data { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user