AdjustGainControl.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PaintDotNet.Base.SettingModel;
  11. using TUCamera;
  12. using TUCAMAPI;
  13. namespace PaintDotNet.ImageCollect.CameraComponent
  14. {
  15. public partial class AdjustGainControl : UserControl
  16. {
  17. private TUCamera.TUCamera m_camera;
  18. private CameraParamModel m_cameraParamModel;
  19. private bool m_use;
  20. private void InitializeLanguageText()
  21. {
  22. this.groupBox2.Text = PdnResources.GetString("Menu.Gainvalueadjustment.text");
  23. }
  24. public AdjustGainControl(CameraParamModel model, bool use)
  25. {
  26. InitializeComponent();
  27. InitializeLanguageText();
  28. m_use = use;
  29. m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
  30. m_cameraParamModel = model;
  31. InitializeControlData();
  32. if (m_cameraParamModel.parame.ATExposure == 1)
  33. {
  34. trbGain.Enabled = false;
  35. txtGain.Enabled = false;
  36. }
  37. }
  38. public void ReLoad(CameraParamModel model, bool use)
  39. {
  40. m_cameraParamModel = model;
  41. m_use = use;
  42. InitializeControlData();
  43. if (m_cameraParamModel.parame.ATExposure == 1)
  44. {
  45. trbGain.Enabled = false;
  46. txtGain.Enabled = false;
  47. }
  48. }
  49. private void InitializeControlData()
  50. {
  51. if (m_camera.IsOpen())
  52. {
  53. // Get gain range
  54. TUCAM_PROP_ATTR attrProp;
  55. attrProp = m_camera.GetGlobalGainRange();
  56. trbGain.SetRange((int)attrProp.dbValMin, (int)attrProp.dbValMax);
  57. lblGainMin.Text = trbGain.Minimum.ToString();
  58. lblGainMax.Text = trbGain.Maximum.ToString();
  59. }
  60. // gain
  61. int gainValue = m_cameraParamModel.parame.GlobalGain;
  62. if (gainValue >= this.trbGain.Minimum && gainValue <= this.trbGain.Maximum)
  63. {
  64. this.trbGain.Value = gainValue;
  65. }
  66. }
  67. private void trbGain_ValueChanged(object sender, EventArgs e)
  68. {
  69. txtGain.Text = trbGain.Value.ToString();
  70. m_cameraParamModel.parame.GlobalGain = trbGain.Value;
  71. // 设置到相机
  72. if (m_use)
  73. {
  74. m_camera.SetGlobalGain(m_cameraParamModel.parame.GlobalGain); //usec
  75. }
  76. }
  77. private void txtGain_KeyPress(object sender, KeyPressEventArgs e)
  78. {
  79. if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Enter)) // 非数字键, 放弃该输入
  80. {
  81. e.Handled = true;
  82. return;
  83. }
  84. if (e.KeyChar == (char)Keys.Enter)
  85. {
  86. try
  87. {
  88. int trbGainVal = Convert.ToInt32(txtGain.Text);
  89. if (trbGainVal < trbGain.Minimum)
  90. {
  91. trbGainVal = trbGain.Minimum;
  92. }
  93. if (trbGainVal > trbGain.Maximum)
  94. {
  95. trbGainVal = trbGain.Maximum;
  96. }
  97. trbGain.Value = trbGainVal;
  98. }
  99. catch (Exception ex)
  100. {
  101. MessageBox.Show(ex.Message);
  102. }
  103. }
  104. }
  105. }
  106. }