diff --git a/ISCamRecorder/ISCamera.cs b/ISCamRecorder/ISCamera.cs index 5a851da..95d93da 100644 --- a/ISCamRecorder/ISCamera.cs +++ b/ISCamRecorder/ISCamera.cs @@ -19,7 +19,7 @@ ICImagingControl _Cam; // カメラオブジェクト string _SerialNumber; // シリアル番号 string _CamID; // カメラID - VCDButtonProperty _Trigger; // トリガー設定 + VCDButtonProperty _Trigger; // ソフトウェアトリガー発信オブジェクト FrameRateCounter _Fps = new FrameRateCounter(10); // フレームレート計測 FrameQueueSink _PreviewSink; // プレビューSink FrameQueueSink _RecSink; // 録画Sink @@ -74,12 +74,13 @@ return false; } CameraFPS = _Cam.DeviceFrameRate; + _Cam.DeviceTrigger = false; // 起動時はトリガーOFF + _Trigger = _Cam.VCDPropertyItems.Find( + VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_SoftwareTrigger); // 表示設定 _Cam.LiveDisplayDefault = false; SetDisplaySize(); - _Trigger = _Cam.VCDPropertyItems.Find( - VCDGUIDs.VCDID_TriggerMode, VCDGUIDs.VCDElement_SoftwareTrigger); _Cam.Sink = _PreviewSink; _Cam.LiveStart(); diff --git a/ISCamRecorder/MainForm.Designer.cs b/ISCamRecorder/MainForm.Designer.cs index 75b3a8f..d077b6f 100644 --- a/ISCamRecorder/MainForm.Designer.cs +++ b/ISCamRecorder/MainForm.Designer.cs @@ -29,7 +29,6 @@ System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.BtnSetProperty = new System.Windows.Forms.Button(); - this.ChkTrigger = new System.Windows.Forms.CheckBox(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.TxtCvCamera = new System.Windows.Forms.TextBox(); @@ -48,8 +47,6 @@ this.TxtRight = new System.Windows.Forms.TextBox(); this.icRight = new TIS.Imaging.ICImagingControl(); this.BtnRecodeMovie = new System.Windows.Forms.Button(); - this.TxtTriggerFPS = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); this.BtnSnapImage = new System.Windows.Forms.Button(); this.ChkStartSW = new System.Windows.Forms.CheckBox(); this.label8 = new System.Windows.Forms.Label(); @@ -97,17 +94,6 @@ this.BtnSetProperty.UseVisualStyleBackColor = true; this.BtnSetProperty.Click += new System.EventHandler(this.SetProperty_Click); // - // ChkTrigger - // - this.ChkTrigger.AutoSize = true; - this.ChkTrigger.Location = new System.Drawing.Point(82, 11); - this.ChkTrigger.Name = "ChkTrigger"; - this.ChkTrigger.Size = new System.Drawing.Size(83, 16); - this.ChkTrigger.TabIndex = 6; - this.ChkTrigger.Text = "トリガー使用"; - this.ChkTrigger.UseVisualStyleBackColor = true; - this.ChkTrigger.CheckedChanged += new System.EventHandler(this.ChkTrigger_CheckedChanged); - // // splitContainer1 // this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -404,25 +390,6 @@ this.BtnRecodeMovie.UseVisualStyleBackColor = true; this.BtnRecodeMovie.Click += new System.EventHandler(this.BtnRecodeMovie_Click); // - // TxtTriggerFPS - // - this.TxtTriggerFPS.Location = new System.Drawing.Point(99, 27); - this.TxtTriggerFPS.Name = "TxtTriggerFPS"; - this.TxtTriggerFPS.Size = new System.Drawing.Size(34, 19); - this.TxtTriggerFPS.TabIndex = 16; - this.TxtTriggerFPS.Text = "40.0"; - this.TxtTriggerFPS.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.TxtTriggerFPS.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.NumberKeyOnly); - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(139, 30); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(21, 12); - this.label4.TabIndex = 17; - this.label4.Text = "fps"; - // // BtnSnapImage // this.BtnSnapImage.Location = new System.Drawing.Point(463, 8); @@ -526,11 +493,8 @@ this.Controls.Add(this.label8); this.Controls.Add(this.ChkStartSW); this.Controls.Add(this.BtnSnapImage); - this.Controls.Add(this.label4); - this.Controls.Add(this.TxtTriggerFPS); this.Controls.Add(this.BtnRecodeMovie); this.Controls.Add(this.splitContainer1); - this.Controls.Add(this.ChkTrigger); this.Controls.Add(this.BtnSetProperty); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "MainForm"; @@ -577,7 +541,6 @@ #endregion private System.Windows.Forms.Button BtnSetProperty; - private System.Windows.Forms.CheckBox ChkTrigger; private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.SplitContainer splitContainer2; private System.Windows.Forms.SplitContainer splitContainer3; @@ -592,8 +555,6 @@ private System.Windows.Forms.TextBox TxtFront; private System.Windows.Forms.TextBox TxtRight; private System.Windows.Forms.Button BtnRecodeMovie; - private System.Windows.Forms.TextBox TxtTriggerFPS; - private System.Windows.Forms.Label label4; private System.Windows.Forms.Button BtnSnapImage; private System.Windows.Forms.DataVisualization.Charting.Chart chart1; private System.Windows.Forms.TextBox TxtSensor; diff --git a/ISCamRecorder/MainForm.cs b/ISCamRecorder/MainForm.cs index 681502c..250967f 100644 --- a/ISCamRecorder/MainForm.cs +++ b/ISCamRecorder/MainForm.cs @@ -47,7 +47,6 @@ Task _SerialThread; // シリアル通信スレッド Task _CvCameraThread; // opencvカメラスレッド Task _RecodingThread; // 録画スレッド - float _TriggerFrameRate = 30.0F; // トリガーフレームレート SubjectList _SubjectList; // 非測定者一覧フォーム public Setting Setting { get; private set; } // 設定ダイアログ @@ -109,7 +108,7 @@ swatch.Start(); while (State != STATE.Exit) { - var interval = (long)(1000F / _TriggerFrameRate); + var interval = (long)(1000F / Setting.SWTriggerFPS); while (State != STATE.Exit) { if (swatch.ElapsedMilliseconds >= interval) break; } @@ -158,7 +157,6 @@ TxtRight.Text = $"右方カメラ {_Cameras[3].CameraInfo()}"; TxtSensor.Text = $"逆血センサー {_Sensor.FrameRate:0.0} Hz"; TxtCvCamera.Text = $"追加カメラ {_CvCamera.CameraInfo()}"; - _TriggerFrameRate = float.Parse(TxtTriggerFPS.Text); } } @@ -171,9 +169,14 @@ Setting.TotalConsumedMemoryPerSecond = _Cameras.Select(c => c.ConsumedMemoryPerSecond()).Sum() + _CvCamera.ConsumedMemoryPerSecond(); + var lastTriggerSetting = Setting.SWTrigger; Setting.ShowDialog(); - Debug.WriteLine("end"); + + if (Setting.SWTrigger != lastTriggerSetting) { + _Cameras.ForEach(c => c.SetTriggerMode(Setting.SWTrigger)); + } + //var config =_Cameras[0].SetProperty(); //_Cameras.ForEach(c => c.SetProperty(config)); } @@ -355,15 +358,6 @@ } /// - /// トリガー使用チェック変更時 - /// - /// - /// - private void ChkTrigger_CheckedChanged(object sender, EventArgs e) { - _Cameras.ForEach(c => c.SetTriggerMode(((CheckBox)sender).Checked)); - } - - /// /// SW連動チェック変更 /// /// diff --git a/ISCamRecorder/Setting.Designer.cs b/ISCamRecorder/Setting.Designer.cs index e025f76..8080841 100644 --- a/ISCamRecorder/Setting.Designer.cs +++ b/ISCamRecorder/Setting.Designer.cs @@ -39,6 +39,9 @@ this.TxtRecodingDulation = new System.Windows.Forms.TextBox(); this.LblRecodingMemory = new System.Windows.Forms.Label(); this.LblAvailableMemory = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.TxtTriggerFPS = new System.Windows.Forms.TextBox(); + this.ChkTrigger = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // @@ -60,6 +63,9 @@ // // groupBox1 // + this.groupBox1.Controls.Add(this.label4); + this.groupBox1.Controls.Add(this.TxtTriggerFPS); + this.groupBox1.Controls.Add(this.ChkTrigger); this.groupBox1.Controls.Add(this.LblAvailableMemory); this.groupBox1.Controls.Add(this.LblRecodingMemory); this.groupBox1.Controls.Add(this.label2); @@ -198,6 +204,36 @@ this.LblAvailableMemory.TabIndex = 31; this.LblAvailableMemory.Text = "利用可能メモリ"; // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(163, 156); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(21, 12); + this.label4.TabIndex = 34; + this.label4.Text = "fps"; + // + // TxtTriggerFPS + // + this.TxtTriggerFPS.Enabled = false; + this.TxtTriggerFPS.Location = new System.Drawing.Point(123, 153); + this.TxtTriggerFPS.Name = "TxtTriggerFPS"; + this.TxtTriggerFPS.Size = new System.Drawing.Size(34, 19); + this.TxtTriggerFPS.TabIndex = 33; + this.TxtTriggerFPS.Text = "40.0"; + this.TxtTriggerFPS.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // ChkTrigger + // + this.ChkTrigger.AutoSize = true; + this.ChkTrigger.Location = new System.Drawing.Point(8, 155); + this.ChkTrigger.Name = "ChkTrigger"; + this.ChkTrigger.Size = new System.Drawing.Size(109, 16); + this.ChkTrigger.TabIndex = 32; + this.ChkTrigger.Text = "ソフトウェアトリガー"; + this.ChkTrigger.UseVisualStyleBackColor = true; + this.ChkTrigger.CheckedChanged += new System.EventHandler(this.ChkTrigger_CheckedChanged); + // // Setting // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -237,5 +273,8 @@ private System.Windows.Forms.TextBox TxtRecodingDulation; private System.Windows.Forms.Label LblRecodingMemory; private System.Windows.Forms.Label LblAvailableMemory; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox TxtTriggerFPS; + private System.Windows.Forms.CheckBox ChkTrigger; } } \ No newline at end of file diff --git a/ISCamRecorder/Setting.cs b/ISCamRecorder/Setting.cs index 45b8c87..f493c83 100644 --- a/ISCamRecorder/Setting.cs +++ b/ISCamRecorder/Setting.cs @@ -16,6 +16,8 @@ public string ImageTypeL { get { return ImageType.ToLower(); } } public int MovieRate { get; private set; } public float RecodingLimit { get; private set; } + public bool SWTrigger { get; private set; } + public float SWTriggerFPS { get; private set; } public float TotalConsumedMemoryPerSecond { get; set; } /// @@ -24,6 +26,8 @@ public Setting() { InitializeComponent(); ImageType = "JPG"; + SWTrigger = false; + SWTriggerFPS = 40F; #if DEBUG SaveDir = @"D:\DataDBG"; RecodingLimit = 3F; @@ -45,25 +49,12 @@ CboImageType.Text = ImageType; TxtMovieRate.Text = MovieRate.ToString(); TxtRecodingDulation.Text = RecodingLimit.ToString("0.0"); + ChkTrigger.Checked = SWTrigger; + TxtTriggerFPS.Text = SWTriggerFPS.ToString("0.0"); this.UpdateMemoryInfo(); } /// - /// メモリー情報の更新 - /// - private void UpdateMemoryInfo() { - var info = new Microsoft.VisualBasic.Devices.ComputerInfo(); - ulong bcs = 1024 * 1024; - var availableMemory = (int)(info.AvailablePhysicalMemory / bcs); //利用可能な物理メモリ - LblAvailableMemory.Text = $"利用可能メモリー:{availableMemory.ToString("#,0").PadLeft(7)}MB"; - - var totalConsumedMemory = (int)(TotalConsumedMemoryPerSecond * float.Parse(TxtRecodingDulation.Text)); - LblRecodingMemory.Text = $"最大消費メモリー:{totalConsumedMemory.ToString("#,0").PadLeft(7)}MB"; - if (totalConsumedMemory > availableMemory) LblRecodingMemory.ForeColor = Color.Red; - else LblRecodingMemory.ForeColor = Color.Black; - } - - /// /// 適用時 /// /// @@ -73,6 +64,8 @@ ImageType = CboImageType.Text; MovieRate = int.Parse(TxtMovieRate.Text); RecodingLimit = float.Parse(TxtRecodingDulation.Text); + SWTrigger = ChkTrigger.Checked; + SWTriggerFPS = float.Parse(TxtTriggerFPS.Text); this.Close(); } @@ -110,5 +103,29 @@ private void TxtRecodingDulation_TextChanged(object sender, EventArgs e) { this.UpdateMemoryInfo(); } + + /// + /// メモリー情報の更新 + /// + private void UpdateMemoryInfo() { + var info = new Microsoft.VisualBasic.Devices.ComputerInfo(); + ulong bcs = 1024 * 1024; + var availableMemory = (int)(info.AvailablePhysicalMemory / bcs); //利用可能な物理メモリ + LblAvailableMemory.Text = $"利用可能メモリー:{availableMemory.ToString("#,0").PadLeft(7)}MB"; + + var totalConsumedMemory = (int)(TotalConsumedMemoryPerSecond * float.Parse(TxtRecodingDulation.Text)); + LblRecodingMemory.Text = $"最大消費メモリー:{totalConsumedMemory.ToString("#,0").PadLeft(7)}MB"; + if (totalConsumedMemory > availableMemory) LblRecodingMemory.ForeColor = Color.Red; + else LblRecodingMemory.ForeColor = Color.Black; + } + + /// + /// ソフトウェアトリガー設定変更時 + /// + /// + /// + private void ChkTrigger_CheckedChanged(object sender, EventArgs e) { + TxtTriggerFPS.Enabled = ChkTrigger.Checked; + } } }