Beispiel #1
0
        private void mergeFunc()
        {
            int dequeueResult;
            //bool isError;
            bool stop;
            bool isParseSuccess;
            int  endCount;
            MergeInQueueElement outqueueElement;
            QueueData           endQueue;

            //isError = false;
            stop            = false;
            isParseSuccess  = false;
            endCount        = 0;
            outqueueElement = new MergeInQueueElement();
            endQueue        = new QueueData();
            endQueue.isEnd  = true;  //A queue atom represent the end of the input.

            init.handclasp_meet();

            while ((!GlobalQuit.Quit) && (!stop))
            {
                try
                {
                    for (int i = 0; i < mergeInList.Count; i++)
                    {
                        dequeueResult = mergeInList[i].DequeueWithSemaphor(ref outqueueElement, ConstParameter.TimeOutMilliSecondValue);

                        if (dequeueResult == -1)
                        {
                            StackTrace st = new StackTrace(new StackFrame(true));
                            LogHelper.WriteLog("MergeThread timed out when semaphor wait for receiving!", st);
#if USE_WARNING
                            MessageBox.Show("融合线程信号量超时,请马上设置断点检查。位置:MergeThread.mergeFunc");
#endif
                            status = ThreadCondition.error;
                            //isError = true;
                        }
                        else if (dequeueResult == 0)
                        {
                            continue;
                        }
                        else if (dequeueResult == 1)
                        {
                            //if receive the end atom of queue, just break and stop the thread.
                            if (outqueueElement.IsEnd == true)
                            {
                                endCount++;
                                if (endCount == mergeInList.Count)
                                {
                                    endCount = 0;
                                    stop     = true;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            isParseSuccess = parsePacket(outqueueElement.setPacket, i);
                            if (!isParseSuccess)
                            {
                                StackTrace st = new StackTrace(new StackFrame(true));
                                LogHelper.WriteLog("The format of packet is wrong or MergeThread timed out when Enqueue!", st);
#if USE_WARNING
                                MessageBox.Show("融合线程获取的数据格式错误或入队失败,请马上设置断点检查。位置:MergeThread.mergeFunc");
#endif
                                status = ThreadCondition.error;
                                //isError = true;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    StackTrace st = new StackTrace(new StackFrame(true));
                    LogHelper.WriteLog(e, st);
#if USE_WARNING
                    MessageBox.Show("检测到异常,请马上设置断点检查。位置:MergeThread.mergeFunc");
#endif
                    status = ThreadCondition.error;
                    //isError = true;
                }
            }
            init.handclasp_force();

            measureQueueElement.IsEnd = true;
            measureQueue.Enqueue(measureQueueElement);

            clean.handclasp_meet();

            status = ThreadCondition.exit;
        }
Beispiel #2
0
        /**Capture thread funcion.*/
        private void captureFunc()
        {
            CaptureOutQueueElement outQueueElement;
            //A queue atom represent the end of the input.
            CaptureOutQueueElement queueFlush;
            int  readResult;
            bool isEnqueue;

            outQueueElement  = new CaptureOutQueueElement();
            queueFlush       = new CaptureOutQueueElement();
            queueFlush.IsEnd = true;
            readResult       = 0;
            //isError = false;
            isEnqueue = false;

            init.handclasp_meet();

            while (!GlobalQuit.Quit)
            {
                try
                {
                    readResult = GetPDAQ.daqRead(boardId, ref outQueueElement.setPacket);
                    //outQueueElement.setPacket.id = 512;
                    if (0 == readResult)
                    {
                        //LogFile.write("收到采集信号");
                        //the receiver count++
                        pkgCounter++;

                        //enqueue
                        isEnqueue = outputQueue.Enqueue(outQueueElement);
                        //LogFile.write("采集入队成功");
                        if (!isEnqueue)
                        {
                            StackTrace st = new StackTrace(new StackFrame(true));
                            LogHelper.WriteLog(boardId + "# CaptureThread timed out when Enqueue!", st);
#if USE_WARNING
                            MessageBox.Show("采集线程入队超时,请马上设置断点检查。位置:CaptureThread.captureFunc");
#endif
                            status = ThreadCondition.error;
                            //isError = true;
                        }
                    }
                    //A symbol for the last one
                    else if (1 == readResult)
                    {
                        outputQueue.Enqueue(queueFlush);
                        break;
                    }
                    else
                    {
                        StackTrace st = new StackTrace(new StackFrame(true));
                        LogHelper.WriteLog("Can't read from DAQ. ErrorCoed = " + readResult, st);
#if USE_WARNING
                        MessageBox.Show("采集线程读取DAQ数据错误,请马上设置断点检查。位置:CaptureThread.captureFunc, " + boardId.ToString() + "#采集线程错误!");
#endif
                        status = ThreadCondition.error;
                        //isError = true;
                    }
                }
                catch (Exception e)
                {
                    StackTrace st = new StackTrace(new StackFrame(true));
                    LogHelper.WriteLog(e, st);
#if USE_WARNING
                    MessageBox.Show("检测到异常,请马上设置断点检查。位置:CaptureThread.captureFunc, " + boardId.ToString() + "#采集线程异常!");
#endif
                    status = ThreadCondition.error;
                    //isError = true;
                }
            }
            init.handclasp_force();

            //outputQueue.Enqueue(queueFlush);
            clean.handclasp_meet();

            status = ThreadCondition.exit;
        }