diff --git a/ISCamRecorder/ISCamera.cs b/ISCamRecorder/ISCamera.cs index 72ba49d..cc620b8 100644 --- a/ISCamRecorder/ISCamera.cs +++ b/ISCamRecorder/ISCamera.cs @@ -18,6 +18,7 @@ string _SerialNumber; // シリアル番号 VCDButtonProperty _Trigger; // トリガー設定 FrameRateCounter _Fps = new FrameRateCounter(10); // フレームレート計測 + public float FrameRate { get { return _Fps.FrameRate; } } /// /// コンストラクタ diff --git a/ISCamRecorder/MainForm.Designer.cs b/ISCamRecorder/MainForm.Designer.cs index decd744..e02bb7c 100644 --- a/ISCamRecorder/MainForm.Designer.cs +++ b/ISCamRecorder/MainForm.Designer.cs @@ -46,6 +46,8 @@ this.textBox1 = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.BtnRecodeMovie = new System.Windows.Forms.Button(); + this.TxtTriggerFPS = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -83,7 +85,7 @@ // ChkTrigger // this.ChkTrigger.AutoSize = true; - this.ChkTrigger.Location = new System.Drawing.Point(93, 22); + this.ChkTrigger.Location = new System.Drawing.Point(93, 11); this.ChkTrigger.Name = "ChkTrigger"; this.ChkTrigger.Size = new System.Drawing.Size(83, 16); this.ChkTrigger.TabIndex = 6; @@ -347,11 +349,31 @@ this.BtnRecodeMovie.Text = "動画撮影"; this.BtnRecodeMovie.UseVisualStyleBackColor = true; // + // TxtTriggerFPS + // + this.TxtTriggerFPS.Location = new System.Drawing.Point(110, 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; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(150, 30); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(21, 12); + this.label4.TabIndex = 17; + this.label4.Text = "fps"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(892, 555); + this.Controls.Add(this.label4); + this.Controls.Add(this.TxtTriggerFPS); this.Controls.Add(this.BtnRecodeMovie); this.Controls.Add(this.label3); this.Controls.Add(this.textBox1); @@ -423,6 +445,8 @@ private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button BtnRecodeMovie; + private System.Windows.Forms.TextBox TxtTriggerFPS; + private System.Windows.Forms.Label label4; } } diff --git a/ISCamRecorder/MainForm.cs b/ISCamRecorder/MainForm.cs index 8f6bbb5..49edbed 100644 --- a/ISCamRecorder/MainForm.cs +++ b/ISCamRecorder/MainForm.cs @@ -12,9 +12,11 @@ namespace ISCamRecorder { public partial class MainForm : Form { - private System.Threading.Timer _UITimer; + private System.Threading.Timer _UITimer; // UI更新タイマー List _Cameras = new List (); // カメラオブジェクト - //private Stopwatch _Swatch = new Stopwatch(); // 高精度時間計測 + bool _ExitSignal = false; // ソフトウェア終了シグナル + Task _TriggerThread; // トリガースレッド + float _TriggerFrameRate = 30.0F; private ulong _availablePhysicalMemory; //合計物理メモリ /// @@ -32,14 +34,33 @@ private void MainForm_Load(object sender, EventArgs e) { SetTitle(this.Text); + // カメラ設定 _Cameras.Add(new ISCamera(icTop, "9220016")); _Cameras.Add(new ISCamera(icLeft, "9220018")); _Cameras.Add(new ISCamera(icFront, "9220021")); _Cameras.Add(new ISCamera(icRight, "9220025")); - //_Swatch.Start(); - _Cameras.ForEach(c => c.Connect()); + + // タイマー起動 _UITimer = new System.Threading.Timer(UITimerCB, this, 0, 2000); + _TriggerThread = Task.Run(TriggerThread); + } + + /// + /// ソフトウェアトリガー生成スレッド + /// + private void TriggerThread() { + var swatch = new Stopwatch(); + swatch.Start(); + + while (!_ExitSignal) { + var interval = (long)(1000F / _TriggerFrameRate); + while (!_ExitSignal) { + if (swatch.ElapsedMilliseconds >= interval) break; + } + swatch.Restart(); + _Cameras.ForEach(c => c.SWTrigger()); + } } /// @@ -58,13 +79,13 @@ this.Invoke((MethodInvoker)delegate { UpdateForm(); }); return; } - //_Cam.ForEach(c => c.SWTrigger()); TxtTop.Text = $"上方カメラ {_Cameras[0].CameraInfo()}"; TxtLeft.Text = $"左方カメラ {_Cameras[1].CameraInfo()}"; TxtFront.Text = $"前方カメラ {_Cameras[2].CameraInfo()}"; TxtRight.Text = $"右方カメラ {_Cameras[3].CameraInfo()}"; TotalPhysicalMemory(); MemoryToUse(); + _TriggerFrameRate = float.Parse(TxtTriggerFPS.Text); } /// @@ -96,7 +117,9 @@ /// /// private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { + _ExitSignal = true; _UITimer.Dispose(); + _TriggerThread.Wait(); } ///