コード例 #1
0
        private void _cameraMV_ConnectionEventCallback(Enum_ConnectionEvent e, object obj)
        {
            switch (e)
            {
            case Enum_ConnectionEvent.DISCOVERED_NEW_CAMERA:
                this.Invoke(new Action(() =>
                {
                    Visionscape.Devices.VsDeviceClass dev = obj as Visionscape.Devices.VsDeviceClass;
                    if (dev.Name != null)
                    {
                        VisionDevice = dev.Name;
                    }
                }));
                break;

            case Enum_ConnectionEvent.DISCOVERED_CAMERA:
                _cameraMV.ConnectJob(job_path + cbbCongViec.SelectedItem.ToString());
                break;

            case Enum_ConnectionEvent.CONNECTED_JOB:
                _cameraMV.DownloadJob();
                break;

            case Enum_ConnectionEvent.DOWNLOADING_JOB:
                break;

            case Enum_ConnectionEvent.DOWNLOADED_JOB:
                _cameraMV.ConnectIO();
                _cameraMV.ConnectReport();
                break;

            case Enum_ConnectionEvent.CONNECTED_REPORT:
                break;

            case Enum_ConnectionEvent.RECEIVED_REPORT:
                break;

            case Enum_ConnectionEvent.RECEIVED_IMAGE:
                Visionscape.Communications.InspectionReport report = obj as Visionscape.Communications.InspectionReport;

                this.Invoke(new Action(() =>
                {
                    //Update Image
                    bufferView2.Buffer = report.Images[0];
                    //Update Tool Data
                    foreach (Visionscape.Communications.InspectionReportValue result in report.Results)
                    {
                        try
                        {
                            //if (result.NameSym == "Snapshot1.OCRX1.OutStr")
                            //{
                            //    _dataCamera.ReceviedString = result.AsString;
                            //    lblChuoiNhan.Text = _dataCamera.ReceviedString;
                            //}
                            if (result.NameSym == _stringOfToolVS)
                            {
                                _dataCamera.ReceviedString = result.AsString;
                                lblChuoiNhan.Text          = _dataCamera.ReceviedString;
                            }
                        }
                        catch
                        {
                        }
                    }

                    if (!chbChayTest.Checked)
                    {
                        //Pass - Fail Processing
                        if (report.InspectionStats.Passed)
                        {
                            if (_dataCamera.ReceviedString.Length == 10)
                            {
                                if (_mode.RunModeCurrent == RunMode.mode.NORMAL)
                                {
                                    _soluongPass++;
                                    _dataCamera.CounterPASS = _soluongPass;

                                    lblPassFail.Text      = ReceviedDataFromCamera.Result.PASS.ToString();
                                    lblPassFail.BackColor = Color.Green;

                                    lblCounterPass.Text = _dataCamera.CounterPASS.ToString();
                                    lblCounter.Text     = _dataCamera.CounterPASS.ToString();

                                    SQLite.Instance().ThemDuLieuSanPham(DateTime.Now.ToString("ddMMyyyyHHmmss"), DateTime.Now.ToString("dd/MM/yyyy"),
                                                                        _dsDaiLy.MaDL, _dsDaiLy.TenDL, _dataCamera.ReceviedString);

                                    if (_soluongPass == int.Parse(numericUpDown1.Value.ToString()))
                                    {
                                        if (MessageBox.Show("Đã chạy đủ số lượng", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                        {
                                            btnChayDung.PerformClick();
                                        }
                                    }
                                }

                                else if (_mode.RunModeCurrent == RunMode.mode.CHECK)
                                {
                                    lblPassFail.Text      = ReceviedDataFromCamera.Result.PASS.ToString();
                                    lblPassFail.BackColor = Color.Green;

                                    _dulieuSP = SQLite.Instance().LayDuLieuSanPham(_dataCamera.ReceviedString);
                                    frmCheck.lblChuoiNhan.Text      = _dulieuSP.MaSP;
                                    frmCheck.lblMaDL.Text           = _dulieuSP.MaDL;
                                    frmCheck.lblTenDL.Text          = _dulieuSP.TenDL;
                                    frmCheck.lblNgayGioXuat.Text    = _dulieuSP.Time;
                                    frmCheck.lblKhoangThoiGian.Text = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy"))
                                                                      .Subtract(Convert.ToDateTime(_dulieuSP.Time)).ToString("dd") + " ngày";
                                    if (frmCheck.cbbChonDaiLy.SelectedItem.ToString() == _dulieuSP.TenDL)
                                    {
                                        frmCheck.lblKetQua.Text         = "KHỚP";
                                        frmCheck.lblKetQua.BackColor    = Color.Green;
                                        frmCheck.lblTenDL.BackColor     = Color.SeaGreen;
                                        frmCheck.cbbChonDaiLy.BackColor = Color.SeaGreen;
                                    }
                                    else
                                    {
                                        frmCheck.lblKetQua.Text         = "KHÔNG KHỚP";
                                        frmCheck.lblKetQua.BackColor    = Color.Red;
                                        frmCheck.lblTenDL.BackColor     = Color.Red;
                                        frmCheck.cbbChonDaiLy.BackColor = Color.Red;
                                        Fx1s.SetDevice2("M2", 1);
                                    }
                                }
                            }
                            else
                            {
                                if (_mode.RunModeCurrent == RunMode.mode.NORMAL)
                                {
                                    _soluongFail++;
                                    _dataCamera.CounterFAIL = _soluongFail;

                                    lblPassFail.Text      = ReceviedDataFromCamera.Result.FAIL.ToString();
                                    lblPassFail.BackColor = Color.OrangeRed;

                                    lblCounterFail.Text = _dataCamera.CounterFAIL.ToString();
                                    lblCounterFail.Text = _dataCamera.CounterFAIL.ToString();

                                    Fx1s.SetDevice2("M2", 1);

                                    string name      = DateTime.Now.ToString("dd/MM/yy-HHmmssfff") + "_F";
                                    string imagePath = Properties.Settings.Default.PathLuuAnh + "\\NORMAL\\" + name + ".bmp";
                                    bufferView2.Buffer.SaveImage(imagePath, Visionscape.Steps.EnumImgFileType.ftWithGraphics);
                                }
                                else if (_mode.RunModeCurrent == RunMode.mode.CHECK)
                                {
                                    lblPassFail.Text      = ReceviedDataFromCamera.Result.FAIL.ToString();
                                    lblPassFail.BackColor = Color.OrangeRed;
                                    Fx1s.SetDevice2("M2", 1);

                                    string name      = DateTime.Now.ToString("dd/MM/yy-HHmmssfff") + "_F";
                                    string imagePath = Properties.Settings.Default.PathLuuAnh + "\\CHECK\\" + name + ".bmp";
                                    bufferView2.Buffer.SaveImage(imagePath, Visionscape.Steps.EnumImgFileType.ftWithGraphics);
                                }
                            }
                        }
                        else
                        {
                            if (_mode.RunModeCurrent == RunMode.mode.NORMAL)
                            {
                                _soluongFail++;
                                _dataCamera.CounterFAIL = _soluongFail;

                                lblPassFail.Text      = ReceviedDataFromCamera.Result.FAIL.ToString();
                                lblPassFail.BackColor = Color.OrangeRed;

                                lblCounterFail.Text = _dataCamera.CounterFAIL.ToString();
                                lblCounterFail.Text = _dataCamera.CounterFAIL.ToString();

                                Fx1s.SetDevice2("M2", 1);

                                string name      = DateTime.Now.ToString("dd/MM/yy-HHmmssfff") + "_F";
                                string imagePath = Properties.Settings.Default.PathLuuAnh + "\\NORMAL\\" + name + ".bmp";
                                bufferView2.Buffer.SaveImage(imagePath, Visionscape.Steps.EnumImgFileType.ftWithGraphics);
                            }
                            else if (_mode.RunModeCurrent == RunMode.mode.CHECK)
                            {
                                lblPassFail.Text      = ReceviedDataFromCamera.Result.FAIL.ToString();
                                lblPassFail.BackColor = Color.OrangeRed;
                                Fx1s.SetDevice2("M2", 1);

                                string name      = DateTime.Now.ToString("dd/MM/yy-HHmmssfff") + "_F";
                                string imagePath = Properties.Settings.Default.PathLuuAnh + "\\CHECK\\" + name + ".bmp";
                                bufferView2.Buffer.SaveImage(imagePath, Visionscape.Steps.EnumImgFileType.ftWithGraphics);
                            }
                        }
                    }
                    else
                    {
                        if (report.InspectionStats.Passed)
                        {
                            if (_dataCamera.ReceviedString.Length == 10)
                            {
                                lblPassFail.Text      = ReceviedDataFromCamera.Result.PASS.ToString();
                                lblPassFail.BackColor = Color.Green;
                            }
                            else
                            {
                                lblPassFail.Text      = ReceviedDataFromCamera.Result.FAIL.ToString();
                                lblPassFail.BackColor = Color.OrangeRed;
                                Fx1s.SetDevice2("M2", 1);
                            }
                        }
                        else
                        {
                            lblPassFail.Text      = ReceviedDataFromCamera.Result.FAIL.ToString();
                            lblPassFail.BackColor = Color.OrangeRed;
                            Fx1s.SetDevice2("M2", 1);
                        }
                    }

                    //Save Image
                }));
                break;

            case Enum_ConnectionEvent.CONNECTED_IO:
                break;

            case Enum_ConnectionEvent.TRIGGERED_IO:
                break;

            case Enum_ConnectionEvent.STATECHANGED_IO:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_DEVICE:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_JOB:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_REPORT:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_IO:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_ALL:
                break;

            case Enum_ConnectionEvent.ERROR:
                break;

            default:
                break;
            }
        }
コード例 #2
0
        private void _cameraMV40_ConnectionEventCallback(Enum_ConnectionEvent e, object obj)
        {
            switch (e)
            {
            case Enum_ConnectionEvent.DISCOVERED_NEW_CAMERA:
                Application.Current.Dispatcher.Invoke(new
                                                      Action(() =>
                {
                    Visionscape.Devices.VsDeviceClass dev = obj as Visionscape.Devices.VsDeviceClass;
                    if (dev.Name != null)
                    {
                        VisionDevice = dev.Name;
                    }
                }));

                break;

            case Enum_ConnectionEvent.DISCOVERED_CAMERA:
                _cameraMV40.ConnectJob(job_path + cbbCongViec.Text);
                break;

            case Enum_ConnectionEvent.CONNECTED_JOB:
                _cameraMV40.DownloadJob();
                break;

            case Enum_ConnectionEvent.DOWNLOADING_JOB:
                break;

            case Enum_ConnectionEvent.DOWNLOADED_JOB:
                _cameraMV40.ConnectIO();
                _cameraMV40.ConnectReport();
                break;

            case Enum_ConnectionEvent.CONNECTED_REPORT:
                break;

            case Enum_ConnectionEvent.RECEIVED_REPORT:
                break;

            case Enum_ConnectionEvent.RECEIVED_IMAGE:
                Visionscape.Communications.InspectionReport report = obj as Visionscape.Communications.InspectionReport;
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    //Update Image
                    imgBuffer.DataContext = report.Images[0];

                    //Update Tool Data
                    foreach (Visionscape.Communications.InspectionReportValue result in report.Results)
                    {
                        try
                        {
                            if (result.NameSym == "Snapshot1.HiLevelTool1.OCRX1.OutStr")
                            {
                                _camera.ReceviedString = result.AsString;
                            }
                        }
                        catch
                        {
                        }
                        if (report.InspectionStats.Passed)
                        {
                            _camera.CounterPass++;
                        }
                        else
                        {
                            _camera.CounterFail++;
                        }
                    }
                }));
                break;

            case Enum_ConnectionEvent.CONNECTED_IO:
                break;

            case Enum_ConnectionEvent.TRIGGERED_IO:
                break;

            case Enum_ConnectionEvent.STATECHANGED_IO:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_DEVICE:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_JOB:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_REPORT:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_IO:
                break;

            case Enum_ConnectionEvent.DISCONNECTED_ALL:
                break;

            case Enum_ConnectionEvent.ERROR:
                break;

            default:
                break;
            }
        }