Example #1
0
        public void WritePort(byte[] send, int offSet, int count)
        {
            if (!IsOpen)
            {
                return;
            }
            var       num  = 100;
            Exception ex1  = new TimeoutException();
            var       flag = false;

            while (num-- > 0 && ex1 != null)
            {
                if (ex1.GetType() == typeof(TimeoutException))
                {
                    try
                    {
                        serialPort.WriteTimeout = 1000;
                        serialPort.Write(send, offSet, count);
                        flag = true;
                        if (isDump)
                        {
                            Dump(send);
                        }
                        ex1 = null;
                    }
                    catch (TimeoutException ex2)
                    {
                        ex1 = ex2;
                        Log.w(serialPort.PortName, "write time out try agian " + (100 - num));
                        Thread.Sleep(500);
                    }
                }
            }
Example #2
0
        /// <summary>
        /// write to comm port
        /// </summary>
        public void WritePort(byte[] send, int offSet, int count)
        {
            if (!IsOpen)
            {
                return;
            }
            int       num  = 100;
            Exception ex1  = new TimeoutException();
            bool      flag = false;

            while (num-- > 0 && ex1 != null)
            {
                if (ex1.GetType() == typeof(TimeoutException))
                {
                    try
                    {
                        serialPort.WriteTimeout = 1000;
                        serialPort.Write(send, offSet, count);
                        flag = true;
                        if (isDump)
                        {
                            Dump(send);
                        }
                        ex1 = null;
                    }
                    catch (TimeoutException ex2)
                    {
                        ex1 = ex2;
                        Logger.w(serialPort.PortName, "write time out try agian " + (100 - num), null);
                        Thread.Sleep(500);
                    }
                    catch (Exception ex2)
                    {
                        Logger.w(ex2.Message, "write failed:" + serialPort.PortName, ex2.StackTrace);
                    }
                }
                else
                {
                    break;
                }
            }
            if (flag)
            {
                return;
            }
            Logger.w(ex1.Message, serialPort.PortName, ex1.StackTrace);
        }
Example #3
0
 // Token: 0x0600006A RID: 106 RVA: 0x00008974 File Offset: 0x00006B74
 public void WritePort(byte[] send, int offSet, int count)
 {
     if (this.IsOpen)
     {
         bool      keepReading = this._keepReading;
         int       num         = 0;
         Exception ex          = new TimeoutException();
         bool      flag        = false;
         while (num++ <= 6 && ex != null && ex.GetType() == typeof(TimeoutException))
         {
             try
             {
                 this.serialPort.WriteTimeout = 2000;
                 this.serialPort.Write(send, offSet, count);
                 flag = true;
                 if (this.isWriteDump)
                 {
                     Log.w(this.serialPort.PortName, "write to port:");
                     this.Dump(send);
                 }
                 ex = null;
             }
             catch (TimeoutException ex2)
             {
                 ex = ex2;
                 Log.w(this.serialPort.PortName, "write time out try agian " + num);
                 Thread.Sleep(500);
             }
             catch (Exception ex3)
             {
                 Log.w(this.serialPort.PortName, "write failed:" + ex3.Message);
             }
         }
         if (!flag)
         {
             Log.w(this.serialPort.PortName, ex, true);
             throw new Exception("write time out,maybe device was disconnected.");
         }
     }
     this.writeCount++;
 }
Example #4
0
            private static void CompleteCleanup(object state, TimeoutException exception)
            {
                CloseAsyncResult thisPtr             = (CloseAsyncResult)state;
                Exception        completionException = null;

                if (exception != null)
                {
                    Fx.Assert(exception.GetType() == typeof(TimeoutException), "Exception on callback should always be TimeoutException");
                    throw FxTrace.Exception.AsError(new TimeoutException(SR.TimeoutOnOperation(thisPtr.timeoutHelper.OriginalTimeout)));
                }

                try
                {
                    lock (thisPtr.channel.ThisLock)
                    {
                        thisPtr.channel.retransmissionDoneWaitHandle = null;

                        // another thread could have called Abort while Close() was waiting for retransmission to complete.
                        if (!thisPtr.channel.cleanedUp)
                        {
                            // never aborting here
                            thisPtr.channel.CleanupAfterWait(false);
                        }
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    completionException = e;
                }

                thisPtr.Complete(false, completionException);
            }
Example #5
0
 public void captures_exception_data()
 {
     theErrorReport.ExceptionText.ShouldBe(theException.ToString());
     theErrorReport.ExceptionMessage.ShouldBe(theException.Message);
     theErrorReport.ExceptionType.ShouldBe(theException.GetType().FullName);
 }
Example #6
0
 private static bool handleTimeoutException(TimeoutException ex, MethodBase Method)
 {
     Logging.Logger("ERROR:  MethodName=" + Method.Name + "  Type: " + ex.GetType().Name + "  #:" + ex.HResult + "  Message:" + ex.Message);
     return(false);
 }