From 217035b528edeb8b325e41b3fd6f65518c77a9eb Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 20 Oct 2015 00:28:36 +0200 Subject: [PATCH] Removed unused code. Added timeout to comport read. --- ErgometerLibrary/ComPort.cs | 9 ++++++++- ErgometerLibrary/NetCommand.cs | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ErgometerLibrary/ComPort.cs b/ErgometerLibrary/ComPort.cs index 176a372..5eef50b 100644 --- a/ErgometerLibrary/ComPort.cs +++ b/ErgometerLibrary/ComPort.cs @@ -24,6 +24,7 @@ namespace ErgometerLibrary comPort.Parity = Parity.None; comPort.StopBits = StopBits.One; comPort.BaudRate = 9600; + comPort.ReadTimeout = 1500; comPort.Open(); @@ -56,7 +57,13 @@ namespace ErgometerLibrary { if (IsOpen()) { - return comPort.ReadLine(); + try { + return comPort.ReadLine(); + } + catch(TimeoutException e) + { + return "error"; + } } return ""; diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index d7b5c36..7b5dc52 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -9,10 +9,10 @@ namespace ErgometerLibrary public class NetCommand { public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST, LENGTH, SESSIONDATA, ERROR } - public enum RequestType { USERS, ALLSESSIONS, CURRENTSESSIONS, OLDDATA, SESSIONDATA } + public enum RequestType { USERS, ALLSESSIONS, OLDDATA, SESSIONDATA } public enum ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN } public enum ValueType { TIME, POWER, ENERGY, DISTANCE } - public enum LengthType { USERS, SESSIONS, SESSIONDATA, DATA, CURRENTSESSIONS } + public enum LengthType { USERS, SESSIONS, SESSIONDATA, DATA } public double Timestamp { get; set; } public int Session { get; set; } @@ -117,6 +117,7 @@ namespace ErgometerLibrary Type = CommandType.USER; Session = session; DisplayName = username; + Password = password; } //LOGIN @@ -211,8 +212,6 @@ namespace ErgometerLibrary return new NetCommand(LengthType.SESSIONS, int.Parse(args[1]), session); case "data": return new NetCommand(LengthType.DATA, int.Parse(args[1]), session); - case "currentsessions": - return new NetCommand(LengthType.CURRENTSESSIONS, int.Parse(args[1]), session); default: throw new FormatException("Error in NetCommand: Length type not recognised"); } @@ -229,8 +228,6 @@ namespace ErgometerLibrary return new NetCommand(RequestType.USERS, session); case "allsessions": return new NetCommand(RequestType.ALLSESSIONS, session); - case "currentsessions": - return new NetCommand(RequestType.CURRENTSESSIONS, session); case "olddata": return new NetCommand(RequestType.OLDDATA, session); case "sessiondata": @@ -383,6 +380,9 @@ namespace ErgometerLibrary case CommandType.SESSIONDATA: command += "11»ses" + Session + "»" + DisplayName; break; + case CommandType.ERROR: + command += "ERROR IN NETCOMMAND"; + break; default: throw new FormatException("Error in NetCommand: Cannot find type of command");