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)); } }
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(); }
/// <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); }
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"), ""); }
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]); } }
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); }
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); }
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); }
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"); }
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); }
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(); }
/// <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); }
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); } }
/// <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); } }
/// <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); } }
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; } } } } }
public double GetPmtGain(CHAN_ID id) { return(GetPmtChannel(id).Gain); }
public string GetPmtAiChannel(CHAN_ID id) { return(m_pmtAiChannels[(int)id]); }
public API_RETURN_CODE SetPmtAiChannel(CHAN_ID id, string aiChannel) { m_pmtAiChannels[(int)id] = aiChannel; return(API_RETURN_CODE.API_SUCCESS); }
public API_RETURN_CODE SetApdCiSrcPfi(CHAN_ID id, string pfi) { m_apdCiSrcPfis[(int)id] = pfi; return(API_RETURN_CODE.API_SUCCESS); }
public string GetApdCiSrcPfi(CHAN_ID id) { return(m_apdCiSrcPfis[(int)id]); }
public short GetChannelBackgroundNoiseLevel(CHAN_ID id) { return(GetPropChannel(id).BackgroundNoiseLevel); }
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); }
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); }
public Color GetChannelColorReference(CHAN_ID id) { return(GetPropChannel(id).ColorReference); }
public LASER_CHAN_SWITCH GetLaserSwitch(CHAN_ID id) { return(GetLaserChannel(id).Status); }
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); }
public double GetLaserPower(CHAN_ID id) { return(GetLaserChannel(id).Power); }
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); }
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); }