[chronojump] Automatic firmware close before checkings



commit 87ac78d782ca2526552bc525576ec3a27d4aecf3
Author: Xavier Padullés <x padulles gmail com>
Date:   Mon Sep 15 14:29:13 2014 +0200

    Automatic firmware close before checkings

 src/chronopic.cs |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/chronopic.cs b/src/chronopic.cs
index 6fe75af..bf8dd29 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -423,20 +423,28 @@ public abstract class ChronopicAuto
        protected internal abstract string Communicate();
        private string str;
 
-       private void make(SerialPort sp) 
+       private bool make(SerialPort sp) 
        {
                this.sp = sp;
 
                if (sp == null) 
-                       sp.Open();
+                       return false;
+               
+               if (sp != null) 
+                       if (sp.IsOpen)
+                               sp.Close(); //close to ensure no bytes are comming
+
+               sp.Open();
 
                str = "";
+               return true;
        }
 
        //'template method'
        public string Read(SerialPort sp) 
        {
-               make(sp);
+               if ( ! make(sp) )
+                       return "Error sp == null";
                
                try {
                        str = Communicate();
@@ -452,7 +460,9 @@ public abstract class ChronopicAuto
        //'template method'
        public string Write(SerialPort sp, int num) 
        {
-               make(sp);
+               if ( ! make(sp) )
+                       return "Error sp == null";
+               
                sendNum = num;
                
                try {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]