示例#1
0
 private void DeviceTxStopWait(bool foundData)
 {
     if (foundData)
     {
         if (stopWaitEvent != null && stopWaitEvent.Callback != null)
         {
             stopWaitEvent.Callback(true, stopWaitEvent.CmdName);
         }
     }
     else
     {
         if (DeviceRxStopWaitCallback != null)
         {
             DeviceRxStopWaitCallback(false, (HCIStopWait.StopWaitEvent)null);
         }
         if (stopWaitEvent != null && stopWaitEvent.Callback != null)
         {
             stopWaitEvent.Callback(false, stopWaitEvent.CmdName);
         }
         else
         {
             ClearTxQueueQuestion();
         }
     }
     if (ShowProgressCallback != null)
     {
         ShowProgressCallback(false);
     }
     stopWaitEvent = null;
     stopWaitMsg   = false;
     stopWaitSuccessEvent.Set();
 }
示例#2
0
        private void TaskThread(object threadData)
        {
            try
            {
                bool flag = false;
                threadCtrl.Init();
                threadCtrl.RunningThread = true;
                SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Starting Thread");
                while (!flag)
                {
                    if (threadCtrl.ExitThread)
                        break;
                    if (threadCtrl.PauseThread)
                    {
                        threadCtrl.IdleThread = true;
                        SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Pausing Thread");
                        threadCtrl.EventPause.WaitOne();
                        threadCtrl.IdleThread = false;
                        if (threadCtrl.ExitThread)
                            break;
                    }
                    if (!stopWaitMsg)
                    {
                        switch (WaitHandle.WaitAny(
                            new WaitHandle[3]
                                {
                                    threadCtrl.EventExit,
                                    threadCtrl.EventPause,
                                    dataQ.qDataReadyEvent
                                }))
                        {
                            case 0:
                                flag = true;
                                break;
                            case 1:
                                threadCtrl.EventPause.Reset();
                                SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Resuming Thread");
                                break;
                            case 2:
                                dataQ.qDataReadyEvent.Reset();
                                QueueDataReady();
                                break;
                            default:
                                flag = true;
                                break;
                        }
                        continue;
                    }

                    switch (WaitHandle.WaitAny(
                        new WaitHandle[3]
                                {
                                    threadCtrl.EventExit,
                                    threadCtrl.EventPause,
                                    stopWaitSuccessEvent
                                }, new TimeSpan(0, 0, 0, 40)))
                    {
                        case 0:
                            flag = true;
                            break;
                        case 1:
                            threadCtrl.EventPause.Reset();
                            SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Resuming Thread");
                            break;
                        case 2:
                            stopWaitSuccessEvent.Reset();
                            stopWaitEvent = (HCIStopWait.StopWaitEvent)null;
                            stopWaitMsg = false;
                            break;
                        case 258:
                            if (DeviceRxStopWaitCallback != null)
                                DeviceRxStopWaitCallback(false, (HCIStopWait.StopWaitEvent)null);
                            if (stopWaitEvent != null)
                            {
                                string msg = "Message Response Timeout\nName = " + devUtils.GetOpCodeName((ushort)stopWaitEvent.TxOpcode) + "\nOpcode = 0x" + ((ushort)stopWaitEvent.TxOpcode).ToString("X4") + "\nTx Time = " + stopWaitEvent.TxTime + "\n";
                                if (DisplayMsgCallback != null)
                                    DisplayMsgCallback(SharedAppObjs.MsgType.Error, msg);
                                if (stopWaitEvent.Callback == null)
                                {
                                    msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                                    ClearTxQueueQuestion();
                                }
                                if (ShowProgressCallback != null)
                                    ShowProgressCallback(false);
                                if (stopWaitEvent.Callback != null)
                                    stopWaitEvent.Callback(false, stopWaitEvent.CmdName);
                            }
                            stopWaitEvent = (HCIStopWait.StopWaitEvent)null;
                            stopWaitMsg = false;
                            break;
                        default:
                            flag = true;
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Task Thread Problem.\n" + ex.Message + "\nTxDataOutThread\n");
            }
            SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Exiting Thread");
            threadCtrl.Exit();
        }
示例#3
0
        private void TaskThread(object threadData)
        {
            try
            {
                bool flag = false;
                threadCtrl.Init();
                threadCtrl.RunningThread = true;
                SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Starting Thread");
                while (!flag)
                {
                    if (threadCtrl.ExitThread)
                    {
                        break;
                    }
                    if (threadCtrl.PauseThread)
                    {
                        threadCtrl.IdleThread = true;
                        SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Pausing Thread");
                        threadCtrl.EventPause.WaitOne();
                        threadCtrl.IdleThread = false;
                        if (threadCtrl.ExitThread)
                        {
                            break;
                        }
                    }
                    if (!stopWaitMsg)
                    {
                        switch (WaitHandle.WaitAny(
                                    new WaitHandle[3]
                        {
                            threadCtrl.EventExit,
                            threadCtrl.EventPause,
                            dataQ.qDataReadyEvent
                        }))
                        {
                        case 0:
                            flag = true;
                            break;

                        case 1:
                            threadCtrl.EventPause.Reset();
                            SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Resuming Thread");
                            break;

                        case 2:
                            dataQ.qDataReadyEvent.Reset();
                            QueueDataReady();
                            break;

                        default:
                            flag = true;
                            break;
                        }
                        continue;
                    }

                    switch (WaitHandle.WaitAny(
                                new WaitHandle[3]
                    {
                        threadCtrl.EventExit,
                        threadCtrl.EventPause,
                        stopWaitSuccessEvent
                    }, new TimeSpan(0, 0, 0, 40)))
                    {
                    case 0:
                        flag = true;
                        break;

                    case 1:
                        threadCtrl.EventPause.Reset();
                        SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Resuming Thread");
                        break;

                    case 2:
                        stopWaitSuccessEvent.Reset();
                        stopWaitEvent = (HCIStopWait.StopWaitEvent)null;
                        stopWaitMsg   = false;
                        break;

                    case 258:
                        if (DeviceRxStopWaitCallback != null)
                        {
                            DeviceRxStopWaitCallback(false, (HCIStopWait.StopWaitEvent)null);
                        }
                        if (stopWaitEvent != null)
                        {
                            string msg = "Message Response Timeout\nName = " + devUtils.GetOpCodeName((ushort)stopWaitEvent.TxOpcode) + "\nOpcode = 0x" + ((ushort)stopWaitEvent.TxOpcode).ToString("X4") + "\nTx Time = " + stopWaitEvent.TxTime + "\n";
                            if (DisplayMsgCallback != null)
                            {
                                DisplayMsgCallback(SharedAppObjs.MsgType.Error, msg);
                            }
                            if (stopWaitEvent.Callback == null)
                            {
                                msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                                ClearTxQueueQuestion();
                            }
                            if (ShowProgressCallback != null)
                            {
                                ShowProgressCallback(false);
                            }
                            if (stopWaitEvent.Callback != null)
                            {
                                stopWaitEvent.Callback(false, stopWaitEvent.CmdName);
                            }
                        }
                        stopWaitEvent = (HCIStopWait.StopWaitEvent)null;
                        stopWaitMsg   = false;
                        break;

                    default:
                        flag = true;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Task Thread Problem.\n" + ex.Message + "\nTxDataOutThread\n");
            }
            SharedObjects.Log.Write(Logging.MsgType.Debug, "TxDataOutThread", "Exiting Thread");
            threadCtrl.Exit();
        }