Esempio n. 1
0
        /**Get the datas ande enqueue.*/
        private bool parsePacket(UniSetPacket setPacket)
        {
            //DEFINATION
            uint tmpId;
            bool isEnqueSuccess;

            //INIT
            tmpId          = setPacket.id;
            isEnqueSuccess = false;

            //PROCESSING
            //Check start
            if (setPacket.start[0] != ConstParameter.StartLowFlag || setPacket.start[1] != ConstParameter.StartHighFlag)
            {
                StackTrace st = new StackTrace(new StackFrame(true));
                LogHelper.WriteLog("Check code of start unmatched!", st);
                return(false);
            }
            //Check stop
            if (setPacket.stop[0] != ConstParameter.StopLowFlag || setPacket.stop[1] != ConstParameter.StopHighFlag)
            {
                StackTrace st = new StackTrace(new StackFrame(true));
                LogHelper.WriteLog("Check code of stop unmatched!", st);
                return(false);
            }
            //Check the id
            if (!Enum.IsDefined(typeof(PacketId), (int)setPacket.id))
            {
                StackTrace st = new StackTrace(new StackFrame(true));
                LogHelper.WriteLog("Packet ID is not defined!", st);
                return(false);
            }


            if (tmpId == (uint)PacketId.none)
            {
                StackTrace st = new StackTrace(new StackFrame(true));
                LogHelper.WriteLog("Packet ID is 0!", st);
                return(false);
            }
            else if (tmpId <= (uint)PacketId.alarmDisp || tmpId == (uint)PacketId.couple || tmpId == (uint)PacketId.eventId)
            {
                if (tmpId == (uint)PacketId.eventId)
                {
                    tmpId = (uint)PacketId.eventId;
                }
                //Gate, Gate2, Alarm, just forward
                mergeInQueueElement.setPacket = setPacket;
                isEnqueSuccess = mergeInQueue.EnqueueWithSemaphor(mergeInQueueElement);
                if (!isEnqueSuccess)
                {
                    return(false);
                }
            }
            else if (tmpId == (uint)PacketId.ascanVedio)
            {
                //AsacnVedio
                copyToAscanPacket(ascanQueueElement.ascanPacket, setPacket);
                SessionInfo sessionAttr = SessionHardWare.getSessionAttr((int)SelectAscan.userIndex);

                if (!MainForm.IsToStop)
                {
                    if ((int)ascanQueueElement.getPort() == sessionAttr.myHardInfo.upPort)
                    {
                        FormList.MDIChild.enqueue(ascanQueueElement);
                        //FormList.MDIChild.BeginInvoke(updateCallBack);

                        /*count++;
                         * if (count >= 5)
                         * {
                         *  FormList.MDIChild.BeginInvoke(updateCallBack);
                         *  count = 0;
                         * }*/

                        //FormList.MDIChild.updateAscan(ascanQueueElement);
                        //ascanUpdate.Execute(ascanQueueElement);
                    }

                    //Sector Scan
                    if (FormList.Formsscan.isStart)
                    {
                        if (((int)ascanQueueElement.getPort() <= 512 + FormList.Formsscan.passNum - 1) && ((int)ascanQueueElement.getPort() >= 512))
                        {
                            FormList.Formsscan.enqueue(ascanQueueElement, (int)ascanQueueElement.getPort() - 512);
                        }
                    }
                }
                return(true);
                //isEnqueSuccess = ascanQueue.EnqueueWithSemaphor(ascanQueueElement);
                //if (!isEnqueSuccess)
                //return false;
            }
            else if (tmpId == (uint)PacketId.status)
            {
                //Status
                copyToStatusPacket(boardStatusPacket, setPacket);

                uint status = boardStatusPacket.status.status;

                switch (status)
                {
                case 0x0:
                case 0x1:
                case 0x3:
                    isBoardStatusOK = false;
                    break;

                case 0x2:
                    isBoardStatusOK = true;
                    break;

                default:
                    isBoardStatusOK = false;
                    break;
                }
                return(true);
            }

            return(isEnqueSuccess);
        }
Esempio n. 2
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;
        }