Application now searches for working comport

This commit is contained in:
2015-11-03 21:01:45 +01:00
parent 43dbc4ad13
commit f1c60b6f23
2 changed files with 18 additions and 3 deletions
@@ -74,7 +74,13 @@ namespace ErgometerApplication
if (SerialPort.GetPortNames().Length > 0)
{
string error = "";
bool connect = MainClient.Connect(SerialPort.GetPortNames()[0], username, password, out error);
bool connect = false;
foreach(string comport in SerialPort.GetPortNames())
{
connect = MainClient.Connect(comport, username, password, out error);
if (connect)
break;
}
if (connect)
{
+11 -2
View File
@@ -24,7 +24,8 @@ namespace ErgometerLibrary
comPort.Parity = Parity.None;
comPort.StopBits = StopBits.One;
comPort.BaudRate = 9600;
comPort.ReadTimeout = 1500;
comPort.ReadTimeout = 200;
comPort.WriteTimeout = 350;
try {
comPort.Open();
}
@@ -54,7 +55,15 @@ namespace ErgometerLibrary
{
if (IsOpen())
{
comPort.WriteLine(input);
try
{
comPort.WriteLine(input);
}
catch (TimeoutException)
{
}
}
}