Пример #1
0
 public void Start()
 {
     if (!serialPort.IsOpen)
     {
         serialPort.Open();
     }
     if (caller.HasTask())
     {
         throw new Exception("延时任务未执行完成");
     }
     Debug.WriteLine("DsrHolding = " + serialPort.DsrHolding.ToString());
     Debug.WriteLine("ctsHolding = " + serialPort.CtsHolding.ToString());
     Debug.WriteLine("Handshake = " + serialPort.Handshake.ToString());
     Debug.WriteLine("CDHolding = " + serialPort.CDHolding.ToString());
     Debug.WriteLine("BreakState = " + serialPort.BreakState.ToString());
     if (serialPort.DsrHolding)
     {
         serialPort.DtrEnable = true;
     }
     serialPort.Write(command1, 0, command1.Count());
     if (Sent != null)
     {
         Sent(this, new string(command1));
     }
     task = caller.NewCall(500, SendModel);
 }
Пример #2
0
 private void Proc()
 {
     while (true)
     {
         try
         {
             if (taskQueue.Count() == 0)
             {
                 Thread.Sleep(0);
                 continue;
             }
             DelayTask task = taskQueue.Peek();
             Thread.Sleep(task.DelayTime);
             task = taskQueue.Dequeue();
             if (!task.IsRun)
             {
                 continue;
             }
             task.Action();
             task.IsRun = false;
         }
         catch (ThreadAbortException)
         {
             return;
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex.Message);
         }
     }
 }
Пример #3
0
 public void CancelAll()
 {
     while (taskQueue.Count > 0)
     {
         DelayTask task = taskQueue.Dequeue();
         task.IsRun = false;
     }
 }
Пример #4
0
 private void SendModel()
 {
     serialPort.Write(command2, 0, command2.Count());
     if (Sent != null)
     {
         Sent(this, new string(command2));
     }
     task = caller.NewCall(500, Error);
 }
Пример #5
0
 private void SendNoDtsIdx()
 {
     serialPort.Write(command1, 0, command1.Count());
     if (Sent != null)
     {
         Sent(this, new string(command1));
     }
     task = caller.NewCall(500, SendModel);
 }
Пример #6
0
        public DelayTask NewCall(int timeout, Action action)
        {
            if (threadTask == null || !threadTask.IsAlive)
            {
                threadTask = new Thread(new ThreadStart(Proc));
                threadTask.Start();
            }
            DelayTask task = new DelayTask();

            task.DelayTime = timeout;
            task.Action    = action;
            taskQueue.Enqueue(task);
            return(task);
        }