diff --git a/ErgometerApplication/.vs/ErgometerApplication/v14/.suo b/ErgometerApplication/.vs/ErgometerApplication/v14/.suo index aba3c9a..ea97c36 100644 Binary files a/ErgometerApplication/.vs/ErgometerApplication/v14/.suo and b/ErgometerApplication/.vs/ErgometerApplication/v14/.suo differ diff --git a/ErgometerApplication/ErgometerApplication/ChartPanel.cs b/ErgometerApplication/ErgometerApplication/ChartPanel.cs index fde0ab9..423df00 100644 --- a/ErgometerApplication/ErgometerApplication/ChartPanel.cs +++ b/ErgometerApplication/ErgometerApplication/ChartPanel.cs @@ -6,19 +6,22 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; + namespace ErgometerApplication { - public class ChartPanel:Panel + public class ChartPanel : Panel { private Chart chart; private MetingType type; private ChartArea chartArea; private Series series; + private SeriesChartType ChartType; - public ChartPanel(MetingType type) : base() + public ChartPanel(MetingType type, SeriesChartType charttype) : base() { this.type = type; - + this.ChartType = charttype; + this.chart = new Chart(); this.chartArea = new ChartArea(); this.chart.Titles.Add(new Title(type.ToString())); @@ -32,7 +35,7 @@ namespace ErgometerApplication this.chartArea.Name = "chartArea"; this.chart.Size = new System.Drawing.Size(250, 200); - + this.chart.Dock = DockStyle.Fill; this.chart.Series.Add(series); this.chart.Text = "chart"; @@ -56,7 +59,7 @@ namespace ErgometerApplication { Series serie = new Series(); serie.Name = "series"; - serie.ChartType = SeriesChartType.Line; + serie.ChartType = ChartType; serie.ChartArea = "chartArea"; serie.BorderWidth = 3; return serie; @@ -64,7 +67,7 @@ namespace ErgometerApplication public int getMetingType(Meting meting) { - switch(type) + switch (type) { case MetingType.HEARTBEAT: return meting.HeartBeat; @@ -83,7 +86,7 @@ namespace ErgometerApplication case MetingType.ACTUALPOWER: return meting.ActualPower; default: - return 0; + return 0; } } @@ -96,7 +99,7 @@ namespace ErgometerApplication POWER, ENERGY, SECONDS, - ACTUALPOWER + ACTUALPOWER } } } diff --git a/ErgometerApplication/ErgometerApplication/ClientApplicatie.Designer.cs b/ErgometerApplication/ErgometerApplication/ClientApplicatie.Designer.cs index 040f542..43f68a1 100644 --- a/ErgometerApplication/ErgometerApplication/ClientApplicatie.Designer.cs +++ b/ErgometerApplication/ErgometerApplication/ClientApplicatie.Designer.cs @@ -57,7 +57,7 @@ namespace ErgometerApplication // // updateTimer // - this.updateTimer.Interval = 800; + this.updateTimer.Interval = 600; this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick); // // panelClientContainer diff --git a/ErgometerApplication/ErgometerApplication/ClientApplicatie.cs b/ErgometerApplication/ErgometerApplication/ClientApplicatie.cs index 45d65bf..7b87357 100644 --- a/ErgometerApplication/ErgometerApplication/ClientApplicatie.cs +++ b/ErgometerApplication/ErgometerApplication/ClientApplicatie.cs @@ -32,10 +32,8 @@ namespace ErgometerApplication private void updateTimer_Tick(object sender, EventArgs e) { - Console.WriteLine("Trying to send data...."); if(MainClient.Doctor.Connected) { - Console.WriteLine("Sending data"); MainClient.ComPort.Write("ST"); string response = MainClient.ComPort.Read(); Meting m = MainClient.SaveMeting(response); diff --git a/ErgometerApplication/ErgometerApplication/MainClient.cs b/ErgometerApplication/ErgometerApplication/MainClient.cs index 26506af..3f9806f 100644 --- a/ErgometerApplication/ErgometerApplication/MainClient.cs +++ b/ErgometerApplication/ErgometerApplication/MainClient.cs @@ -13,7 +13,7 @@ namespace ErgometerApplication { public static ComPort ComPort { get; } - public static TcpClient Doctor { get; } + public static TcpClient Doctor { get; set; } public static List Metingen { get; } public static List Chat { get; } @@ -37,8 +37,6 @@ namespace ErgometerApplication Metingen = new List(); Chat = new List(); - t = new Thread(run); - Name = "Unknown"; Session = 0; Loggedin = false; @@ -53,16 +51,21 @@ namespace ErgometerApplication { error = "Succes"; - if (!Doctor.Connected) + if (Doctor == null || !Doctor.Connected) { - try { + if (Doctor == null) + Doctor = new TcpClient(); + + try + { Doctor.Connect(HOST, PORT); } catch (Exception e) { - error = "De server is niet online."; + error = "Server is niet online."; return false; } + Name = name; NetCommand net = NetHelper.ReadNetCommand(Doctor); @@ -72,6 +75,8 @@ namespace ErgometerApplication throw new Exception("Session not assigned"); running = true; + + t = new Thread(run); t.IsBackground = true; t.Start(); } @@ -105,7 +110,6 @@ namespace ErgometerApplication ComPort.Write("ST"); string response = ComPort.Read(); - Console.WriteLine(response); SaveMeting(response); } @@ -136,6 +140,8 @@ namespace ErgometerApplication NetHelper.SendNetCommand(Doctor, new NetCommand(NetCommand.CommandType.LOGOUT, Session)); Loggedin = false; running = false; + Doctor.Close(); + Doctor = null; } } @@ -183,6 +189,9 @@ namespace ErgometerApplication case NetCommand.CommandType.SESSION: Session = command.Session; break; + case NetCommand.CommandType.ERROR: + Console.WriteLine("An error occured, ignoring"); + break; default: throw new FormatException("Error in Netcommand: Received command not recognized"); } diff --git a/ErgometerApplication/ErgometerApplication/PanelClientDataView.cs b/ErgometerApplication/ErgometerApplication/PanelClientDataView.cs index fe3d405..4c27172 100644 --- a/ErgometerApplication/ErgometerApplication/PanelClientDataView.cs +++ b/ErgometerApplication/ErgometerApplication/PanelClientDataView.cs @@ -5,10 +5,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; namespace ErgometerApplication { - public class PanelGraphView:Panel + public class PanelGraphView : Panel { private List charts; @@ -16,7 +17,7 @@ namespace ErgometerApplication public PanelGraphView() : base() { - createCharts(); + createCharts(); flowlayout = new FlowLayoutPanel(); @@ -26,22 +27,13 @@ namespace ErgometerApplication flowlayout.Name = "flowlayout"; flowlayout.Padding = new Padding(15); flowlayout.AutoScroll = true; - foreach(ChartPanel chart in charts) + foreach (ChartPanel chart in charts) { flowlayout.Controls.Add(chart); } List metingen = new List(); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); - metingen.Add(new Meting(23, 25, 12, 46, 13, 25, 13, 1, 32)); + metingen.Add(new Meting(0, 0, 0, 0, 0, 0, 0, 0, 0)); updateAllCharts(metingen); // @@ -59,19 +51,18 @@ namespace ErgometerApplication public void createCharts() { charts = new List(); - charts.Add(new ChartPanel(ChartPanel.MetingType.HEARTBEAT)); - charts.Add(new ChartPanel(ChartPanel.MetingType.RPM)); - charts.Add(new ChartPanel(ChartPanel.MetingType.SPEED)); - charts.Add(new ChartPanel(ChartPanel.MetingType.DISTANCE)); - charts.Add(new ChartPanel(ChartPanel.MetingType.ENERGY)); - charts.Add(new ChartPanel(ChartPanel.MetingType.SECONDS)); - charts.Add(new ChartPanel(ChartPanel.MetingType.POWER)); - charts.Add(new ChartPanel(ChartPanel.MetingType.ACTUALPOWER)); + charts.Add(new ChartPanel(ChartPanel.MetingType.HEARTBEAT, SeriesChartType.Line)); + charts.Add(new ChartPanel(ChartPanel.MetingType.RPM, SeriesChartType.Line)); + charts.Add(new ChartPanel(ChartPanel.MetingType.SPEED, SeriesChartType.Line)); + charts.Add(new ChartPanel(ChartPanel.MetingType.DISTANCE, SeriesChartType.Line)); + charts.Add(new ChartPanel(ChartPanel.MetingType.ENERGY, SeriesChartType.Line)); + charts.Add(new ChartPanel(ChartPanel.MetingType.POWER, SeriesChartType.Line)); + charts.Add(new ChartPanel(ChartPanel.MetingType.ACTUALPOWER, SeriesChartType.Line)); } public void updateAllCharts(List metingen) { - foreach(ChartPanel chart in charts) + foreach (ChartPanel chart in charts) { chart.updateChart(metingen); } diff --git a/ErgometerApplication/ErgometerApplication/bin/Debug/ErgometerLibrary.dll b/ErgometerApplication/ErgometerApplication/bin/Debug/ErgometerLibrary.dll index eacc8eb..8ef32a7 100644 Binary files a/ErgometerApplication/ErgometerApplication/bin/Debug/ErgometerLibrary.dll and b/ErgometerApplication/ErgometerApplication/bin/Debug/ErgometerLibrary.dll differ