Beispiel #1
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 #2
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 #3
0
        /// <summary>
        /// 配置CI采集任务
        /// </summary>
        /// <returns></returns>
        private API_RETURN_CODE ConfigCiTasks()
        {
            API_RETURN_CODE code = API_RETURN_CODE.API_SUCCESS;

            int channelNum = m_config.GetChannelNum();

            m_ciTasks          = new Task[channelNum];
            m_ciChannelReaders = new CounterSingleChannelReader[channelNum];
            for (int i = 0; i < channelNum; i++)
            {
                CHAN_ID id = (CHAN_ID)i;
                if (m_config.GetLaserSwitch(id) == LASER_CHAN_SWITCH.ON)
                {
                    code = ConfigCiTask(m_sysConfig.GetApdCiChannel(id), m_sysConfig.GetApdCiSrcPfi(id), m_sysConfig.GetApdTriggerInPfi(), ref m_ciTasks[i], ref m_ciChannelReaders[i]);
                    if (code != API_RETURN_CODE.API_SUCCESS)
                    {
                        return(code);
                    }
                }
                else
                {
                    m_ciTasks[i]          = null;
                    m_ciChannelReaders[i] = null;
                }
            }
            return(code);
        }
Beispiel #4
0
        private void tb640Gain_ValueChanged(object sender, EventArgs e)
        {
            CHAN_ID id          = CHAN_ID.WAVELENGTH_640_NM;
            float   configValue = tb640Gain.Value / 10.0f;

            m_config.SetPmtGain(id, configValue);
            UsbDac.SetDacOut((uint)id, UsbDac.ConfigValueToVout(configValue));
            // UsbDac.SetGainCalibration((uint)id, UsbDac.ConfigValueToGain(configValue));
            tbx640Gain.Text = string.Concat(configValue.ToString("F1"), "");
        }
Beispiel #5
0
        public void GenerateColorMapping()
        {
            int channelNum = m_config.GetChannelNum();

            for (int i = 0; i < channelNum; i++)
            {
                CHAN_ID id             = (CHAN_ID)Enum.ToObject(typeof(CHAN_ID), i);
                Color   colorReference = m_config.GetChannelColorReference(id);
                CImage.CreateColorMapping(colorReference, ref m_colorMappingArr[i]);
            }
        }
Beispiel #6
0
 private PmtChannel GetPmtChannel(CHAN_ID id)
 {
     for (int i = 0; i < CHAN_NUM; i++)
     {
         if (m_pmt.Channels[i].Id == id)
         {
             return(m_pmt.Channels[i]);
         }
     }
     return(null);
 }
Beispiel #7
0
 private LaserChannel GetLaserChannel(CHAN_ID id)
 {
     for (int i = 0; i < CHAN_NUM; i++)
     {
         if (m_laser.Channels[i].Id == id)
         {
             return(m_laser.Channels[i]);
         }
     }
     return(null);
 }
Beispiel #8
0
 private PropChannel GetPropChannel(CHAN_ID id)
 {
     for (int i = 0; i < CHAN_NUM; i++)
     {
         if (m_properties.Channels[i].Id == id)
         {
             return(m_properties.Channels[i]);
         }
     }
     return(null);
 }
Beispiel #9
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 #10
0
        public int GetActivatedChannelNum()
        {
            int activatedChannelNum = 0;

            for (int i = 0; i < CHAN_NUM; i++)
            {
                CHAN_ID id = (CHAN_ID)Enum.ToObject(typeof(CHAN_ID), i);
                if (GetLaserSwitch(id) == LASER_CHAN_SWITCH.ON)
                {
                    activatedChannelNum++;
                }
            }
            return(activatedChannelNum);
        }
Beispiel #11
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 #12
0
        /// <summary>
        /// 生成AI物理通道名
        /// </summary>
        /// <returns></returns>
        private string GetAiPhysicalChannelName()
        {
            List <string> activatedChannelNames = new List <string>();
            int           channelNum            = m_config.GetChannelNum();

            for (int i = 0; i < channelNum; i++)
            {
                CHAN_ID id = (CHAN_ID)i;
                if (m_config.GetLaserSwitch(id) == LASER_CHAN_SWITCH.ON)
                {
                    activatedChannelNames.Add(m_sysConfig.GetPmtAiChannel(id));
                }
            }
            string physicalChannelName = string.Join(",", activatedChannelNames.ToArray());

            Logger.Info(string.Format("ai physical channel name: [{0}].", physicalChannelName));
            return(physicalChannelName);
        }
Beispiel #13
0
        private static int GetChannelIndex(CHAN_ID id)
        {
            switch (id)
            {
            case CHAN_ID.WAVELENGTH_405_NM:
                return(2);

            case CHAN_ID.WAVELENGTH_488_NM:
                return(1);

            case CHAN_ID.WAVELENGTH_561_NM:
                return(4);

            case CHAN_ID.WAVELENGTH_640_NM:
                return(3);

            default:
                return(0);
            }
        }
Beispiel #14
0
        /// <summary>
        /// 关闭激光通道
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static API_RETURN_CODE CloseChannel(CHAN_ID id)
        {
            int channel = GetChannelIndex(id);

            try
            {
                if (!LaserLib2_Active(channel, false))
                {
                    Logger.Error(string.Format("Laser close channel[{0}] failed:[LaserLib2_Active][{1}].", id, API_RETURN_CODE.API_FAILED_LASER_CLOSE_CHANNEL_FAILED));
                    return(API_RETURN_CODE.API_FAILED_LASER_CLOSE_CHANNEL_FAILED);
                }
                Logger.Info(string.Format("Laser close channel[{0}] success:[LaserLib2_Active][{1}].", id, API_RETURN_CODE.API_SUCCESS));
                return(API_RETURN_CODE.API_SUCCESS);
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("Laser close channel[{0}] exception: [{1}].", id, e));
                return(API_RETURN_CODE.API_FAILED_LASER_CLOSE_CHANNEL_FAILED);
            }
        }
Beispiel #15
0
        /// <summary>
        /// 设置激光功率
        /// </summary>
        /// <param name="id"></param>
        /// <param name="power"></param>
        /// <returns></returns>
        public static API_RETURN_CODE SetChannelPower(CHAN_ID id, double power)
        {
            int channel     = GetChannelIndex(id);
            int configValue = PowerToConfigValue(power);

            try
            {
                if (!LaserLib2_SetPower(channel, configValue))
                {
                    Logger.Error(string.Format("Laser set channel[{0}] power[{1}] failed:[LaserLib2_SetPower][{2}].", id, power, API_RETURN_CODE.API_FAILED_LASER_SET_POWER_FAILED));
                    return(API_RETURN_CODE.API_FAILED_LASER_SET_POWER_FAILED);
                }
                Logger.Info(string.Format("Laser set channel[{0}] power[{1}] success:[LaserLib2_SetPower][{2}].", id, power, API_RETURN_CODE.API_SUCCESS));
                return(API_RETURN_CODE.API_SUCCESS);
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("Laser set channel[{0}] power[{1}] exception: [{2}].", id, power, e));
                return(API_RETURN_CODE.API_FAILED_LASER_SET_POWER_FAILED);
            }
        }
Beispiel #16
0
 public void Convert()
 {
     for (int i = 0; i < NSamples.GetLength(0); i++)
     {
         short[] channelSample = NSamples[i];
         if (channelSample != null)
         {
             CHAN_ID id         = (CHAN_ID)Enum.ToObject(typeof(CHAN_ID), i);
             short   noiseLevel = Config.GetConfig().GetChannelBackgroundNoiseLevel(id);
             int     len        = channelSample.Length;
             for (int j = 0; j < len; j++)
             {
                 if (channelSample[j] < 0)
                 {
                     channelSample[j] = (short)-channelSample[j];
                 }
                 if (channelSample[j] <= noiseLevel)
                 {
                     channelSample[j] = 0;
                 }
             }
         }
     }
 }
Beispiel #17
0
 public double GetPmtGain(CHAN_ID id)
 {
     return(GetPmtChannel(id).Gain);
 }
Beispiel #18
0
 public string GetPmtAiChannel(CHAN_ID id)
 {
     return(m_pmtAiChannels[(int)id]);
 }
Beispiel #19
0
 public API_RETURN_CODE SetPmtAiChannel(CHAN_ID id, string aiChannel)
 {
     m_pmtAiChannels[(int)id] = aiChannel;
     return(API_RETURN_CODE.API_SUCCESS);
 }
Beispiel #20
0
 public API_RETURN_CODE SetApdCiSrcPfi(CHAN_ID id, string pfi)
 {
     m_apdCiSrcPfis[(int)id] = pfi;
     return(API_RETURN_CODE.API_SUCCESS);
 }
Beispiel #21
0
 public string GetApdCiSrcPfi(CHAN_ID id)
 {
     return(m_apdCiSrcPfis[(int)id]);
 }
Beispiel #22
0
 public short GetChannelBackgroundNoiseLevel(CHAN_ID id)
 {
     return(GetPropChannel(id).BackgroundNoiseLevel);
 }
Beispiel #23
0
 public API_RETURN_CODE SetLaserSwitch(CHAN_ID id, LASER_CHAN_SWITCH status)
 {
     Logger.Info(string.Format("set laser swicth: [id:{0}], [status:{1}].", id, status));
     GetLaserChannel(id).Status = status;
     return(API_RETURN_CODE.API_SUCCESS);
 }
Beispiel #24
0
 public API_RETURN_CODE SetChannelBackgroundNoiseLevel(CHAN_ID id, short noiseLevel)
 {
     Logger.Info(string.Format("set channel background noise level: [id:{0}], [level:{1}].", id, noiseLevel));
     GetPropChannel(id).BackgroundNoiseLevel = noiseLevel;
     return(API_RETURN_CODE.API_SUCCESS);
 }
Beispiel #25
0
 public Color GetChannelColorReference(CHAN_ID id)
 {
     return(GetPropChannel(id).ColorReference);
 }
Beispiel #26
0
 public LASER_CHAN_SWITCH GetLaserSwitch(CHAN_ID id)
 {
     return(GetLaserChannel(id).Status);
 }
Beispiel #27
0
 public API_RETURN_CODE SetLaserPower(CHAN_ID id, double power)
 {
     Logger.Info(string.Format("set laser power: [id:{0}], [power:{1}].", id, power));
     GetLaserChannel(id).Power = power;
     return(API_RETURN_CODE.API_SUCCESS);
 }
Beispiel #28
0
 public double GetLaserPower(CHAN_ID id)
 {
     return(GetLaserChannel(id).Power);
 }
Beispiel #29
0
 public API_RETURN_CODE SetPmtGain(CHAN_ID id, double gain)
 {
     Logger.Info(string.Format("set pmt gain: [id:{0}], [gain:{1}].", id, gain));
     GetPmtChannel(id).Gain = gain;
     return(API_RETURN_CODE.API_SUCCESS);
 }
Beispiel #30
0
 public API_RETURN_CODE SetChannelColorReference(CHAN_ID id, Color colorReference)
 {
     Logger.Info(string.Format("set channel color reference: [id:{0}], [color:{1}].", id, colorReference));
     GetPropChannel(id).ColorReference = colorReference;
     return(API_RETURN_CODE.API_SUCCESS);
 }