Sfoglia il codice sorgente

Application now searches for working comport

Kenneth van Ewijk 10 anni fa
parent
commit
f1c60b6f23

+ 7 - 1
ErgometerIPR/ErgometerApplication/ClientApplicatie.cs

@@ -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
ErgometerIPR/ErgometerLibrary/ComPort.cs

@@ -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)
+                {
+                  
+                }
             }
         }