Пример #1
0
        /**Copy the datas to the queue of boardStatus.*/
        private void copyToStatusPacket(BoardStatusSetPacket statusPacket, UniSetPacket setPacket)
        {
            //DEFINATION
            ItemHeader      head;
            UploadTagHeader tag;
            BoardStatus     status;
            int             uintOffset;

            //INIT
            head       = statusPacket.head;
            tag        = statusPacket.tag;
            status     = statusPacket.status;
            uintOffset = 0;

            //PROCESSING
            //head
            head.port = setPacket.port;
            head.id   = setPacket.id;
            head.bin  = setPacket.bin;
            head.size = setPacket.size;

            //tag
            tag.stampMode = setPacket.stampMode;
            Array.Copy(setPacket.stampPos, tag.stampPos, 3);
            Array.Copy(setPacket.stampInc, tag.stampInc, 3);
            tag.cellNum = setPacket.cellNum;

            //status
            status.status    = setPacket.ud[uintOffset++];
            status.errCode   = (int)setPacket.ud[uintOffset++];
            status.beatHeart = setPacket.ud[uintOffset++];
        }
Пример #2
0
 /**Start thread.*/
 public void start()
 {
     if (status != ThreadCondition.run)
     {
         thread.Start();
         status = ThreadCondition.run;
     }
 }
Пример #3
0
 /**Start timer.*/
 public void start()
 {
     if (status != ThreadCondition.run)
     {
         //timer.Enabled = true;
         thread.Start();
         status = ThreadCondition.run;
     }
 }
Пример #4
0
        public CaptureThread(CaptureThreadEnv tmpEnv)
        {
            boardId     = (uint)tmpEnv.boardId;
            init        = tmpEnv.init;
            clean       = tmpEnv.clean;
            status      = tmpEnv.status;
            outputQueue = tmpEnv.captureOutQueue;
            pkgCounter  = 0;

            thread = new Thread(captureFunc);
            thread.IsBackground = true;
        }
Пример #5
0
        public MergeThread(MergeThreadEnv tmpEnv)
        {
            init         = tmpEnv.init;
            clean        = tmpEnv.clean;
            status       = tmpEnv.status;
            mergeInList  = tmpEnv.mergeInList;
            measureQueue = tmpEnv.measureQueue;

            measureQueueElement = new MeasureQueueElement();

            thread = new Thread(mergeFunc);
            thread.IsBackground = true;
        }
Пример #6
0
        public UIThread(UIThreadEnv tmpEnv)
        {
            init        = tmpEnv.init;
            clean       = tmpEnv.clean;
            status      = tmpEnv.status;
            ascanInList = tmpEnv.ascanInList;

            this.sessionsAttrs = tmpEnv.sessionsAttrs;
            ascanQueueElement  = new AscanQueueElement();

            thread = new Thread(UIFunc);
            thread.IsBackground = true;
        }
Пример #7
0
        public AscanUIThread(AscanUIThreadEnv tmpEnv)
        {
            init        = tmpEnv.init;
            clean       = tmpEnv.clean;
            status      = tmpEnv.status;
            ascanInList = tmpEnv.ascanInList;

            ascanQueueElement = new AscanQueueElement();
            //timer = new System.Windows.Forms.Timer();
            //timer.Interval = ConstParameter.AscanTimerInterval;
            //timer.Tick += new EventHandler(AscanUIFunc);
            thread = new Thread(AscanUIFunc);
            thread.IsBackground = true;
        }
Пример #8
0
        public MeasureUIThread(MeasureUIThreadEnv tmpEnv)
        {
            init         = tmpEnv.init;
            clean        = tmpEnv.clean;
            status       = tmpEnv.status;
            measureQueue = tmpEnv.measureQueue;

            measureQueueElement = new MeasureQueueElement();

            thread = new Thread(MeasureUIFunc);
            thread.IsBackground = true;

            //timer.Elapsed += new System.Timers.ElapsedEventHandler(UpdateAUT);
            timer.AutoReset = true;
        }
Пример #9
0
        public ParseThread(ParseThreadEnv tmpEnv)
        {
            timer.Elapsed  += new System.Timers.ElapsedEventHandler(UpdateAscan);
            timer.AutoReset = true;

            init         = tmpEnv.init;
            clean        = tmpEnv.clean;
            status       = tmpEnv.status;
            inputQueue   = tmpEnv.captureOutQueue;
            ascanQueue   = tmpEnv.ascanQueue;
            mergeInQueue = tmpEnv.mergeInQueue;

            mergeInQueueElement = new MergeInQueueElement();
            ascanQueueElement   = new AscanQueueElement();
            boardStatusPacket   = new BoardStatusSetPacket();

            thread = new Thread(parseFunc);
            thread.IsBackground = true;

            updateCallBack = new updateDelegate(FormList.MDIChild.updateAscanbytimer);
        }
Пример #10
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;
        }
Пример #11
0
        /**Measure UI thread function.*/
        private void MeasureUIFunc()
        {
            //DEFINATION
            //bool isError;

            bool isDequeSuccess;

            //INIT
            //isError = false;
            isDequeSuccess = false;

            //PROCESSING
            init.handclasp_meet();

            while (!GlobalQuit.Quit)
            {
                try
                {
                    //if (measureUpdateList.Count != mapRowDataList.Count)
                    //bindMeasureDrawEvent();

                    isDequeSuccess = measureQueue.Dequeue(ref measureQueueElement);

                    if (isDequeSuccess)
                    {
                        //if receive the end atom of queue, just break and stop the thread.
                        if (measureQueueElement.IsEnd == true)
                        {
                            break;
                        }

                        if (FormList.FormMeasurement == null)
                        {
                            continue;
                        }

                        if (!MainForm.IsToStop)
                        {
                            FormList.FormMeasurement.addPoints(measureQueueElement);
                            //FormList.FormCalibrate.addPoints(measureQueueElement);
                        }
                    }
                    else
                    {
                        StackTrace st = new StackTrace(new StackFrame(true));
                        LogHelper.WriteLog("MeasureUI thread timed out when Dequeue!", st);
#if USE_WARNING
                        MessageBox.Show("融合显示线程出队超时,请马上设置断点检查。位置:MeasureUIThread.MeasureUIFunc");
#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("检测到异常,请马上设置断点检查。位置:AscanUIThread.AscanUIFunc");
#endif
                    status = ThreadCondition.error;
                    //isError = true;
                }
            }
            init.handclasp_force();

            clean.handclasp_meet();

            status = ThreadCondition.exit;
        }
Пример #12
0
        /**Parse thread function.*/
        private void parseFunc()
        {
            //DEFINATION
            bool isDequeSuccess;
            bool isParseSuccess;
            //bool isError;
            CaptureOutQueueElement outqueueElement;
            //A queue atom represent the end of the ascan queue.
            AscanQueueElement ascanEndElement;
            //A queue atom represent the end of the mergein queue.
            MergeInQueueElement mergeInEndElement;

            //INIT
            isDequeSuccess = false;
            isParseSuccess = false;
            //isError = false;
            outqueueElement         = new CaptureOutQueueElement();
            ascanEndElement         = new AscanQueueElement();
            ascanEndElement.IsEnd   = true;
            mergeInEndElement       = new MergeInQueueElement();
            mergeInEndElement.IsEnd = true;

            //PROCESSING
            init.handclasp_meet();

            while (!GlobalQuit.Quit)
            {
                try
                {
                    isDequeSuccess = inputQueue.Dequeue(ref outqueueElement);

                    if (isDequeSuccess)
                    {
                        //if receive the end atom of queue, just break and stop the thread.
                        if (outqueueElement.IsEnd == true)
                        {
                            break;
                        }
                        // LogFile.write("开始分发");
                        isParseSuccess = parsePacket(outqueueElement.setPacket);
                        //  LogFile.write("分发结束");
                        if (!isParseSuccess)
                        {
                            StackTrace st = new StackTrace(new StackFrame(true));
                            LogHelper.WriteLog("The format of packet is wrong or ParseThread timed out when Enqueue!", st);
#if USE_WARNING
                            MessageBox.Show("分发线程获取的数据格式错误或入队失败,请马上设置断点检查。位置:ParseThread.parseFunc");
#endif
                            status = ThreadCondition.error;
                            //isError = true;
                        }
                    }
                    else
                    {
                        StackTrace st = new StackTrace(new StackFrame(true));
                        LogHelper.WriteLog("ParseThread timed out when Dequeue!", st);
#if USE_WARNING
                        MessageBox.Show("分发线程出队超时,请马上设置断点检查。位置:ParseThread.parseFunc");
#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("检测到异常,请马上设置断点检查。位置:ParseThread.parseFunc");
#endif
                    status = ThreadCondition.error;
                    //isError = true;
                }
            }

            init.handclasp_force();

            //ascanQueue.EnqueueWithSemaphor(ascanEndElement);
            //mergeInQueue.EnqueueWithSemaphor(mergeInEndElement);

            clean.handclasp_meet();

            status = ThreadCondition.exit;
        }
Пример #13
0
        /**UI thread function.*/
        private void UIFunc()
        {
            //DEFINATION
            bool isError;

            int dequeueResult;

            //INIT
            isError = false;

            //PROCESSING
            init.handclasp_meet();

            bindAscanDrawEvent();

            while (!GlobalQuit.Quit)
            {
                try
                {
                    for (int i = 0; i < sessionsAttrs.Count; i++)
                    {
                        dequeueResult = ascanInList[i].DequeueWithSemaphor(ref ascanQueueElement);

                        if (dequeueResult == -1)
                        {
                            StackTrace st = new StackTrace(new StackFrame(true));
                            LogHelper.WriteLog("UI Thread timed out when semaphor wait for receiving!", st);
#if USE_WARNING
                            MessageBox.Show("UI主线程信号量超时,请马上设置断点检查。位置:UIThread.UIFunc");
#endif
                            status  = ThreadCondition.error;
                            isError = true;
                        }
                        else if (dequeueResult == 0)
                        {
                            continue;
                        }
                        else if (dequeueResult == 1)
                        {
                            if (sessionsAttrs[i].myHardInfo.enable)
                            {
                                ascanUpdateList[i].Execute(ascanQueueElement);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    StackTrace st = new StackTrace(new StackFrame(true));
                    LogHelper.WriteLog(e, st);
#if USE_WARNING
                    MessageBox.Show("检测到异常,请马上设置断点检查。位置:UIThread.UIFunc");
#endif
                    status  = ThreadCondition.error;
                    isError = true;
                }
            }

            init.handclasp_force();

            clean.handclasp_meet();

            if (!isError)
            {
                status = ThreadCondition.exit;
            }
        }
Пример #14
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;
        }
Пример #15
0
        /**Stop timer.*/

        /*public void stop()
         * {
         *  if (timer.Enabled)
         *      timer.Enabled = false;
         * }*/

        /**Ascan UI timer function.*/
        private void AscanUIFunc()
        {
            //DEFINATION
            bool isError;

            int  dequeueResult;
            int  endCount;
            bool isQuit = false;

            //INIT
            isError  = false;
            endCount = 0;

            //PROCESSING
            init.handclasp_meet();

            DelegateAscanUpdate ascanUpdate = new DelegateAscanUpdate();

            while (!GlobalQuit.Quit && !isQuit)
            {
                try
                {
                    for (int i = 0; i < SessionInfo.sessionNum; i++)
                    {
                        dequeueResult = ascanInList[i].DequeueWithSemaphor(ref ascanQueueElement, ConstParameter.TimeOutMilliSecondValue);

                        if (dequeueResult == -1)
                        {
                            StackTrace st = new StackTrace(new StackFrame(true));
                            LogHelper.WriteLog("Ascan UI Thread timed out when semaphor wait for receiving!", st);
#if USE_WARNING
                            MessageBox.Show("A扫UI线程信号量超时,请马上设置断点检查。位置:AscanUIThread.AscanUIFunc");
#endif
                            status = ThreadCondition.error;
                            //isError = true;
                        }
                        else if (dequeueResult == 0)
                        {
                            continue;
                        }
                        else if (dequeueResult == 1)
                        {
                            if (ascanQueueElement.IsEnd)
                            {
                                endCount++;
                                if (endCount == ascanInList.Count)
                                {
                                    endCount = 0;
                                    isQuit   = true;
                                    //timer.Enabled = false;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (!MainForm.IsToStop)
                            {
                                if (i == SelectAscan.userIndex && (int)ascanQueueElement.getPort() == SelectAscan.port)
                                {
                                    MainForm.syncContext.Post(FormList.MDIChild.updateAscan, (Object)ascanQueueElement);
                                    //FormList.MDIChild.updateAscan(ascanQueueElement);
                                    //ascanUpdate.Execute(ascanQueueElement);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    StackTrace st = new StackTrace(new StackFrame(true));
                    LogHelper.WriteLog(ex, st);
#if USE_WARNING
                    MessageBox.Show("检测到异常,请马上设置断点检查。位置:AscanUIThread.AscanUIFunc");
#endif
                    status = ThreadCondition.error;
                    //isError = true;
                }
            }
            init.handclasp_force();

            clean.handclasp_meet();

            status = ThreadCondition.exit;
        }