Removed unused code. Added timeout to comport read.
This commit is contained in:
@@ -24,6 +24,7 @@ namespace ErgometerLibrary
|
|||||||
comPort.Parity = Parity.None;
|
comPort.Parity = Parity.None;
|
||||||
comPort.StopBits = StopBits.One;
|
comPort.StopBits = StopBits.One;
|
||||||
comPort.BaudRate = 9600;
|
comPort.BaudRate = 9600;
|
||||||
|
comPort.ReadTimeout = 1500;
|
||||||
|
|
||||||
comPort.Open();
|
comPort.Open();
|
||||||
|
|
||||||
@@ -56,7 +57,13 @@ namespace ErgometerLibrary
|
|||||||
{
|
{
|
||||||
if (IsOpen())
|
if (IsOpen())
|
||||||
{
|
{
|
||||||
return comPort.ReadLine();
|
try {
|
||||||
|
return comPort.ReadLine();
|
||||||
|
}
|
||||||
|
catch(TimeoutException e)
|
||||||
|
{
|
||||||
|
return "error";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ namespace ErgometerLibrary
|
|||||||
public class NetCommand
|
public class NetCommand
|
||||||
{
|
{
|
||||||
public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST, LENGTH, SESSIONDATA, ERROR }
|
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 ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN }
|
||||||
public enum ValueType { TIME, POWER, ENERGY, DISTANCE }
|
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 double Timestamp { get; set; }
|
||||||
public int Session { get; set; }
|
public int Session { get; set; }
|
||||||
@@ -117,6 +117,7 @@ namespace ErgometerLibrary
|
|||||||
Type = CommandType.USER;
|
Type = CommandType.USER;
|
||||||
Session = session;
|
Session = session;
|
||||||
DisplayName = username;
|
DisplayName = username;
|
||||||
|
Password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
//LOGIN
|
//LOGIN
|
||||||
@@ -211,8 +212,6 @@ namespace ErgometerLibrary
|
|||||||
return new NetCommand(LengthType.SESSIONS, int.Parse(args[1]), session);
|
return new NetCommand(LengthType.SESSIONS, int.Parse(args[1]), session);
|
||||||
case "data":
|
case "data":
|
||||||
return new NetCommand(LengthType.DATA, int.Parse(args[1]), session);
|
return new NetCommand(LengthType.DATA, int.Parse(args[1]), session);
|
||||||
case "currentsessions":
|
|
||||||
return new NetCommand(LengthType.CURRENTSESSIONS, int.Parse(args[1]), session);
|
|
||||||
default:
|
default:
|
||||||
throw new FormatException("Error in NetCommand: Length type not recognised");
|
throw new FormatException("Error in NetCommand: Length type not recognised");
|
||||||
}
|
}
|
||||||
@@ -229,8 +228,6 @@ namespace ErgometerLibrary
|
|||||||
return new NetCommand(RequestType.USERS, session);
|
return new NetCommand(RequestType.USERS, session);
|
||||||
case "allsessions":
|
case "allsessions":
|
||||||
return new NetCommand(RequestType.ALLSESSIONS, session);
|
return new NetCommand(RequestType.ALLSESSIONS, session);
|
||||||
case "currentsessions":
|
|
||||||
return new NetCommand(RequestType.CURRENTSESSIONS, session);
|
|
||||||
case "olddata":
|
case "olddata":
|
||||||
return new NetCommand(RequestType.OLDDATA, session);
|
return new NetCommand(RequestType.OLDDATA, session);
|
||||||
case "sessiondata":
|
case "sessiondata":
|
||||||
@@ -383,6 +380,9 @@ namespace ErgometerLibrary
|
|||||||
case CommandType.SESSIONDATA:
|
case CommandType.SESSIONDATA:
|
||||||
command += "11»ses" + Session + "»" + DisplayName;
|
command += "11»ses" + Session + "»" + DisplayName;
|
||||||
break;
|
break;
|
||||||
|
case CommandType.ERROR:
|
||||||
|
command += "ERROR IN NETCOMMAND";
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new FormatException("Error in NetCommand: Cannot find type of command");
|
throw new FormatException("Error in NetCommand: Cannot find type of command");
|
||||||
|
|||||||
Reference in New Issue
Block a user