Removed unused code. Added timeout to comport read.

This commit is contained in:
2015-10-20 00:28:36 +02:00
parent 2319c86320
commit 217035b528
2 changed files with 14 additions and 7 deletions
+8 -1
View File
@@ -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 "";
+6 -6
View File
@@ -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");