예제 #1
0
        private void buttonGetImage_Click(object sender, EventArgs e)
        {
            if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
            {
                Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                try
                {
                    if (image != null)
                    {
                        image.Dispose();
                    }
                    Svision.GetMe().baslerCamera.getFrameImageWithStart(out image);
                    if (ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag)
                    {
                        HOperatorSet.MapImage(image, ConfigInformation.GetInstance().tCalCfg.ho_MapFixed, out image);
                    }
                    basicClass.getImageSize(image, out rowNumber, out columnNumber);
                    double widRat = pictureBoxGetAndSaveImage.Width / ((double)columnNumber);
                    double heiRat = pictureBoxGetAndSaveImage.Height / ((double)rowNumber);
                    resizerate = widRat < heiRat ? widRat : heiRat;
                    if (img != null)
                    {
                        img.Dispose();
                    }
                    basicClass.resizeImage(image, out img, resizerate);
                    if (oriPictureBoxShowImageWidth != pictureBoxGetAndSaveImage.Width)
                    {
                        basicClass.displayClear(GetAndSaveImageHWHandle);
                    }
                    if (oriPictureBoxShowImageHeight != pictureBoxGetAndSaveImage.Height)
                    {
                        basicClass.displayClear(GetAndSaveImageHWHandle);
                    }
                    basicClass.displayhobject(img, GetAndSaveImageHWHandle);
                }
                catch (Exception ex)
                {
                    System.Threading.Thread.Sleep(100);
                    if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    else
                    {
                        groupBoxManual.Enabled = false;
                        groupBoxAuto.Enabled   = false;

                        Cursor = Cursors.WaitCursor;
                        Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
                        MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
                        Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
                        Svision.GetMe().cameraRefresh();
                        Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                        Cursor = Cursors.Default;
                        groupBoxManual.Enabled = true;
                        groupBoxAuto.Enabled   = true;
                    }
                }
            }
        }
        private void buttonSystemCfgBootConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.checkBoxSystemCfgEnableBoot.Checked == true)
                {
                    if ((this.textBoxSystemCfgBootProgram.Text == String.Empty) || (this.textBoxSystemCfgBootProgram.Text == " "))
                    {
                        MessageBox.Show("请输入正确的工程路径");
                        return;
                    }
                    else
                    {
                        ConfigInformation.GetInstance().tSysCfg.bootPath = this.textBoxSystemCfgBootProgram.Text;
                        ConfigInformation.GetInstance().tSysCfg.isBoot = this.checkBoxSystemCfgEnableBoot.Checked;

                        ConfigInformation.GetInstance().tSysCfg.saveSysInfoCfg();
                        this.Close();
                    }
                }
                else
                {
                    ConfigInformation.GetInstance().tSysCfg.bootPath = this.textBoxSystemCfgBootProgram.Text;
                    ConfigInformation.GetInstance().tSysCfg.isBoot = this.checkBoxSystemCfgEnableBoot.Checked;

                    ConfigInformation.GetInstance().tSysCfg.saveSysInfoCfg();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        public static ConfigInformation GetInstance()
        {
            if (tCfgInfo == null)
            {
                tCfgInfo = new ConfigInformation();
            }

            return(tCfgInfo);
        }
예제 #4
0
 private void FileInputSet_Load(object sender, EventArgs e)
 {
     HOperatorSet.OpenWindow(0, 0, (pictureBoxImage.Width), (pictureBoxImage.Height), pictureBoxImage.Handle, "visible", "", out FileInputHWHandle);
     HOperatorSet.SetPart(FileInputHWHandle, 0, 0, (pictureBoxImage.Height), (pictureBoxImage.Width));
     HDevWindowStack.Push(FileInputHWHandle);
     oriPictureBoxShowImageWidth  = pictureBoxImage.Width;
     oriPictureBoxShowImageHeight = pictureBoxImage.Height;
     numericUpDownColumn.Value    = ConfigInformation.GetInstance().tFileCfg.columns;
     numericUpDownRow.Value       = ConfigInformation.GetInstance().tFileCfg.rows;
     if (ConfigInformation.GetInstance().tFileCfg.channelNum == 1)
     {
         comboBoxChannel.SelectedIndex = 0;
     }
     else
     {
         comboBoxChannel.SelectedIndex = 1;
     }
 }
        private void buttonCamParaSetCancel_Click(object sender, EventArgs e)
        {
            try
            {
                cameraParaTimer.Enabled    = false;
                numericUpDownheight.Value  = prvRow;
                numericUpDownWidth.Value   = prvColumn;
                numericUpDownXOffset.Value = prvXoffset;
                numericUpDownYOffset.Value = prvYoffset;
                ConfigInformation.GetInstance().tCamCfg.rows = (int)numericUpDownheight.Value;
                ConfigInformation.GetInstance().tCamCfg.columns = (int)numericUpDownWidth.Value;
                ConfigInformation.GetInstance().tCamCfg.xOffset = (int)numericUpDownXOffset.Value;
                ConfigInformation.GetInstance().tCamCfg.yOffset = (int)numericUpDownYOffset.Value;
                //channel


                if (prvChannelNum == 1)
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(1);

                    ConfigInformation.GetInstance().tCamCfg.channelNum = 1;
                }
                else if (prvChannelNum == 3 && channelMax == 3)
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(3);
                    ConfigInformation.GetInstance().tCamCfg.channelNum = 3;
                }
                else
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(1);
                    ConfigInformation.GetInstance().tCamCfg.channelNum = 1;
                }

                //gamma
                numericUpDownGamma.Value = (decimal)(prvGammaPercent * 100);
                ConfigInformation.GetInstance().tCamCfg.gammaPercent = prvGammaPercent;

                //gain
                if (prvIsGainAuto)
                {
                    ConfigInformation.GetInstance().tCamCfg.isGainAuto = true;
                    checkBoxGainAuto.CheckState = CheckState.Checked;
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isGainAuto = false;
                    checkBoxGainAuto.CheckState = CheckState.Unchecked;
                    numericUpDownGain.Value     = (decimal)(prvGainPercent * 100);
                    ConfigInformation.GetInstance().tCamCfg.gainPercent = prvGainPercent;
                }

                //exposure
                if (prvIsExposureAuto)
                {
                    checkBoxExposureAuto.CheckState = CheckState.Checked;
                    ConfigInformation.GetInstance().tCamCfg.isExposureAuto = true;
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isExposureAuto = false;
                    checkBoxExposureAuto.CheckState = CheckState.Unchecked;
                    numericUpDownExposure.Value     = (decimal)(prvExposurePercent * 100);
                    ConfigInformation.GetInstance().tCamCfg.exposurePercent = prvExposurePercent;
                }

                //white balance
                if (prvIsWhiteBalanceAuto)
                {
                    checkBoxWhiteBalanceAuto.CheckState = CheckState.Checked;
                    ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = true;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = prvWhiteBalanceBluePercent;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = prvWhiteBalanceGreenPercent;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = prvWhiteBalanceRedPercent;
                    }
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = false;
                    checkBoxWhiteBalanceAuto.CheckState = CheckState.Unchecked;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = prvWhiteBalanceBluePercent;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = prvWhiteBalanceGreenPercent;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = prvWhiteBalanceRedPercent;
                        numericUpDownBlueBalance.Value  = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent() * 100);
                        numericUpDownRedBalance.Value   = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent() * 100);
                        numericUpDownGreenBalance.Value = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent() * 100);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.Close();
        }
        private void buttonCamParaSetConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                cameraParaTimer.Enabled = false;

                ConfigInformation.GetInstance().tCamCfg.rows = (int)numericUpDownheight.Value;
                ConfigInformation.GetInstance().tCamCfg.columns = (int)numericUpDownWidth.Value;
                ConfigInformation.GetInstance().tCamCfg.xOffset = (int)numericUpDownXOffset.Value;
                ConfigInformation.GetInstance().tCamCfg.yOffset = (int)numericUpDownYOffset.Value;
                ConfigInformation.GetInstance().tCamCfg.channelNum = Svision.GetMe().baslerCamera.getChannelNumber();
                ConfigInformation.GetInstance().tCamCfg.gammaPercent = ((double)numericUpDownGamma.Value) / 100;
                if (checkBoxGainAuto.Checked)
                {
                    ConfigInformation.GetInstance().tCamCfg.isGainAuto = true;
                    ConfigInformation.GetInstance().tCamCfg.gainPercent = Svision.GetMe().baslerCamera.getGainPercent();
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isGainAuto = false;
                    ConfigInformation.GetInstance().tCamCfg.gainPercent = Svision.GetMe().baslerCamera.getGainPercent();
                }
                if (checkBoxExposureAuto.Checked)
                {
                    ConfigInformation.GetInstance().tCamCfg.isExposureAuto = true;
                    ConfigInformation.GetInstance().tCamCfg.exposurePercent = Svision.GetMe().baslerCamera.getExposurePercent();
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isExposureAuto = false;
                    ConfigInformation.GetInstance().tCamCfg.exposurePercent = Svision.GetMe().baslerCamera.getExposurePercent();
                }
                if (checkBoxWhiteBalanceAuto.Checked)
                {
                    ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = true;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = ((double)numericUpDownBlueBalance.Value) / 100;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = ((double)numericUpDownGreenBalance.Value) / 100;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = ((double)numericUpDownRedBalance.Value) / 100;
                    }
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = false;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = ((double)numericUpDownBlueBalance.Value) / 100;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = ((double)numericUpDownGreenBalance.Value) / 100;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = ((double)numericUpDownRedBalance.Value) / 100;
                    }
                }
                this.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //Svision.GetMe().Enabled = tru;
        }
        private void CameraParaSet_Load(object sender, EventArgs e)
        {
            try
            {
                HOperatorSet.OpenWindow(0, 0, 256, 192, cameraParapictureBox.Handle, "visible", "", out cameraParaHWHandle);
                HOperatorSet.SetPart(cameraParaHWHandle, 0, 0, 191, 255);
                HDevWindowStack.Push(cameraParaHWHandle);
                HOperatorSet.SetLineWidth(cameraParaHWHandle, 1);
                HOperatorSet.SetColor(cameraParaHWHandle, "green");
                HOperatorSet.OpenWindow(0, 0, cameraParaPartpictureBox.Width, cameraParaPartpictureBox.Height, cameraParaPartpictureBox.Handle, "visible", "", out cameraParaPartHWHandle);
                HOperatorSet.SetPart(cameraParaPartHWHandle, 0, 0, cameraParaPartpictureBox.Height - 1, cameraParaPartpictureBox.Width - 1);
                HDevWindowStack.Push(cameraParaPartHWHandle);

                //Load Camera Config from configInformation and set these to the camera
                //row
                //  numericUpDownheight.Value = trackBarHeight.Value = Svision.GetMe().baslerCamera.getRowNumber();

                int[] rowRange;
                int   rowIncrement;
                Svision.GetMe().baslerCamera.getCameraRowRange(out rowRange);
                Svision.GetMe().baslerCamera.getRowIncrement(out rowIncrement);
                numericUpDownheight.Maximum            = rowRange[1];
                numericUpDownheight.Minimum            = rowRange[0];
                numericUpDownheight.Increment          = rowIncrement;
                numericUpDownheight.InterceptArrowKeys = true;
                trackBarHeight.Maximum     = rowRange[1];
                trackBarHeight.Minimum     = rowRange[0];
                trackBarHeight.SmallChange = rowIncrement;
                trackBarHeight.LargeChange = rowIncrement * 10;
                numericUpDownheight.Value  = ConfigInformation.GetInstance().tCamCfg.rows;
                prvRow = trackBarHeight.Value;
                //column
                //       numericUpDownWidth.Value = trackBarWidth.Value = Svision.GetMe().baslerCamera.getColumnNumber();

                int[] columnRange;
                int   columnIncrement;
                Svision.GetMe().baslerCamera.getCameraColumnRange(out columnRange);
                Svision.GetMe().baslerCamera.getColumnIncrement(out columnIncrement);
                numericUpDownWidth.Maximum            = columnRange[1];
                numericUpDownWidth.Minimum            = columnRange[0];
                numericUpDownWidth.Increment          = columnIncrement;
                numericUpDownWidth.InterceptArrowKeys = true;
                trackBarWidth.Maximum     = columnRange[1];
                trackBarWidth.Minimum     = columnRange[0];
                trackBarWidth.SmallChange = columnIncrement;
                trackBarWidth.LargeChange = columnIncrement * 10;
                numericUpDownWidth.Value  = ConfigInformation.GetInstance().tCamCfg.columns;
                prvColumn = trackBarWidth.Value;
                //Offset

                int XOffsetIncrement, YOffsetIncrement;
                Svision.GetMe().baslerCamera.getCameraOffsetRange(out XOffsetRange, out YOffsetRange);
                Svision.GetMe().baslerCamera.getOffsetIncrement(out XOffsetIncrement, out YOffsetIncrement);
                numericUpDownXOffset.Maximum            = XOffsetRange[1];
                numericUpDownXOffset.Minimum            = XOffsetRange[0];
                numericUpDownXOffset.Increment          = XOffsetIncrement;
                numericUpDownXOffset.InterceptArrowKeys = true;
                numericUpDownYOffset.Maximum            = YOffsetRange[1];
                numericUpDownYOffset.Minimum            = YOffsetRange[0];
                numericUpDownYOffset.Increment          = YOffsetIncrement;
                numericUpDownYOffset.InterceptArrowKeys = true;
                trackBarXOffset.Maximum     = XOffsetRange[1];
                trackBarXOffset.Minimum     = XOffsetRange[0];
                trackBarXOffset.SmallChange = XOffsetIncrement;
                trackBarXOffset.LargeChange = XOffsetIncrement * 10;
                trackBarYOffset.Maximum     = YOffsetRange[1];
                trackBarYOffset.Minimum     = YOffsetRange[0];
                trackBarYOffset.SmallChange = YOffsetIncrement;
                trackBarYOffset.LargeChange = YOffsetIncrement * 10;
                numericUpDownXOffset.Value  = ConfigInformation.GetInstance().tCamCfg.xOffset;
                numericUpDownYOffset.Value  = ConfigInformation.GetInstance().tCamCfg.yOffset;
                //        numericUpDownXOffset.Value = trackBarXOffset.Value = Svision.GetMe().baslerCamera.getXOffsetNumber();
                prvXoffset = trackBarXOffset.Value;
                //     numericUpDownYOffset.Value = trackBarYOffset.Value = Svision.GetMe().baslerCamera.getYOffsetNumber();
                prvYoffset = trackBarYOffset.Value;
                //channel

                Svision.GetMe().baslerCamera.getCameraMaxChannel(out channelMax);
                if (ConfigInformation.GetInstance().tCamCfg.channelNum == 1)
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(1);
                    radioButtonGray.Checked = true;
                    prvChannelNum           = 1;
                }
                else if (ConfigInformation.GetInstance().tCamCfg.channelNum == 3 && channelMax == 3)
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(3);
                    radioButtonColour.Checked = true;
                    prvChannelNum             = 3;
                }
                else
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(1);
                    radioButtonGray.Checked = true;
                    prvChannelNum           = 1;
                }

                if (channelMax == 1)
                {
                    radioButtonColour.Enabled = false;
                }
                //gamma
                numericUpDownGamma.Value = (decimal)(ConfigInformation.GetInstance().tCamCfg.gammaPercent * 100);
                prvGammaPercent          = ConfigInformation.GetInstance().tCamCfg.gammaPercent;

                //gain
                if (ConfigInformation.GetInstance().tCamCfg.isGainAuto)
                {
                    prvIsGainAuto = true;
                    checkBoxGainAuto.CheckState = CheckState.Checked;
                    groupBoxGain.Enabled        = false;
                }
                else
                {
                    prvIsGainAuto = false;
                    Svision.GetMe().baslerCamera.setGainAuto(false);
                    checkBoxGainAuto.CheckState = CheckState.Unchecked;
                    numericUpDownGain.Value     = (decimal)(ConfigInformation.GetInstance().tCamCfg.gainPercent * 100);
                    prvGainPercent       = ConfigInformation.GetInstance().tCamCfg.gainPercent;
                    groupBoxGain.Enabled = true;
                }

                //exposure
                if (ConfigInformation.GetInstance().tCamCfg.isExposureAuto)
                {
                    checkBoxExposureAuto.CheckState = CheckState.Checked;
                    groupBoxExposure.Enabled        = false;
                    prvIsExposureAuto = true;
                }
                else
                {
                    prvIsExposureAuto = false;
                    Svision.GetMe().baslerCamera.setExposureAuto(false);
                    checkBoxExposureAuto.CheckState = CheckState.Unchecked;
                    numericUpDownExposure.Value     = (decimal)(ConfigInformation.GetInstance().tCamCfg.exposurePercent * 100);
                    prvExposurePercent       = ConfigInformation.GetInstance().tCamCfg.exposurePercent;
                    groupBoxExposure.Enabled = true;
                }

                //white balance
                if (ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto)
                {
                    checkBoxWhiteBalanceAuto.CheckState = CheckState.Checked;
                    groupBoxWhiteBalance.Enabled        = false;
                    prvIsWhiteBalanceAuto = true;
                }
                else
                {
                    prvIsWhiteBalanceAuto = false;
                    Svision.GetMe().baslerCamera.setWhiteBalanceAuto(false);
                    checkBoxWhiteBalanceAuto.CheckState = CheckState.Unchecked;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        groupBoxWhiteBalance.Enabled = true;
                        prvWhiteBalanceBluePercent   = ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent;
                        prvWhiteBalanceGreenPercent  = ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent;
                        prvWhiteBalanceRedPercent    = ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent;

                        //prvWhiteBalanceBluePercent = ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent;
                        //prvWhiteBalanceGreenPercent = ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent;
                        //prvWhiteBalanceRedPercent = ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent;


                        numericUpDownBlueBalance.Value  = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent() * 100);
                        numericUpDownRedBalance.Value   = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent() * 100);
                        numericUpDownGreenBalance.Value = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent() * 100);
                    }
                    else
                    {
                        groupBoxWhiteBalance.Enabled = false;
                        //numericUpDownBlueBalance.Value = (int)(Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent() * 100);
                        //numericUpDownRedBalance.Value = (int)(Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent() * 100);
                        //numericUpDownGreenBalance.Value = (int)(Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent() * 100);
                        //prvWhiteBalanceBluePercent = Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent();
                        //prvWhiteBalanceGreenPercent = Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent();
                        //prvWhiteBalanceRedPercent = Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent();
                    }
                }


                panelDetail.Enabled = false;
                //camera information
                string modelNameStr, deviceVendorNameStr, deviceModelNameStr, deviceFirmwareVersionStr;
                Svision.GetMe().baslerCamera.getCameraInformation(out modelNameStr, out deviceVendorNameStr, out deviceModelNameStr, out deviceFirmwareVersionStr);
                textBoxCameraInformation.Text = "相机型号: " + modelNameStr + "\r\n" + "\r\n" + "供应商: " + deviceVendorNameStr + "\r\n" + "\r\n" + "设备型号: " + deviceModelNameStr + "\r\n" + "\r\n" + "设备固件版本:" + deviceFirmwareVersionStr + "\r\n";
                cameraParaTimer.Enabled       = true;
            }
            catch (System.Exception ex)
            {
                cameraParaTimer.Enabled = false;
                System.Threading.Thread.Sleep(100);
                if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
                {
                    MessageBox.Show(ex.Message);
                }
                else
                {
                    Cursor = Cursors.WaitCursor;
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
                    MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
                    Svision.GetMe().cameraRefresh();
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                    Cursor = Cursors.Default;
                    cameraParaTimer.Enabled = true;
                }
            }
        }
 private void cameraParaTimer_Tick(object sender, EventArgs e)
 {
     try
     {
         if (image != null)
         {
             image.Dispose();
         }
         int rowNum, columnNum;
         numericUpDownExposure.Value = (decimal)(Svision.GetMe().baslerCamera.getExposurePercent() * 100);
         numericUpDownGain.Value     = (decimal)(Svision.GetMe().baslerCamera.getGainPercent() * 100);
         Svision.GetMe().baslerCamera.getFrameImage(out image);
         if (ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag)
         {
             HOperatorSet.MapImage(image, ConfigInformation.GetInstance().tCalCfg.ho_MapFixed, out image);
         }
         //HOperatorSet.WriteImage(image, "bmp", 0, "H:/vision_dll/trunk/C#_CODE/UI/Svision/a.bmp");
         basicClass.getImageSize(image, out rowNum, out columnNum);
         double widRat    = 256 / ((double)columnNum);
         double heiRat    = 192 / ((double)rowNum);
         double resRatNew = widRat < heiRat ? widRat : heiRat;
         if (resRat != resRatNew)
         {
             basicClass.displayClear(cameraParaHWHandle);
             resRat = resRatNew;
         }
         rectLocationX = preLocation.X;
         rectLocationY = preLocation.Y;
         if (preLocation.X <= 0)
         {
             rectLocationX = 0;
         }
         if (preLocation.Y <= 0)
         {
             rectLocationY = 0;
         }
         if (preLocation.X + cameraParaPartpictureBox.Width * resRat > Math.Min((columnNum - 1) * resRat - 1, 255))
         {
             rectLocationX = Math.Min((columnNum - cameraParaPartpictureBox.Width - 1) * resRat - 1, 255 - cameraParaPartpictureBox.Width * resRat);
         }
         if (preLocation.Y + cameraParaPartpictureBox.Height * resRat > Math.Min((rowNum - 1) * resRat - 1, 191))
         {
             rectLocationY = Math.Min((rowNum - cameraParaPartpictureBox.Height - 1) * resRat - 1, 191 - cameraParaPartpictureBox.Height * resRat);
         }
         double widRatPart    = cameraParaPartpictureBox.Width / ((double)columnNum);
         double heiRatPart    = cameraParaPartpictureBox.Height / ((double)rowNum);
         double resRatPartNew = widRatPart < heiRatPart ? widRatPart : heiRatPart;
         if (resRatPart != resRatPartNew)
         {
             basicClass.displayClear(cameraParaPartHWHandle);
             resRatPart = resRatPartNew;
         }
         if (img != null)
         {
             img.Dispose();
         }
         basicClass.resizeImage(image, out img, resRat);
         HOperatorSet.DispObj(img, cameraParaHWHandle);
         if (resRatPart > 1)
         {
             if (imgPart != null)
             {
                 imgPart.Dispose();
             }
             HOperatorSet.CopyImage(image, out imgPart);
             HOperatorSet.DispObj(imgPart, cameraParaPartHWHandle);
         }
         else
         {
             if (rowNum * resRat > 6 && columnNum * resRat > 8)
             {
                 basicClass.displayRectangle1XldScreen(cameraParaHWHandle, Math.Max(rectLocationY, 1), Math.Max(rectLocationX, 1), rectLocationY + cameraParaPartpictureBox.Height * resRat - 2, rectLocationX + cameraParaPartpictureBox.Width * resRat - 2);
                 basicClass.genRectangle1(out rectDomain, rectLocationY / resRat, rectLocationX / resRat, Math.Min(rectLocationY / resRat + cameraParaPartpictureBox.Height - 1, rowNum - 1), Math.Min(rectLocationX / resRat + cameraParaPartpictureBox.Width - 1, columnNum - 1));
                 if (imgPart != null)
                 {
                     imgPart.Dispose();
                 }
                 basicClass.reduceDomain(image, rectDomain, out imgPart);
                 HOperatorSet.CropDomain(imgPart, out imgPart);
                 HOperatorSet.DispObj(imgPart, cameraParaPartHWHandle);
             }
         }
     }
     catch (System.Exception ex)
     {
         cameraParaTimer.Enabled = false;
         System.Threading.Thread.Sleep(100);
         if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
         {
             MessageBox.Show(ex.Message);
         }
         else
         {
             Cursor = Cursors.WaitCursor;
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
             MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
             Svision.GetMe().cameraRefresh();
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
             Cursor = Cursors.Default;
             cameraParaTimer.Enabled = true;
         }
     }
 }
예제 #9
0
        private void InitCom()
        {
            switch (ConfigInformation.GetInstance().tComCfg.ComMainType)
            {
            case CComConfig.ComTypeEnum.MODBUS_TCP:
                radioButtonTCP.Checked       = false;
                radioButtonModbusTCP.Checked = true;
                radioButtonUDP.Checked       = false;
                tabControlComCfg.SelectedTab = tabPageComCfgModbusTCP;
                break;

            case CComConfig.ComTypeEnum.TCP_CLIENT:
                radioButtonTCP.Checked             = true;
                radioButtonModbusTCP.Checked       = false;
                radioButtonUDP.Checked             = false;
                tabControlComCfg.SelectedTab       = tabPageComCfgTCP;
                radioButtonComCfgTcpServer.Checked = false;
                radioButtonComCfgTcpClient.Checked = true;
                textBoxComCfgTcpServerIP.Text      = ConfigInformation.GetInstance().tComCfg.TCPServerIP;
                textBoxComCfgTcpServerPort.Text    = ConfigInformation.GetInstance().tComCfg.TCPServerPort;
                textBoxComCfgTcpLocalPort.Enabled  = false;
                textBoxComCfgTcpLocalIP.Enabled    = false;
                if (ConfigInformation.GetInstance().tComCfg.TrigMode == CComConfig.TrigModeEnum.COM_TRIG)
                {
                    radioButtonComCfgTcpTrigModeComTrig.Checked = true;
                    textBoxComCfgTcpTrigCom.Text     = ConfigInformation.GetInstance().tComCfg.TrigStr;
                    textBoxComCfgTcpTrigTime.Enabled = false;
                }
                else
                {
                    radioButtonComCfgTcpTrigModeTimeTrig.Checked = true;
                    textBoxComCfgTcpTrigTime.Text   = ConfigInformation.GetInstance().tComCfg.TrigTime.ToString();
                    textBoxComCfgTcpTrigCom.Enabled = false;
                }
                break;

            case CComConfig.ComTypeEnum.TCP_SERVER:
                radioButtonTCP.Checked             = true;
                radioButtonModbusTCP.Checked       = false;
                radioButtonUDP.Checked             = false;
                tabControlComCfg.SelectedTab       = tabPageComCfgTCP;
                radioButtonComCfgTcpServer.Checked = true;
                radioButtonComCfgTcpClient.Checked = false;

                textBoxComCfgTcpLocalIP.Text   = ConfigInformation.GetInstance().tComCfg.TCPLocalIP;
                textBoxComCfgTcpLocalPort.Text = ConfigInformation.GetInstance().tComCfg.TCPLocalPort;

                if (ConfigInformation.GetInstance().tComCfg.TrigMode == CComConfig.TrigModeEnum.COM_TRIG)
                {
                    radioButtonComCfgTcpTrigModeComTrig.Checked = true;
                    textBoxComCfgTcpTrigCom.Text     = ConfigInformation.GetInstance().tComCfg.TrigStr;
                    textBoxComCfgTcpTrigTime.Enabled = false;
                }
                else
                {
                    radioButtonComCfgTcpTrigModeTimeTrig.Checked = true;
                    textBoxComCfgTcpTrigTime.Text   = ConfigInformation.GetInstance().tComCfg.TrigTime.ToString();
                    textBoxComCfgTcpTrigCom.Enabled = false;
                }

                textBoxComCfgTcpServerIP.Enabled   = false;
                textBoxComCfgTcpServerPort.Enabled = false;
                break;

            case CComConfig.ComTypeEnum.UDP:
                radioButtonTCP.Checked       = true;
                radioButtonModbusTCP.Checked = false;
                radioButtonUDP.Checked       = false;
                tabControlComCfg.SelectedTab = tabPageComCfgUDP;
                break;

            default:
                break;
            }
        }
예제 #10
0
 private void buttonComCfgConfirm_Click(object sender, EventArgs e)
 {
     try
     {
         if (radioButtonTCP.Checked)                             //TCP
         {
             if (radioButtonComCfgTcpServer.Checked)             //TCP_Server
             {
                 if (textBoxComCfgTcpLocalPort.Text == String.Empty ||
                     textBoxComCfgTcpLocalIP.Text == String.Empty)
                 {
                     MessageBox.Show("请输入正确的本地IP地址和端口号!");
                     return;
                 }
                 else
                 {
                     if (radioButtonComCfgTcpTrigModeComTrig.Checked && (textBoxComCfgTcpTrigCom.Text == String.Empty))
                     {
                         MessageBox.Show("请输入正确的触发报文!");
                         return;
                     }
                     else if (radioButtonComCfgTcpTrigModeTimeTrig.Checked && (textBoxComCfgTcpTrigTime.Text == String.Empty))
                     {
                         MessageBox.Show("请输入正确的触发时间!");
                         return;
                     }
                     else
                     {
                         ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.TCP_SERVER;
                         ConfigInformation.GetInstance().tComCfg.TCPLocalPort = textBoxComCfgTcpLocalPort.Text;
                         ConfigInformation.GetInstance().tComCfg.TCPLocalIP = textBoxComCfgTcpLocalIP.Text;
                         if (radioButtonComCfgTcpTrigModeTimeTrig.Checked)
                         {
                             ConfigInformation.GetInstance().tComCfg.TrigMode = CComConfig.TrigModeEnum.TIME_TRIG;
                             ConfigInformation.GetInstance().tComCfg.TrigTime = int.Parse(textBoxComCfgTcpTrigTime.Text);
                         }
                         else
                         {
                             ConfigInformation.GetInstance().tComCfg.TrigMode = CComConfig.TrigModeEnum.COM_TRIG;
                             ConfigInformation.GetInstance().tComCfg.TrigStr = textBoxComCfgTcpTrigCom.Text;
                         }
                     }
                 }
             }
             else if (radioButtonComCfgTcpClient.Checked)        //TCP_Client
             {
                 if ((textBoxComCfgTcpServerPort.Text == String.Empty) | (textBoxComCfgTcpServerIP.Text == String.Empty))
                 {
                     MessageBox.Show("请正确的输入远程服务器IP地址,端口号和触发条件");
                     return;
                 }
                 else
                 {
                     if (radioButtonComCfgTcpTrigModeComTrig.Checked && (textBoxComCfgTcpTrigCom.Text == String.Empty))
                     {
                         MessageBox.Show("请输入正确的触发报文!");
                         return;
                     }
                     else if (radioButtonComCfgTcpTrigModeTimeTrig.Checked && (textBoxComCfgTcpTrigTime.Text == String.Empty))
                     {
                         MessageBox.Show("请输入正确的触发时间!");
                         return;
                     }
                     else
                     {
                         ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.TCP_CLIENT;
                         ConfigInformation.GetInstance().tComCfg.TCPServerPort = textBoxComCfgTcpServerPort.Text;
                         ConfigInformation.GetInstance().tComCfg.TCPServerIP = textBoxComCfgTcpServerIP.Text;
                         if (radioButtonComCfgTcpTrigModeTimeTrig.Checked)
                         {
                             ConfigInformation.GetInstance().tComCfg.TrigMode = CComConfig.TrigModeEnum.TIME_TRIG;
                             ConfigInformation.GetInstance().tComCfg.TrigTime = int.Parse(textBoxComCfgTcpTrigTime.Text);
                         }
                         else
                         {
                             ConfigInformation.GetInstance().tComCfg.TrigMode = CComConfig.TrigModeEnum.COM_TRIG;
                             ConfigInformation.GetInstance().tComCfg.TrigStr = textBoxComCfgTcpTrigCom.Text;
                         }
                     }
                 }
             }
         }
         else if (radioButtonUDP.Checked)                                             //UDP
         {
         }
         else if (radioButtonModbusTCP.Checked)                                      //ModbusTCP
         {
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     this.Close();
 }
예제 #11
0
        public void LoadCfgInfo(String tmpPath)
        {
            XmlDocument tXmlDoc = new XmlDocument();

            try
            {
                tXmlDoc.Load(tmpPath);
                XmlNode rootNode = tXmlDoc.SelectSingleNode("Configuration");
                //load com config
                {
                    XmlNode ComNode = rootNode.SelectSingleNode("CommunicateConfig");

                    if (ComNode.SelectSingleNode("ComMainType").Attributes["ComMainType"].InnerText ==
                        ConfigInformation.GetInstance().tComCfg.ComTypeDic[CComConfig.ComTypeEnum.TCP_SERVER])
                    {
                        ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.TCP_SERVER;
                    }
                    else if (ComNode.SelectSingleNode("ComMainType").Attributes["ComMainType"].InnerText ==
                             ConfigInformation.GetInstance().tComCfg.ComTypeDic[CComConfig.ComTypeEnum.TCP_CLIENT])
                    {
                        ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.TCP_CLIENT;
                    }
                    else if (ComNode.SelectSingleNode("ComMainType").Attributes["ComMainType"].InnerText ==
                             ConfigInformation.GetInstance().tComCfg.ComTypeDic[CComConfig.ComTypeEnum.UDP])
                    {
                        ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.UDP;
                    }
                    else if (ComNode.SelectSingleNode("ComMainType").Attributes["ComMainType"].InnerText ==
                             ConfigInformation.GetInstance().tComCfg.ComTypeDic[CComConfig.ComTypeEnum.MODBUS_TCP])
                    {
                        ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.MODBUS_TCP;
                    }

                    ConfigInformation.GetInstance().tComCfg.ComTCPServer =
                        bool.Parse(ComNode.SelectSingleNode("ComTCPServer").Attributes["ComTCPServer"].InnerText);

                    ConfigInformation.GetInstance().tComCfg.TCPServerIP =
                        ComNode.SelectSingleNode("TCPServerIP").Attributes["TCPServerIP"].InnerText;
                    ConfigInformation.GetInstance().tComCfg.TCPServerPort =
                        ComNode.SelectSingleNode("TCPServerPort").Attributes["TCPServerPort"].InnerText;
                    ConfigInformation.GetInstance().tComCfg.TCPLocalIP =
                        ComNode.SelectSingleNode("TCPLocalIP").Attributes["TCPLocalIP"].InnerText;
                    ConfigInformation.GetInstance().tComCfg.TCPLocalPort =
                        ComNode.SelectSingleNode("TCPLocalPort").Attributes["TCPLocalPort"].InnerText;

                    if (ComNode.SelectSingleNode("TrigMode").Attributes["TrigMode"].InnerText ==
                        ConfigInformation.GetInstance().tComCfg.TrigModeDic[CComConfig.TrigModeEnum.COM_TRIG])
                    {
                        ConfigInformation.GetInstance().tComCfg.TrigMode = CComConfig.TrigModeEnum.COM_TRIG;
                    }
                    else if (ComNode.SelectSingleNode("TrigMode").Attributes["TrigMode"].InnerText ==
                             ConfigInformation.GetInstance().tComCfg.TrigModeDic[CComConfig.TrigModeEnum.TIME_TRIG])
                    {
                        ConfigInformation.GetInstance().tComCfg.TrigMode = CComConfig.TrigModeEnum.TIME_TRIG;
                    }

                    ConfigInformation.GetInstance().tComCfg.TrigStr =
                        ComNode.SelectSingleNode("TrigStr").Attributes["TrigStr"].InnerText;
                    ConfigInformation.GetInstance().tComCfg.TrigTime =
                        int.Parse(ComNode.SelectSingleNode("TrigTime").Attributes["TrigTime"].InnerText);
                }
                //load camera config
                {
                    XmlNode CameraNode = rootNode.SelectSingleNode("CameraConfig");
                    //Row
                    int   rowTest = int.Parse(CameraNode.SelectSingleNode("Rows").Attributes["Rows"].InnerText);
                    int[] rowRange;
                    Svision.GetMe().baslerCamera.getCameraRowRange(out rowRange);
                    if (rowTest > rowRange[1])
                    {
                        throw new Exception("错误!当前导入工程设置的相机行数大于当前使用相机行数的最大值!相机配置、标定配置和文件配置部分内容导入失败!");
                    }
                    Svision.GetMe().baslerCamera.setRowNumber(int.Parse(CameraNode.SelectSingleNode("Rows").Attributes["Rows"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.rows = int.Parse(CameraNode.SelectSingleNode("Rows").Attributes["Rows"].InnerText);
                    Svision.GetMe().oriRowNumber = ConfigInformation.GetInstance().tCamCfg.rows;
                    //Column
                    int   columnTest = int.Parse(CameraNode.SelectSingleNode("Columns").Attributes["Columns"].InnerText);
                    int[] columnRange;
                    Svision.GetMe().baslerCamera.getCameraColumnRange(out columnRange);
                    if (columnTest > columnRange[1])
                    {
                        throw new Exception("错误!当前导入工程设置的相机行数大于当前使用相机列数的最大值!相机配置、标定配置和文件配置部分内容导入失败!");
                    }
                    Svision.GetMe().baslerCamera.setColumnNumber(int.Parse(CameraNode.SelectSingleNode("Columns").Attributes["Columns"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.columns = int.Parse(CameraNode.SelectSingleNode("Columns").Attributes["Columns"].InnerText);
                    Svision.GetMe().oriColumnNumber = ConfigInformation.GetInstance().tCamCfg.columns;
                    //XOffset
                    int   XOffsetTest = int.Parse(CameraNode.SelectSingleNode("XOffset").Attributes["XOffset"].InnerText);
                    int[] XOffsetRange;
                    Svision.GetMe().baslerCamera.getCameraXOffsetRange(out XOffsetRange);
                    if (XOffsetTest > XOffsetRange[1])
                    {
                        throw new Exception("错误!当前导入工程设置的相机行偏移大于当前使用相机行偏移的最大值!相机配置、标定配置和文件配置部分内容导入失败!");
                    }
                    Svision.GetMe().baslerCamera.setOffsetX(int.Parse(CameraNode.SelectSingleNode("XOffset").Attributes["XOffset"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.xOffset = int.Parse(CameraNode.SelectSingleNode("XOffset").Attributes["XOffset"].InnerText);
                    //YOffset
                    int   YOffsetTest = int.Parse(CameraNode.SelectSingleNode("YOffset").Attributes["YOffset"].InnerText);
                    int[] YOffsetRange;
                    Svision.GetMe().baslerCamera.getCameraYOffsetRange(out YOffsetRange);
                    if (YOffsetTest > YOffsetRange[1])
                    {
                        throw new Exception("错误!当前导入工程设置的相机列偏移大于当前使用相机列偏移的最大值!相机配置、标定配置和文件配置部分内容导入失败!");
                    }
                    Svision.GetMe().baslerCamera.setOffsetY(int.Parse(CameraNode.SelectSingleNode("YOffset").Attributes["YOffset"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.yOffset = int.Parse(CameraNode.SelectSingleNode("YOffset").Attributes["YOffset"].InnerText);
                    //ChannelNum
                    int channelMax;
                    Svision.GetMe().baslerCamera.getCameraMaxChannel(out channelMax);
                    if (int.Parse(CameraNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText) == 1)
                    {
                        Svision.GetMe().baslerCamera.setChannelNumber(1);
                        ConfigInformation.GetInstance().tCamCfg.channelNum = int.Parse(CameraNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText);
                    }
                    else if (int.Parse(CameraNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText) == 3 && channelMax == 3)
                    {
                        Svision.GetMe().baslerCamera.setChannelNumber(3);
                        ConfigInformation.GetInstance().tCamCfg.channelNum = int.Parse(CameraNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText);
                    }
                    else
                    {
                        throw new Exception("导入相机通道设置失败!当前相机为黑白相机,无法设置获取彩色图像!");
                    }

                    //Gamma
                    Svision.GetMe().baslerCamera.setGammaPercent(double.Parse(CameraNode.SelectSingleNode("GammaPercent").Attributes["GammaPercent"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.gammaPercent = double.Parse(CameraNode.SelectSingleNode("GammaPercent").Attributes["GammaPercent"].InnerText);

                    //Gain
                    if (bool.Parse(CameraNode.SelectSingleNode("IsGainAuto").Attributes["IsGainAuto"].InnerText))
                    {
                        Svision.GetMe().baslerCamera.setGainAuto(true);
                        ConfigInformation.GetInstance().tCamCfg.isGainAuto = bool.Parse(CameraNode.SelectSingleNode("IsGainAuto").Attributes["IsGainAuto"].InnerText);
                        ConfigInformation.GetInstance().tCamCfg.gainPercent = Svision.GetMe().baslerCamera.getGainPercent();
                    }
                    else
                    {
                        Svision.GetMe().baslerCamera.setGainAuto(false);
                        ConfigInformation.GetInstance().tCamCfg.isGainAuto = bool.Parse(CameraNode.SelectSingleNode("IsGainAuto").Attributes["IsGainAuto"].InnerText);
                        Svision.GetMe().baslerCamera.setGainPercent(double.Parse(CameraNode.SelectSingleNode("GainPercent").Attributes["GainPercent"].InnerText));
                        ConfigInformation.GetInstance().tCamCfg.gainPercent = double.Parse(CameraNode.SelectSingleNode("GainPercent").Attributes["GainPercent"].InnerText);
                    }

                    //Exposure
                    if (bool.Parse(CameraNode.SelectSingleNode("IsExposureAuto").Attributes["IsExposureAuto"].InnerText))
                    {
                        Svision.GetMe().baslerCamera.setExposureAuto(true);
                        ConfigInformation.GetInstance().tCamCfg.exposurePercent = Svision.GetMe().baslerCamera.getExposurePercent();
                        ConfigInformation.GetInstance().tCamCfg.isExposureAuto = bool.Parse(CameraNode.SelectSingleNode("IsExposureAuto").Attributes["IsExposureAuto"].InnerText);
                    }
                    else
                    {
                        Svision.GetMe().baslerCamera.setExposureAuto(false);
                        ConfigInformation.GetInstance().tCamCfg.isExposureAuto = bool.Parse(CameraNode.SelectSingleNode("IsExposureAuto").Attributes["IsExposureAuto"].InnerText);
                        Svision.GetMe().baslerCamera.setExposurePercent(double.Parse(CameraNode.SelectSingleNode("ExposurePercent").Attributes["ExposurePercent"].InnerText));
                        ConfigInformation.GetInstance().tCamCfg.exposurePercent = double.Parse(CameraNode.SelectSingleNode("ExposurePercent").Attributes["ExposurePercent"].InnerText);
                    }

                    //WhiteBalance
                    if (bool.Parse(CameraNode.SelectSingleNode("IsWhiteBalanceAuto").Attributes["IsWhiteBalanceAuto"].InnerText))
                    {
                        Svision.GetMe().baslerCamera.setWhiteBalanceAuto(true);
                        ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = bool.Parse(CameraNode.SelectSingleNode("IsWhiteBalanceAuto").Attributes["IsWhiteBalanceAuto"].InnerText);
                    }
                    else
                    {
                        Svision.GetMe().baslerCamera.setWhiteBalanceAuto(false);
                        ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = bool.Parse(CameraNode.SelectSingleNode("IsWhiteBalanceAuto").Attributes["IsWhiteBalanceAuto"].InnerText);
                        if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                        {
                            Svision.GetMe().baslerCamera.setWhiteBalanceBlue(double.Parse(CameraNode.SelectSingleNode("WhiteBalanceBluePercent").Attributes["WhiteBalanceBluePercent"].InnerText));
                            Svision.GetMe().baslerCamera.setWhiteBalanceGreen(double.Parse(CameraNode.SelectSingleNode("WhiteBalanceGreenPercent").Attributes["WhiteBalanceGreenPercent"].InnerText));
                            Svision.GetMe().baslerCamera.setWhiteBalanceRed(double.Parse(CameraNode.SelectSingleNode("WhiteBalanceRedPercent").Attributes["WhiteBalanceRedPercent"].InnerText));

                            ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = double.Parse(CameraNode.SelectSingleNode("WhiteBalanceBluePercent").Attributes["WhiteBalanceBluePercent"].InnerText);
                            ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = double.Parse(CameraNode.SelectSingleNode("WhiteBalanceGreenPercent").Attributes["WhiteBalanceGreenPercent"].InnerText);
                            ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = double.Parse(CameraNode.SelectSingleNode("WhiteBalanceRedPercent").Attributes["WhiteBalanceRedPercent"].InnerText);
                        }
                    }
                }
                //load file config
                {
                    XmlNode FileNode = null;
                    bool    isFileOK = true;
                    try
                    {
                        FileNode = rootNode.SelectSingleNode("FileConfig");
                    }
                    catch (System.Exception ex)
                    {
                        isFileOK = false;
                    }
                    if (isFileOK && FileNode != null)
                    {
                        ConfigInformation.GetInstance().tFileCfg.rows = int.Parse(FileNode.SelectSingleNode("Rows").Attributes["Rows"].InnerText);
                        ConfigInformation.GetInstance().tFileCfg.columns = int.Parse(FileNode.SelectSingleNode("Columns").Attributes["Columns"].InnerText);
                        ConfigInformation.GetInstance().tFileCfg.channelNum = int.Parse(FileNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText);
                        Svision.GetMe().checkBoxIsFile.Checked = bool.Parse(FileNode.SelectSingleNode("IsFileInput").Attributes["IsFileInput"].InnerText);
                        if (Svision.GetMe().checkBoxIsFile.Checked)
                        {
                            Svision.GetMe().oriRowNumber    = ConfigInformation.GetInstance().tFileCfg.rows;
                            Svision.GetMe().oriColumnNumber = ConfigInformation.GetInstance().tFileCfg.columns;
                        }
                    }
                }
                //load calibration config
                {
                    XmlNode CalNode = rootNode.SelectSingleNode("CalibrationConfig");

                    ConfigInformation.GetInstance().tCalCfg.calibrationDistance = double.Parse(CalNode.SelectSingleNode("calibrationDistance").Attributes["calibrationDistance"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.calibrationPoint = int.Parse(CalNode.SelectSingleNode("calibrationPoint").Attributes["calibrationPoint"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.focus = int.Parse(CalNode.SelectSingleNode("focus").Attributes["focus"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.calibrationRate = double.Parse(CalNode.SelectSingleNode("calibrationRate").Attributes["calibrationRate"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.pixelSize = double.Parse(CalNode.SelectSingleNode("pixelSize").Attributes["pixelSize"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.isCheckBoxRadialDistortion = bool.Parse(CalNode.SelectSingleNode("isCheckBoxRadialDistortion").Attributes["isCheckBoxRadialDistortion"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.calibrationParaConfirmFlag = bool.Parse(CalNode.SelectSingleNode("calibrationParaConfirmFlag").Attributes["calibrationParaConfirmFlag"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag = bool.Parse(CalNode.SelectSingleNode("calibrationIsRadialDistortionFlag").Attributes["calibrationIsRadialDistortionFlag"].InnerText);
                    if (ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag)
                    {
                        HOperatorSet.ReadImage(out ConfigInformation.GetInstance().tCalCfg.ho_MapFixed, (HTuple)tmpPath.Remove(tmpPath.LastIndexOf("\\") + 1) + "_calibrationMap.tiff");
                    }
                    XmlNode useThreePointCalibrationNode = null;
                    bool    isuseThreePointCalibrationOK = true;
                    try
                    {
                        useThreePointCalibrationNode = CalNode.SelectSingleNode("useThreePointCalibration");
                    }
                    catch (System.Exception ex)
                    {
                        isuseThreePointCalibrationOK = false;
                    }
                    if (isuseThreePointCalibrationOK && useThreePointCalibrationNode != null)
                    {
                        ConfigInformation.GetInstance().tCalCfg.useThreePointCalibration = bool.Parse(CalNode.SelectSingleNode("useThreePointCalibration").Attributes["useThreePointCalibration"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p1x = double.Parse(CalNode.SelectSingleNode("p1x").Attributes["p1x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p2x = double.Parse(CalNode.SelectSingleNode("p2x").Attributes["p2x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p3x = double.Parse(CalNode.SelectSingleNode("p3x").Attributes["p3x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r1x = double.Parse(CalNode.SelectSingleNode("r1x").Attributes["r1x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r2x = double.Parse(CalNode.SelectSingleNode("r2x").Attributes["r2x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r3x = double.Parse(CalNode.SelectSingleNode("r3x").Attributes["r3x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p1y = double.Parse(CalNode.SelectSingleNode("p1y").Attributes["p1y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p2y = double.Parse(CalNode.SelectSingleNode("p2y").Attributes["p2y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p3y = double.Parse(CalNode.SelectSingleNode("p3y").Attributes["p3y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r1y = double.Parse(CalNode.SelectSingleNode("r1y").Attributes["r1y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r2y = double.Parse(CalNode.SelectSingleNode("r2y").Attributes["r2y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r3y = double.Parse(CalNode.SelectSingleNode("r3y").Attributes["r3y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.Sx = double.Parse(CalNode.SelectSingleNode("Sx").Attributes["Sx"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.Sy = double.Parse(CalNode.SelectSingleNode("Sy").Attributes["Sy"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.thea = double.Parse(CalNode.SelectSingleNode("thea").Attributes["thea"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.Tx = double.Parse(CalNode.SelectSingleNode("Tx").Attributes["Tx"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.Ty = double.Parse(CalNode.SelectSingleNode("Ty").Attributes["Ty"].InnerText);
                        if (ConfigInformation.GetInstance().tCalCfg.useThreePointCalibration)
                        {
                            double[][] a = { new double[] { double.Parse(CalNode.SelectSingleNode("mx1").Attributes["mx1"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx2").Attributes["mx2"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx3").Attributes["mx3"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx4").Attributes["mx4"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx5").Attributes["mx5"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx6").Attributes["mx6"].InnerText) } };
                            ConfigInformation.GetInstance().tCalCfg.mx = Matrix.Create(a);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #12
0
        public void SaveCfgInfo(String tmpPath)
        {
            XmlDocument    tXmlDoc = new XmlDocument();
            XmlDeclaration xmldel;

            xmldel = tXmlDoc.CreateXmlDeclaration("1.0", null, null);
            tXmlDoc.AppendChild(xmldel);
            XmlElement xmlelem = tXmlDoc.CreateElement("", "Configuration", "");

            tXmlDoc.AppendChild(xmlelem);

            XmlElement rootCameraCfg      = tXmlDoc.CreateElement("CameraConfig");
            XmlElement rootFileCfg        = tXmlDoc.CreateElement("FileConfig");
            XmlElement rootCalibrationCfg = tXmlDoc.CreateElement("CalibrationConfig");
            XmlElement rootCommunicateCfg = tXmlDoc.CreateElement("CommunicateConfig");

            xmlelem.AppendChild(rootCommunicateCfg);
            xmlelem.AppendChild(rootCameraCfg);
            xmlelem.AppendChild(rootFileCfg);
            xmlelem.AppendChild(rootCalibrationCfg);

            //save com information
            {
                XmlElement ComMainTypeElement = tXmlDoc.CreateElement("ComMainType");
                ComMainTypeElement.SetAttribute("ComMainType", ConfigInformation.GetInstance().tComCfg.ComMainType.ToString());
                XmlElement ComTCPServerElement = tXmlDoc.CreateElement("ComTCPServer");
                ComTCPServerElement.SetAttribute("ComTCPServer", ConfigInformation.GetInstance().tComCfg.ComTCPServer.ToString());
                XmlElement TCPServerIPElement = tXmlDoc.CreateElement("TCPServerIP");
                TCPServerIPElement.SetAttribute("TCPServerIP", ConfigInformation.GetInstance().tComCfg.TCPServerIP.ToString());
                XmlElement TCPServerPortElement = tXmlDoc.CreateElement("TCPServerPort");
                TCPServerPortElement.SetAttribute("TCPServerPort", ConfigInformation.GetInstance().tComCfg.TCPServerPort.ToString());
                XmlElement TCPLocalIPElement = tXmlDoc.CreateElement("TCPLocalIP");
                TCPLocalIPElement.SetAttribute("TCPLocalIP", ConfigInformation.GetInstance().tComCfg.TCPLocalIP.ToString());
                XmlElement TCPLocalPortElement = tXmlDoc.CreateElement("TCPLocalPort");
                TCPLocalPortElement.SetAttribute("TCPLocalPort", ConfigInformation.GetInstance().tComCfg.TCPLocalPort.ToString());
                XmlElement TrigModeElement = tXmlDoc.CreateElement("TrigMode");
                TrigModeElement.SetAttribute("TrigMode", ConfigInformation.GetInstance().tComCfg.TrigMode.ToString());
                XmlElement TrigStrElement = tXmlDoc.CreateElement("TrigStr");
                TrigStrElement.SetAttribute("TrigStr", ConfigInformation.GetInstance().tComCfg.TrigStr.ToString());
                XmlElement TrigTimeElement = tXmlDoc.CreateElement("TrigTime");
                TrigTimeElement.SetAttribute("TrigTime", ConfigInformation.GetInstance().tComCfg.TrigTime.ToString());

                rootCommunicateCfg.AppendChild(ComMainTypeElement);
                rootCommunicateCfg.AppendChild(ComTCPServerElement);
                rootCommunicateCfg.AppendChild(TCPServerIPElement);
                rootCommunicateCfg.AppendChild(TCPServerPortElement);
                rootCommunicateCfg.AppendChild(TCPLocalIPElement);
                rootCommunicateCfg.AppendChild(TCPLocalPortElement);
                rootCommunicateCfg.AppendChild(TrigModeElement);
                rootCommunicateCfg.AppendChild(TrigStrElement);
                rootCommunicateCfg.AppendChild(TrigTimeElement);
            }
            //save camera information
            {
                XmlElement RowsElement = tXmlDoc.CreateElement("Rows");
                RowsElement.SetAttribute("Rows", ConfigInformation.GetInstance().tCamCfg.rows.ToString());

                XmlElement ColumnsElement = tXmlDoc.CreateElement("Columns");
                ColumnsElement.SetAttribute("Columns", ConfigInformation.GetInstance().tCamCfg.columns.ToString());

                XmlElement XoffsetElement = tXmlDoc.CreateElement("XOffset");
                XoffsetElement.SetAttribute("XOffset", ConfigInformation.GetInstance().tCamCfg.xOffset.ToString());

                XmlElement YoffsetElement = tXmlDoc.CreateElement("YOffset");
                YoffsetElement.SetAttribute("YOffset", ConfigInformation.GetInstance().tCamCfg.yOffset.ToString());

                XmlElement channelNumElement = tXmlDoc.CreateElement("ChannelNum");
                channelNumElement.SetAttribute("ChannelNum", ConfigInformation.GetInstance().tCamCfg.channelNum.ToString());

                XmlElement gainPercentElement = tXmlDoc.CreateElement("GainPercent");
                gainPercentElement.SetAttribute("GainPercent", ConfigInformation.GetInstance().tCamCfg.gainPercent.ToString());

                XmlElement gammaPercentElement = tXmlDoc.CreateElement("GammaPercent");
                gammaPercentElement.SetAttribute("GammaPercent", ConfigInformation.GetInstance().tCamCfg.gammaPercent.ToString());

                XmlElement exposurePercentElement = tXmlDoc.CreateElement("ExposurePercent");
                exposurePercentElement.SetAttribute("ExposurePercent", ConfigInformation.GetInstance().tCamCfg.exposurePercent.ToString());

                XmlElement whiteBalanceBluePercentElement = tXmlDoc.CreateElement("WhiteBalanceBluePercent");
                whiteBalanceBluePercentElement.SetAttribute("WhiteBalanceBluePercent", ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent.ToString());

                XmlElement whiteBalanceGreenPercentElement = tXmlDoc.CreateElement("WhiteBalanceGreenPercent");
                whiteBalanceGreenPercentElement.SetAttribute("WhiteBalanceGreenPercent", ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent.ToString());

                XmlElement whiteBalanceRedPercentElement = tXmlDoc.CreateElement("WhiteBalanceRedPercent");
                whiteBalanceRedPercentElement.SetAttribute("WhiteBalanceRedPercent", ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent.ToString());

                XmlElement isExposureAutoElement = tXmlDoc.CreateElement("IsExposureAuto");
                isExposureAutoElement.SetAttribute("IsExposureAuto", ConfigInformation.GetInstance().tCamCfg.isExposureAuto.ToString());

                XmlElement isGainAutoElement = tXmlDoc.CreateElement("IsGainAuto");
                isGainAutoElement.SetAttribute("IsGainAuto", ConfigInformation.GetInstance().tCamCfg.isGainAuto.ToString());

                XmlElement isWhiteBalanceAutoElement = tXmlDoc.CreateElement("IsWhiteBalanceAuto");
                isWhiteBalanceAutoElement.SetAttribute("IsWhiteBalanceAuto", ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto.ToString());


                rootCameraCfg.AppendChild(RowsElement);
                rootCameraCfg.AppendChild(ColumnsElement);
                rootCameraCfg.AppendChild(XoffsetElement);
                rootCameraCfg.AppendChild(YoffsetElement);
                rootCameraCfg.AppendChild(channelNumElement);
                rootCameraCfg.AppendChild(gainPercentElement);
                rootCameraCfg.AppendChild(gammaPercentElement);
                rootCameraCfg.AppendChild(exposurePercentElement);
                rootCameraCfg.AppendChild(whiteBalanceBluePercentElement);
                rootCameraCfg.AppendChild(whiteBalanceGreenPercentElement);
                rootCameraCfg.AppendChild(whiteBalanceRedPercentElement);
                rootCameraCfg.AppendChild(isExposureAutoElement);
                rootCameraCfg.AppendChild(isGainAutoElement);
                rootCameraCfg.AppendChild(isWhiteBalanceAutoElement);
            }
            //save file information
            {
                XmlElement RowsElement = tXmlDoc.CreateElement("Rows");
                RowsElement.SetAttribute("Rows", ConfigInformation.GetInstance().tCamCfg.rows.ToString());
                XmlElement ColumnsElement = tXmlDoc.CreateElement("Columns");
                ColumnsElement.SetAttribute("Columns", ConfigInformation.GetInstance().tCamCfg.columns.ToString());
                XmlElement channelNumElement = tXmlDoc.CreateElement("ChannelNum");
                channelNumElement.SetAttribute("ChannelNum", ConfigInformation.GetInstance().tCamCfg.channelNum.ToString());
                XmlElement isFileInputElement = tXmlDoc.CreateElement("IsFileInput");
                isFileInputElement.SetAttribute("IsFileInput", Svision.GetMe().checkBoxIsFile.Checked.ToString());
                rootFileCfg.AppendChild(RowsElement);
                rootFileCfg.AppendChild(ColumnsElement);
                rootFileCfg.AppendChild(channelNumElement);
                rootFileCfg.AppendChild(isFileInputElement);
            }
            //save calibration information
            {
                XmlElement calibrationDistanceElement = tXmlDoc.CreateElement("calibrationDistance");
                calibrationDistanceElement.SetAttribute("calibrationDistance", ConfigInformation.GetInstance().tCalCfg.calibrationDistance.ToString());

                XmlElement calibrationPointElement = tXmlDoc.CreateElement("calibrationPoint");
                calibrationPointElement.SetAttribute("calibrationPoint", ConfigInformation.GetInstance().tCalCfg.calibrationPoint.ToString());

                XmlElement focusElement = tXmlDoc.CreateElement("focus");
                focusElement.SetAttribute("focus", ConfigInformation.GetInstance().tCalCfg.focus.ToString());

                XmlElement calibrationRateElement = tXmlDoc.CreateElement("calibrationRate");
                calibrationRateElement.SetAttribute("calibrationRate", ConfigInformation.GetInstance().tCalCfg.calibrationRate.ToString());

                XmlElement pixelSizeElement = tXmlDoc.CreateElement("pixelSize");
                pixelSizeElement.SetAttribute("pixelSize", ConfigInformation.GetInstance().tCalCfg.pixelSize.ToString());

                XmlElement isCheckBoxRadialDistortionElement = tXmlDoc.CreateElement("isCheckBoxRadialDistortion");
                isCheckBoxRadialDistortionElement.SetAttribute("isCheckBoxRadialDistortion", ConfigInformation.GetInstance().tCalCfg.isCheckBoxRadialDistortion.ToString());

                XmlElement calibrationParaConfirmFlagElement = tXmlDoc.CreateElement("calibrationParaConfirmFlag");
                calibrationParaConfirmFlagElement.SetAttribute("calibrationParaConfirmFlag", ConfigInformation.GetInstance().tCalCfg.calibrationParaConfirmFlag.ToString());

                XmlElement calibrationIsRadialDistortionFlagElement = tXmlDoc.CreateElement("calibrationIsRadialDistortionFlag");
                calibrationIsRadialDistortionFlagElement.SetAttribute("calibrationIsRadialDistortionFlag", ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag.ToString());
                if (ConfigInformation.GetInstance().tCalCfg.ho_MapFixed != null && ConfigInformation.GetInstance().tCalCfg.ho_MapFixed.IsInitialized())
                {
                    HOperatorSet.WriteImage(ConfigInformation.GetInstance().tCalCfg.ho_MapFixed, "tiff", 0, tmpPath.Remove(tmpPath.LastIndexOf("\\") + 1) + "_calibrationMap.tiff");
                }//XmlElement ho_MapFixedPathElement = tXmlDoc.CreateElement("ho_MapFixedPath");
                //ho_MapFixedPathElement.SetAttribute("ho_MapFixedPath", ConfigInformation.GetInstance().tCalCfg.ho_MapFixed.ToString());
                rootCalibrationCfg.AppendChild(calibrationDistanceElement);
                rootCalibrationCfg.AppendChild(calibrationPointElement);
                rootCalibrationCfg.AppendChild(focusElement);
                rootCalibrationCfg.AppendChild(calibrationRateElement);
                rootCalibrationCfg.AppendChild(pixelSizeElement);
                rootCalibrationCfg.AppendChild(isCheckBoxRadialDistortionElement);
                rootCalibrationCfg.AppendChild(calibrationParaConfirmFlagElement);
                rootCalibrationCfg.AppendChild(calibrationIsRadialDistortionFlagElement);
                //rootCameraCfg.AppendChild(whiteBalanceBluePercentElement);
                XmlElement useThreePointCalibrationElement = tXmlDoc.CreateElement("useThreePointCalibration");
                useThreePointCalibrationElement.SetAttribute("useThreePointCalibration", ConfigInformation.GetInstance().tCalCfg.useThreePointCalibration.ToString());

                XmlElement p1xElement = tXmlDoc.CreateElement("p1x");
                p1xElement.SetAttribute("p1x", ConfigInformation.GetInstance().tCalCfg.p1x.ToString());

                XmlElement p2xElement = tXmlDoc.CreateElement("p2x");
                p2xElement.SetAttribute("p2x", ConfigInformation.GetInstance().tCalCfg.p2x.ToString());

                XmlElement p3xElement = tXmlDoc.CreateElement("p3x");
                p3xElement.SetAttribute("p3x", ConfigInformation.GetInstance().tCalCfg.p3x.ToString());

                XmlElement r1xElement = tXmlDoc.CreateElement("r1x");
                r1xElement.SetAttribute("r1x", ConfigInformation.GetInstance().tCalCfg.r1x.ToString());

                XmlElement r2xElement = tXmlDoc.CreateElement("r2x");
                r2xElement.SetAttribute("r2x", ConfigInformation.GetInstance().tCalCfg.r2x.ToString());

                XmlElement r3xElement = tXmlDoc.CreateElement("r3x");
                r3xElement.SetAttribute("r3x", ConfigInformation.GetInstance().tCalCfg.r3x.ToString());

                XmlElement p1yElement = tXmlDoc.CreateElement("p1y");
                p1yElement.SetAttribute("p1y", ConfigInformation.GetInstance().tCalCfg.p1y.ToString());

                XmlElement p2yElement = tXmlDoc.CreateElement("p2y");
                p2yElement.SetAttribute("p2y", ConfigInformation.GetInstance().tCalCfg.p2y.ToString());

                XmlElement p3yElement = tXmlDoc.CreateElement("p3y");
                p3yElement.SetAttribute("p3y", ConfigInformation.GetInstance().tCalCfg.p3y.ToString());

                XmlElement r1yElement = tXmlDoc.CreateElement("r1y");
                r1yElement.SetAttribute("r1y", ConfigInformation.GetInstance().tCalCfg.r1y.ToString());

                XmlElement r2yElement = tXmlDoc.CreateElement("r2y");
                r2yElement.SetAttribute("r2y", ConfigInformation.GetInstance().tCalCfg.r2y.ToString());

                XmlElement r3yElement = tXmlDoc.CreateElement("r3y");
                r3yElement.SetAttribute("r3y", ConfigInformation.GetInstance().tCalCfg.r3y.ToString());

                XmlElement SxElement = tXmlDoc.CreateElement("Sx");
                SxElement.SetAttribute("Sx", ConfigInformation.GetInstance().tCalCfg.Sx.ToString());

                XmlElement SyElement = tXmlDoc.CreateElement("Sy");
                SyElement.SetAttribute("Sy", ConfigInformation.GetInstance().tCalCfg.Sy.ToString());

                XmlElement theaElement = tXmlDoc.CreateElement("thea");
                theaElement.SetAttribute("thea", ConfigInformation.GetInstance().tCalCfg.thea.ToString());

                XmlElement TxElement = tXmlDoc.CreateElement("Tx");
                TxElement.SetAttribute("Tx", ConfigInformation.GetInstance().tCalCfg.Tx.ToString());

                XmlElement TyElement = tXmlDoc.CreateElement("Ty");
                TyElement.SetAttribute("Ty", ConfigInformation.GetInstance().tCalCfg.Ty.ToString());
                rootCalibrationCfg.AppendChild(useThreePointCalibrationElement);
                rootCalibrationCfg.AppendChild(p1xElement);
                rootCalibrationCfg.AppendChild(p2xElement);
                rootCalibrationCfg.AppendChild(p3xElement);
                rootCalibrationCfg.AppendChild(r1xElement);
                rootCalibrationCfg.AppendChild(r2xElement);
                rootCalibrationCfg.AppendChild(r3xElement);
                rootCalibrationCfg.AppendChild(p1yElement);
                rootCalibrationCfg.AppendChild(p2yElement);
                rootCalibrationCfg.AppendChild(p3yElement);
                rootCalibrationCfg.AppendChild(r1yElement);
                rootCalibrationCfg.AppendChild(r2yElement);
                rootCalibrationCfg.AppendChild(r3yElement);
                rootCalibrationCfg.AppendChild(SxElement);
                rootCalibrationCfg.AppendChild(SyElement);
                rootCalibrationCfg.AppendChild(theaElement);
                rootCalibrationCfg.AppendChild(TxElement);
                rootCalibrationCfg.AppendChild(TyElement);
                if (ConfigInformation.GetInstance().tCalCfg.mx != null)
                {
                    XmlElement mx1Element = tXmlDoc.CreateElement("mx1");
                    mx1Element.SetAttribute("mx1", ConfigInformation.GetInstance().tCalCfg.mx[0, 0].ToString());

                    XmlElement mx2Element = tXmlDoc.CreateElement("mx2");
                    mx2Element.SetAttribute("mx2", ConfigInformation.GetInstance().tCalCfg.mx[1, 0].ToString());

                    XmlElement mx3Element = tXmlDoc.CreateElement("mx3");
                    mx3Element.SetAttribute("mx3", ConfigInformation.GetInstance().tCalCfg.mx[2, 0].ToString());

                    XmlElement mx4Element = tXmlDoc.CreateElement("mx4");
                    mx4Element.SetAttribute("mx4", ConfigInformation.GetInstance().tCalCfg.mx[3, 0].ToString());

                    XmlElement mx5Element = tXmlDoc.CreateElement("mx5");
                    mx5Element.SetAttribute("mx5", ConfigInformation.GetInstance().tCalCfg.mx[4, 0].ToString());

                    XmlElement mx6Element = tXmlDoc.CreateElement("mx6");
                    mx6Element.SetAttribute("mx6", ConfigInformation.GetInstance().tCalCfg.mx[5, 0].ToString());
                    rootCalibrationCfg.AppendChild(mx1Element);
                    rootCalibrationCfg.AppendChild(mx2Element);
                    rootCalibrationCfg.AppendChild(mx3Element);
                    rootCalibrationCfg.AppendChild(mx4Element);
                    rootCalibrationCfg.AppendChild(mx5Element);
                    rootCalibrationCfg.AppendChild(mx6Element);
                }
            }


            tXmlDoc.Save(tmpPath);
        }
예제 #13
0
        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                int channeltest;
                if (comboBoxChannel.SelectedIndex == 0)
                {
                    channeltest = 1;
                }
                else
                {
                    channeltest = 3;
                }
                int    rNum, cNum;
                HTuple imgCNum;
                HOperatorSet.ReadImage(out image, (HTuple)fnFileNameList[listBoxFileList.SelectedIndex]);
                basicClass.getImageSize(image, out rNum, out cNum);
                HOperatorSet.CountChannels(image, out imgCNum);
                labelImageInfo.Text = rNum.ToString() + "行 " + cNum.ToString() + "列 " + ((int)imgCNum).ToString() + "通道 ";
                if (rNum == (int)numericUpDownRow.Value && cNum == (int)numericUpDownColumn.Value &&
                    imgCNum == channeltest)
                {
                    double widRat = pictureBoxImage.Width / ((double)cNum);
                    double heiRat = pictureBoxImage.Height / ((double)rNum);
                    resizerate = widRat < heiRat ? widRat : heiRat;
                    if (img != null)
                    {
                        img.Dispose();
                    }
                    basicClass.resizeImage(image, out img, resizerate);
                    basicClass.displayClear(FileInputHWHandle);
                    basicClass.displayhobject(img, FileInputHWHandle);

                    HOperatorSet.CopyImage(image, out UserCode.GetInstance().fileImages);
                    Svision.GetMe().fileNameList.Clear();
                    Svision.GetMe().fileNameList = fnFileNameList;
                    ConfigInformation.GetInstance().tFileCfg.columns = (int)numericUpDownColumn.Value;
                    ConfigInformation.GetInstance().tFileCfg.rows = (int)numericUpDownRow.Value;
                    if (comboBoxChannel.SelectedIndex == 0)
                    {
                        ConfigInformation.GetInstance().tFileCfg.channelNum = 1;
                    }
                    else
                    {
                        ConfigInformation.GetInstance().tFileCfg.channelNum = 3;
                    }
                    Svision.GetMe().fileNumIdx = listBoxFileList.SelectedIndex;
                    Svision.GetMe().textBoxFileNum.Text = (Svision.GetMe().fileNumIdx + 1).ToString();
                    Svision.GetMe().textBoxAllFileNum.Text = ImageNum.ToString();
                    if (Svision.GetMe().checkBoxIsFile.Checked)
                    {
                        Svision.GetMe().oriRowNumber    = ConfigInformation.GetInstance().tFileCfg.rows;
                        Svision.GetMe().oriColumnNumber = ConfigInformation.GetInstance().tFileCfg.columns;
                    }
                    if (image != null)
                    {
                        image.Dispose();
                    }
                    if (img != null)
                    {
                        img.Dispose();
                    }
                    this.Close();
                }
                else
                {
                    if (image != null)
                    {
                        image.Dispose();
                    }
                    if (img != null)
                    {
                        img.Dispose();
                    }
                    throw new Exception("所选择图像参数与当前图像文件参数设置不符!请修改!");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public SystemConfig()
 {
     InitializeComponent();
     this.textBoxSystemCfgBootProgram.Text    = ConfigInformation.GetInstance().tSysCfg.bootPath;
     this.checkBoxSystemCfgEnableBoot.Checked = ConfigInformation.GetInstance().tSysCfg.isBoot;
 }