Beispiel #1
0
 private void UpdateControlers()
 {
     // menu
     cbxSelectLaser.Enabled  = LaserDevice.IsConnected() ? false : true;
     btnLaserConnect.Enabled = LaserDevice.IsConnected() ? false : true;
     btnLaserRelease.Enabled = LaserDevice.IsConnected() ? true : false;
 }
Beispiel #2
0
 private void chbx488_CheckedChanged(object sender, EventArgs e)
 {
     if (LaserDevice.IsConnected())
     {
         LaserDevice.OpenChannel(CHAN_ID.WAVELENGTH_488_NM);
     }
 }
Beispiel #3
0
        private void btnLaserRelease_Click(object sender, EventArgs e)
        {
            if (LaserDevice.IsConnected())
            {
                for (int i = 0; i < m_config.GetChannelNum(); i++)
                {
                    CHAN_ID id = (CHAN_ID)Enum.ToObject(typeof(CHAN_ID), i);
                    if (m_config.GetLaserSwitch(id) == LASER_CHAN_SWITCH.ON)
                    {
                        LaserDevice.CloseChannel(id);
                        m_config.SetLaserSwitch(id, LASER_CHAN_SWITCH.OFF);
                    }
                }
            }

            API_RETURN_CODE code = LaserDevice.Release();

            if (code != API_RETURN_CODE.API_SUCCESS)
            {
                MessageBox.Show(string.Format("断开激光器连接失败,失败码: [0x{0}][{1}].", ((int)code).ToString("X"), code));
            }
            else
            {
                m_config.SetLaserPortName(null);
            }
            UpdateControlers();
        }
Beispiel #4
0
        private void ConfigLaserDevice()
        {
            string          portName = cbxSelectLaser.SelectedItem.ToString();
            API_RETURN_CODE code     = LaserDevice.Connect(portName);

            if (code != API_RETURN_CODE.API_SUCCESS)
            {
                MessageBox.Show(string.Format("连接激光器端口[{0}]失败,请检查接线是否正常,端口号是否正确。", portName));
            }

            m_config.SetLaserPortName(portName);
            for (int i = 0; i < m_config.GetChannelNum(); i++)
            {
                CHAN_ID id = (CHAN_ID)i;
                if (m_config.GetLaserSwitch(id) != LASER_CHAN_SWITCH.ON)
                {
                    continue;
                }

                if (LaserDevice.OpenChannel(id) != API_RETURN_CODE.API_SUCCESS)
                {
                    m_config.SetLaserSwitch(id, LASER_CHAN_SWITCH.OFF);
                    continue;
                }

                LaserDevice.SetChannelPower(id, (float)m_config.GetLaserPower(id));
            }
        }
Beispiel #5
0
        private void btnLaserRelease_Click(object sender, EventArgs e)
        {
            API_RETURN_CODE code = LaserDevice.Release();

            if (code != API_RETURN_CODE.API_SUCCESS)
            {
                MessageBox.Show(string.Format("断开激光器连接失败,失败码: [0x{0}][{1}].", ((int)code).ToString("X"), code));
            }
        }
Beispiel #6
0
        private void btnLaserConnect_Click(object sender, EventArgs e)
        {
            string          portName = cbxLaser.SelectedItem.ToString();
            API_RETURN_CODE code     = LaserDevice.Connect(portName);

            if (code != API_RETURN_CODE.API_SUCCESS)
            {
                MessageBox.Show(string.Format("连接激光器失败,失败码: [0x{0}][{1}].", ((int)code).ToString("X"), code));
            }
        }
Beispiel #7
0
        private void tb640Power_ValueChanged(object sender, EventArgs e)
        {
            CHAN_ID id    = CHAN_ID.WAVELENGTH_640_NM;
            double  power = LaserDevice.ConfigValueToPower(tb640Power.Value);

            m_config.SetLaserPower(id, power);
            if (LaserDevice.IsConnected())
            {
                LaserDevice.SetChannelPower(id, power);
            }
            tbx640Power.Text = power.ToString("F2");
        }
Beispiel #8
0
 private void chbx405_CheckedChanged(object sender, EventArgs e)
 {
     if (LaserDevice.IsConnected())
     {
         if (chbx405.Checked)
         {
             LaserDevice.OpenChannel(CHAN_ID.WAVELENGTH_405_NM);
         }
         else
         {
             LaserDevice.CloseChannel(CHAN_ID.WAVELENGTH_405_NM);
         }
     }
 }
Beispiel #9
0
 private void ReleaseLaserDevice()
 {
     if (LaserDevice.IsConnected())
     {
         for (int i = 0; i < m_config.GetChannelNum(); i++)
         {
             CHAN_ID id = (CHAN_ID)Enum.ToObject(typeof(CHAN_ID), i);
             if (m_config.GetLaserSwitch(id) == LASER_CHAN_SWITCH.ON)
             {
                 LaserDevice.CloseChannel(id);
                 m_config.SetLaserSwitch(id, LASER_CHAN_SWITCH.OFF);
             }
         }
     }
     LaserDevice.Release();
 }
Beispiel #10
0
        private void InitControlers()
        {
            // 扫描模式
            rbtnGalv.Checked         = m_config.GetScanMode() == SCAN_MODE.GALVANOMETER ? true : false;
            rbtnRes.Checked          = m_config.GetScanMode() == SCAN_MODE.GALVANOMETER ? false : true;
            rbtnGalv.CheckedChanged += rbtnGalv_CheckedChanged;

            // 扫描策略
            cbxScanStrategy.DataSource            = scanStrategyDict.ToList <KeyValuePair <SCAN_STRATEGY, string> >();
            cbxScanStrategy.DisplayMember         = "Value";
            cbxScanStrategy.ValueMember           = "Key";
            cbxScanStrategy.SelectedIndex         = cbxScanStrategy.FindString(scanStrategyDict[m_config.GetScanStrategy()]);
            cbxScanStrategy.SelectedIndexChanged += cbxScanStrategy_SelectedIndexChanged;

            // 双向扫描补偿
            nudScanPixelOffset.Maximum = m_config.GetScanPixelCompensation() / 2;
            nudScanPixelOffset.Minimum = -m_config.GetScanPixelCompensation() / 2;
            nudScanPixelOffset.Value   = m_config.GetScanPixelOffset();
            // nudScanPixelOffset.Visible = m_config.GetScanStrategy() == SCAN_STRATEGY.Z_BIDIRECTION ? true : false;

            nudScanPixelCali.Maximum = m_config.GetScanPixelCompensation() / 2;
            nudScanPixelCali.Minimum = -m_config.GetScanPixelCompensation() / 2;
            nudScanPixelCali.Value   = m_config.GetScanPixelCalibration();
            nudScanPixelCali.Visible = m_config.GetScanStrategy() == SCAN_STRATEGY.Z_BIDIRECTION ? true : false;

            // 扫描采集模式
            cbxAcquisitionMode.DataSource            = scanAcquisitionModeDict.ToList <KeyValuePair <SCAN_ACQUISITION_MODE, string> >();
            cbxAcquisitionMode.DisplayMember         = "Value";
            cbxAcquisitionMode.ValueMember           = "Key";
            cbxAcquisitionMode.SelectedIndex         = cbxAcquisitionMode.FindString(scanAcquisitionModeDict[m_config.GetScanAcquisitionMode()]);
            cbxAcquisitionMode.SelectedIndexChanged += cbxAcquisitionMode_SelectedIndexChanged;

            // 扫描采集模式数量
            cbxAcquisitionModeNum.DataSource    = new int[] { 2, 4, 8, 16 };
            cbxAcquisitionModeNum.SelectedIndex = cbxAcquisitionModeNum.FindString(m_config.GetScanAcquisitionModeNum().ToString());

            // 扫描像素
            cbxScanPixels.DataSource            = scanPixelsDict.ToList <KeyValuePair <int, string> >();
            cbxScanPixels.DisplayMember         = "Value";
            cbxScanPixels.ValueMember           = "Key";
            cbxScanPixels.SelectedIndex         = cbxScanPixels.FindString(scanPixelsDict[m_config.GetScanXPoints()]);
            cbxScanPixels.SelectedIndexChanged += cbxScanPixels_SelectedIndexChanged;

            // 振镜系统
            rbtnThree.Checked       = m_config.GetScanMirrorNum() == SCAN_MIRROR_NUM.THREEE ? true : false;
            rbtnTwo.Checked         = m_config.GetScanMirrorNum() == SCAN_MIRROR_NUM.THREEE ? false : true;
            rbtnTwo.CheckedChanged += rbtnTwo_CheckedChanged;

            // 停留时间
            cbxDwellTime.DataSource            = new string[] { "0.5", "1.0", "2.0", "4.0", "6.0", "8.0", "10.0", "12.0", "14.0", "16.0", "18.0", "20.0" };
            cbxDwellTime.SelectedIndex         = cbxDwellTime.FindString(m_config.GetScanDwellTime().ToString("F1"));
            cbxDwellTime.SelectedIndexChanged += cbxDwellTime_SelectedIndexChanged;

            // 激光[通道]开关状态/功率/增益
            chbx405.Checked = m_config.GetLaserSwitch(CHAN_ID.WAVELENGTH_405_NM) == LASER_CHAN_SWITCH.ON ? true : false;
            chbx488.Checked = m_config.GetLaserSwitch(CHAN_ID.WAVELENGTH_488_NM) == LASER_CHAN_SWITCH.ON ? true : false;
            chbx561.Checked = m_config.GetLaserSwitch(CHAN_ID.WAVELENGTH_561_NM) == LASER_CHAN_SWITCH.ON ? true : false;
            chbx640.Checked = m_config.GetLaserSwitch(CHAN_ID.WAVELENGTH_640_NM) == LASER_CHAN_SWITCH.ON ? true : false;

            tb405Power.Value = LaserDevice.PowerToConfigValue(m_config.GetLaserPower(CHAN_ID.WAVELENGTH_405_NM));
            tb488Power.Value = LaserDevice.PowerToConfigValue(m_config.GetLaserPower(CHAN_ID.WAVELENGTH_488_NM));
            tb561Power.Value = LaserDevice.PowerToConfigValue(m_config.GetLaserPower(CHAN_ID.WAVELENGTH_561_NM));
            tb640Power.Value = LaserDevice.PowerToConfigValue(m_config.GetLaserPower(CHAN_ID.WAVELENGTH_640_NM));

            tbx405Power.Text = m_config.GetLaserPower(CHAN_ID.WAVELENGTH_405_NM).ToString("F2");
            tbx488Power.Text = m_config.GetLaserPower(CHAN_ID.WAVELENGTH_488_NM).ToString("F2");
            tbx561Power.Text = m_config.GetLaserPower(CHAN_ID.WAVELENGTH_561_NM).ToString("F2");
            tbx640Power.Text = m_config.GetLaserPower(CHAN_ID.WAVELENGTH_640_NM).ToString("F2");

            tb405Gain.Value = (int)m_config.GetPmtGain(CHAN_ID.WAVELENGTH_405_NM) * 10;
            tb488Gain.Value = (int)m_config.GetPmtGain(CHAN_ID.WAVELENGTH_488_NM) * 10;
            tb561Gain.Value = (int)m_config.GetPmtGain(CHAN_ID.WAVELENGTH_561_NM) * 10;
            tb640Gain.Value = (int)m_config.GetPmtGain(CHAN_ID.WAVELENGTH_640_NM) * 10;

            tbx405Gain.Text = string.Concat(m_config.GetPmtGain(CHAN_ID.WAVELENGTH_405_NM).ToString("F1"), "");
            tbx488Gain.Text = string.Concat(m_config.GetPmtGain(CHAN_ID.WAVELENGTH_488_NM).ToString("F1"), "");
            tbx561Gain.Text = string.Concat(m_config.GetPmtGain(CHAN_ID.WAVELENGTH_561_NM).ToString("F1"), "");
            tbx640Gain.Text = string.Concat(m_config.GetPmtGain(CHAN_ID.WAVELENGTH_640_NM).ToString("F1"), "");
        }
Beispiel #11
0
        private void UpdateLaserSwitch(CheckBox chbx, CHAN_ID id)
        {
            LASER_CHAN_SWITCH status = chbx.Checked ? LASER_CHAN_SWITCH.ON : LASER_CHAN_SWITCH.OFF;

            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

            // if task is not running, just update config
            if (m_scheduler.TaskScanning() == false)
            {
                chbx.Checked = !chbx.Checked;
                status       = chbx.Checked ? LASER_CHAN_SWITCH.ON : LASER_CHAN_SWITCH.OFF;
                m_config.SetLaserSwitch(id, status);

                if (LaserDevice.IsConnected())
                {
                    if (status == LASER_CHAN_SWITCH.ON)
                    {
                        LaserDevice.OpenChannel(id);
                        LaserDevice.SetChannelPower(id, m_config.GetLaserPower(id));
                    }
                    else
                    {
                        LaserDevice.CloseChannel(id);
                    }
                }

                this.Cursor = System.Windows.Forms.Cursors.Default;
                return;
            }

            // task is already running
            if (status == LASER_CHAN_SWITCH.OFF)                         // 激光当前是OFF状态
            {
                m_scheduler.StopScanTask(m_scheduler.GetScanningTask()); // 先停止扫描

                chbx.Checked = true;                                     // 再更新配置,并打开激光,设置激光功率
                m_config.SetLaserSwitch(id, LASER_CHAN_SWITCH.ON);
                if (LaserDevice.IsConnected())
                {
                    LaserDevice.OpenChannel(id);
                    LaserDevice.SetChannelPower(id, m_config.GetLaserPower(id));
                }

                m_scheduler.CreateScanTask(0, "实时扫描", out ScanTask scanTask);   // 创建Task,并启动
                API_RETURN_CODE code = m_scheduler.StartScanTask(scanTask);

                this.Cursor = System.Windows.Forms.Cursors.Default;

                if (code != API_RETURN_CODE.API_SUCCESS)
                {
                    MessageBox.Show(string.Format("启动扫描任务失败,失败码: [0x{0}][{1}].", ((int)code).ToString("X"), code));
                }
            }
            else
            {
                // 激光当前是ON状态
                if (m_config.GetActivatedChannelNum() == 1)     // 该路激光是扫描状态下唯一开启的激光
                {
                    this.Cursor = System.Windows.Forms.Cursors.Default;
                    return;                                     // 作为扫描状态下唯一开启的激光,不允许关闭,直接返回
                }
                else
                {
                    m_scheduler.StopScanTask(m_scheduler.GetScanningTask());    // 先停止扫描

                    chbx.Checked = false;                                       // 再更新配置,并关闭激光
                    m_config.SetLaserSwitch(id, LASER_CHAN_SWITCH.OFF);
                    if (LaserDevice.IsConnected())
                    {
                        LaserDevice.CloseChannel(id);
                    }

                    m_scheduler.CreateScanTask(0, "实时扫描", out ScanTask scanTask);   // 创建Task,并启动
                    API_RETURN_CODE code = m_scheduler.StartScanTask(scanTask);

                    this.Cursor = System.Windows.Forms.Cursors.Default;

                    if (code != API_RETURN_CODE.API_SUCCESS)
                    {
                        MessageBox.Show(string.Format("启动扫描任务失败,失败码: [0x{0}][{1}].", ((int)code).ToString("X"), code));
                    }
                }
            }
        }