public TopInfoUnit(FrmMain mainframe)
 {
     _pMainFrame = mainframe;
     InitializeComponent();
     statusManger              = StatusManger.Instance;
     statusManger.StatusEvent += StatusManger_StatusEvent;
 }
Exemplo n.º 2
0
        private void StartExtTrigger()
        {
            StatusManger status1 = StatusManger.Instance;

            foreach (var item in CameraManger.CameraDic.Values)
            {
                item.SetExtTrigger();
            }
            CameraBase camera = CameraManger.CameraDic.Values.ToList().Find(x => x.IsExtTrigger == false);

            if (camera == null && CameraManger.CameraDic.Count > 0)
            {
                //btnRun.Text = "运行中";
                //btnRun.BackColor = Color.Green;
                //status1.RuningStatus = RuningStatus.系统运行中;
                SetNotifyMessage(string.Format("等待外部触发"));
            }
            else
            {
                if (camera == null)
                {
                    SetNotifyMessage(string.Format("相机未连接,无法开始运行"));
                }
                else
                {
                    SetNotifyMessage(string.Format("相机{0}开始外触发运行异常", camera.CameraIndex));
                }

                btnRun.Text      = "运行";
                btnRun.BackColor = Control.DefaultBackColor;
            }
        }
Exemplo n.º 3
0
        private void AutoUnit_Load(object sender, EventArgs e)
        {
            StatusManger statusManger = StatusManger.Instance;

            statusManger.RuningStatus            = RuningStatus.初始化;
            toolShowUnit1.ToolGroupsChangeEvent += ToolGroupsChange_Event;
            timerInit.Enabled = true;
        }
Exemplo n.º 4
0
 // Start is called before the first frame update
 void Start()
 {
     theTimingManager = FindObjectOfType <TimingManager>();
     theCam           = FindObjectOfType <CameraController>();
     theStatus        = FindObjectOfType <StatusManger>();
     myRigid          = GetComponentInChildren <Rigidbody>();
     originPos        = transform.position;
 }
Exemplo n.º 5
0
    [SerializeField] CenterFlame theMusic = null; //처음에 비활성화되어있기때문에 find로 찾을 수 없다.

    // Start is called before the first frame update
    void Start()
    {
        instance  = this;
        theNote   = FindObjectOfType <NoteManager>();
        theCombo  = FindObjectOfType <ComboManager>();
        theScore  = FindObjectOfType <ScoreManager>();
        theTiming = FindObjectOfType <TimingManager>();
        theStatus = FindObjectOfType <StatusManger>();
        thePlayer = FindObjectOfType <PlayerController>();
        theStage  = FindObjectOfType <StageManger>();
        theResult = FindObjectOfType <Result>();
    }
Exemplo n.º 6
0
    // Start is called before the first frame update
    void Start()
    {
        theEffect        = FindObjectOfType <EffectManager>();
        theScoreManager  = FindObjectOfType <ScoreManager>();
        theComboManager  = FindObjectOfType <ComboManager>();
        theStageManager  = FindObjectOfType <StageManger>();
        thePlayer        = FindObjectOfType <PlayerController>();
        theStatusManager = FindObjectOfType <StatusManger>();


        //타이밍 박스 설정
        timingBoxs = new Vector2[timingRect.Length];

        for (int i = 0; i < timingRect.Length; i++)
        {
            //각각의 판정 범위 = 중심 - 이미지 너비/2 ~ 중심 + 이미지 너비/2
            timingBoxs[i].Set(center.localPosition.x - timingRect[i].rect.width / 2,
                              center.localPosition.x + timingRect[i].rect.width / 2);
        }
    }
        public void RunAllTool()
        {
            HTuple /*start = null, */ end = null;

            //帧率统计增加
            fps.IncreaseFrameNum();
            fpsCount++;
            if (fpsCount > 10)
            {
                fps.UpdateFps();
                fpsCount = 0;
            }
            RunStatus runStatus = new RunStatus(settingIndex, cameraIndex);

            runStatus.FpsStr = string.Format("FPS:{0:F1}|帧:{1}|", fps.GetFps(), fps.GetTotalFrameCount());

            List <ToolBase> runToolList = ToolsFactory.GetToolList(settingIndex);

            Tools.CreateImage.CreateImageTool createImageTool = runToolList[0] as Tools.CreateImage.CreateImageTool;
            HWndCtrl hWndCtrl = cameraShowUnit.HWndUnit.HWndCtrl;

            try
            {
                HTuple       toolStart = new HTuple(), toolEnd = new HTuple();
                StatusManger statusManger = StatusManger.Instance;
                statusManger.RuningStatus = RuningStatus.图像检测中;
                runningResultFlag         = false;
                toolErr = null;

                //开始运行所有工具
                HOperatorSet.CountSeconds(out toolStart);
                //外部触发处理
                if (isExtTrigger || isGrabber)
                {
                    createImageTool.SettExtTriggerData(ImageData);
                    isGrabber = false;
                }
                else
                {
                    createImageTool.SetExtTriggerDataOff();
                }
                StringBuilder MyStringBuilder = new StringBuilder();
                //string yy = MyStringBuilder.ToString();
                string datSend = "";

                foreach (var item in runToolList)
                {
                    if (item is IToolRun)
                    {
                        try
                        {
                            item.Run();
                            string result = item.IsOk ? "OK" : "NG";
                            Util.Notify(string.Format("{0}_{1} T={2:f2}ms,结果: {3}", item.Name, result, item.ExecutionTime, item.Result));
                            MyStringBuilder.Append(string.Format("{0}_{1}_T={2:f2}ms\r\n", item.Name, result, item.ExecutionTime));
                            if (item.IsOutputResults)
                            {
                                string dat = item.GetSendResult();
                                if (dat != string.Empty)
                                {
                                    datSend += dat;
                                    datSend += toolDelimiter;
                                }
                            }
                            runStatus.RunStatusList.Add(item.IsOk);
                        }
                        catch (Exception ex)
                        {
                            //Util.WriteLog(this.GetType(), ex);
                            Util.Notify(Level.Err, string.Format("工具{0}运行出现异常{1}", item.Name, ex.Message));
                            runStatus.RunStatusList.Add(false);
                        }
                    }
                    else
                    {
                        runStatus.RunStatusList.Add(true);
                    }
                }
                runStatus.ResultMessage = MyStringBuilder.ToString();

                //时间统计
                HOperatorSet.CountSeconds(out toolEnd);
                double toolTime = (toolEnd - toolStart) * 1000.0;   //toolStart) * 1000.0;
                Util.Notify(string.Format("工具组{0}图像处理用时{1:f2}ms", settingIndex, toolTime));
                #region 3 查找是否存在运行错误的工具
                toolErr = runToolList.Find(x => x.IsOk == false && x is IToolRun);

                if (toolErr == null && ToolsFactory.ToolsDic.Count > 0)
                {
                    runningResultFlag = true;
                    ok++;
                }
                else
                {
                    runningResultFlag = false;
                    ng++;
                    Util.Notify(string.Format("工具{0}图像处理检测到异常", toolErr.Name));
                }

                if (runningResultFlag == true)
                {
                    datSend = Util.TrimEndString(datSend, toolDelimiter);
                    datSend = Util.TrimStartString(datSend, toolDelimiter);
                }
                else
                {
                    datSend = ("Image" + Environment.NewLine + "Done" + Environment.NewLine);
                }

                if (isOffLineMode == false)         //这个变量与AutoUnit中的isTestMode不是同一个,这里是指AutoUnit的测试模式与离线模式。
                {
                    //SerialHelper.Instance.WriteCommdToSerial(datSend);
                    //非相机输出模式下就直接输出文本信息
                    if (!CommHandle.Instance.CommunicationParam.IsCamIOOutput &&
                        datSend != string.Empty)
                    {
                        Util.Notify(string.Format("发送结果: {0}", datSend));
                        autoUnit.RunCommWriteDataThread.WriteData(datSend);
                    }
                    else
                    {
                        if (StatusManger.Instance.IsInterlocking && CameraManger.CameraDic.ContainsKey(settingIndex) && runningResultFlag == false)
                        {
                            CameraManger.CameraDic[settingIndex].Output();   //结果NG时相机外部输出信号导通。
                        }
                    }
                }
                else
                {
                    if (runningResultFlag == false)
                    {
                        Util.Notify(string.Format("测试结果:{0}", "NG"));
                    }
                    else
                    {
                        Util.Notify(string.Format("测试结果:{0}", "OK"));
                    }
                }
                #endregion
                #region 4 显示所有的图形
                //HTuple showStart;
                //HOperatorSet.CountSeconds(out showStart);
                autoUnit.Invoke(new Action <HWndCtrl, List <ToolBase>, bool>((h, l, f) =>
                {
                    ShowResult(h, l, f);
                }), hWndCtrl, runToolList, runningResultFlag);

                #endregion

                HTuple end1;
                HOperatorSet.CountSeconds(out end1);
                double time1 = (end1 - toolEnd) * 1000.0;
                Util.Notify(string.Format("工具组{0}分析显示用时{1:f2}ms", settingIndex, time1));
            }
            catch (Exception)
            {
                //Util.WriteLog(this.GetType(), ex);
                Util.Notify(string.Format("图像处理异常"));
            }
            finally
            {
                HOperatorSet.CountSeconds(out end);
                double runTime = 0;
                runTime = (end - startExTime) * 1000.0;

                runStatus.OKCount   = ok;
                runStatus.NgCount   = ng;
                runStatus.CylceTime = runTime;
                RunStatus runStatusTmp = runStatus.DeepClone();
                autoUnit.RefreshUI(runStatusTmp);

                //指示可以来图像处理
                Util.Notify(string.Format("---工具组{0}运行完成,用时{1:f2}ms\r\n", settingIndex, runTime));
                imageRunFinishSignalFlow.Set();
                //离线模式
                if (isOffLineMode &&
                    createImageTool.OffLineMode == true &&
                    createImageTool.AllReadFinish == false)
                {
                    Task.Run(async delegate
                    {
                        await Task.Delay(1000);
                        if (isOffLineMode)
                        {
                            TrigerRun(this.settingIndex, true);  //离线测试模式时,接着触发下次离线测试。
                        }
                    });
                }
                else
                {
                    isOffLineMode = false;   //将该对象的离线模式标志复位,不再执行离线。
                }
            }
        }
Exemplo n.º 8
0
        protected override void ProcDataDeal()
        {
            if (comChannel == null)
            {
                comChannel = new PanasonicSerial();
            }
            try
            {
                comChannel.InitSerial(UserSetting.Instance.MainDeviceComParam);
            }
            catch (Exception ex)
            {
                if (comChannel != null)
                {
                    comChannel.Close();
                    comChannel = null;
                }
                StatusManger statusManger = StatusManger.Instance;
                statusManger.RuningStatus = RuningStatus.系统异常;
                Util.WriteLog(this.GetType(), ex);
                Util.Notify("PLC : 初始化失败: " + ex.Message);
                if (comChannel == null)
                {
                    return;
                }
                try
                {
                    while (isLink)
                    {
                        #region 读plc数据流程
                        {
                            comChannel.ReadDT("D10", "D40");
                            // 待机
                            Thread.Sleep(10);

                            // 数据接收
                            comChannel.ReceiveFinsResponse();
                            if (comChannel.IsReadOK)
                            {
                                // 锁定
                                mutexShMem.WaitOne();

                                // 读取数据写入共享内存区域
                                int length = comChannel.DTValue.Length;
                                if (length < (DMI_SIZE))
                                {
                                    throw new ArgumentOutOfRangeException("收到数据长度异常");
                                }
                                for (int i = 0; i < DMI_SIZE; i++)
                                {
                                    // 共有存储在存储器  16位eg:abcd
                                    int   ofst  = DMI_OFST + i * Marshal.SizeOf(typeof(short));
                                    short value = (short)(comChannel.DTValue[i]);
                                    //将读取到的PLC数据写入到相应的内存区域
                                    Marshal.WriteInt16(mapAddrPtr, ofst, value);
                                }

                                // 解除
                                mutexShMem.ReleaseMutex();
                            }
                        }
                        #endregion
                        Thread.Sleep(8);
                        #region 写数据到plc
                        {
                            // 锁定
                            mutexShMem.WaitOne();

                            // 从共享存储器获取要写入plc的数据
                            short[] data = new short[DMO_SIZE];

                            for (int i = 0; i < data.GetLength(0); i++)
                            {
                                int ofst = DMO_OFST + i * Marshal.SizeOf(typeof(short));

                                data[i] = Marshal.ReadInt16(mapAddrPtr, ofst);
                            }

                            // 解除
                            mutexShMem.ReleaseMutex();

                            comChannel.WriteDT("D0", "D10", data);

                            // 待机
                            Thread.Sleep(1);

                            // 等待接收  --接收数据校验
                            comChannel.ReceiveFinsResponse();

                            #endregion
                            Thread.Sleep(8);
                        }
                    }
                }
                catch (Exception ex1)
                {
                    Util.WriteLog(this.GetType(), ex1);
                    Util.Notify("串口通信异常");
                }
                finally
                {
                    if (comChannel != null)
                    {
                        comChannel.Close();
                    }
                }
            }
        }