diff --git a/ISCamRecorder/ISCamRecorder.csproj b/ISCamRecorder/ISCamRecorder.csproj index 87d08bd..7034dd2 100644 --- a/ISCamRecorder/ISCamRecorder.csproj +++ b/ISCamRecorder/ISCamRecorder.csproj @@ -59,6 +59,8 @@ + + diff --git a/ISCamRecorder/MainForm.Designer.cs b/ISCamRecorder/MainForm.Designer.cs index 9420e94..7ccb37e 100644 --- a/ISCamRecorder/MainForm.Designer.cs +++ b/ISCamRecorder/MainForm.Designer.cs @@ -23,6 +23,9 @@ /// コード エディターで変更しないでください。 /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = 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(); @@ -55,6 +58,8 @@ this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.CboImageType = new System.Windows.Forms.ComboBox(); + this.serialPort1 = new System.IO.Ports.SerialPort(this.components); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -64,6 +69,7 @@ this.splitContainer2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit(); this.splitContainer3.Panel1.SuspendLayout(); + this.splitContainer3.Panel2.SuspendLayout(); this.splitContainer3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.icTop)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer4)).BeginInit(); @@ -77,13 +83,14 @@ this.splitContainer5.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.icFront)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.icRight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); this.SuspendLayout(); // // BtnSetProperty // this.BtnSetProperty.Location = new System.Drawing.Point(12, 12); this.BtnSetProperty.Name = "BtnSetProperty"; - this.BtnSetProperty.Size = new System.Drawing.Size(75, 34); + this.BtnSetProperty.Size = new System.Drawing.Size(64, 34); this.BtnSetProperty.TabIndex = 5; this.BtnSetProperty.Text = "プロパティ"; this.BtnSetProperty.UseVisualStyleBackColor = true; @@ -92,7 +99,7 @@ // ChkTrigger // this.ChkTrigger.AutoSize = true; - this.ChkTrigger.Location = new System.Drawing.Point(93, 11); + 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; @@ -143,6 +150,10 @@ // this.splitContainer3.Panel1.Controls.Add(this.TxtTop); this.splitContainer3.Panel1.Controls.Add(this.icTop); + // + // splitContainer3.Panel2 + // + this.splitContainer3.Panel2.Controls.Add(this.chart1); this.splitContainer3.Size = new System.Drawing.Size(592, 248); this.splitContainer3.SplitterDistance = 296; this.splitContainer3.TabIndex = 0; @@ -290,7 +301,7 @@ // // TxtRecodingDulation // - this.TxtRecodingDulation.Location = new System.Drawing.Point(187, 27); + this.TxtRecodingDulation.Location = new System.Drawing.Point(176, 27); this.TxtRecodingDulation.Name = "TxtRecodingDulation"; this.TxtRecodingDulation.Size = new System.Drawing.Size(34, 19); this.TxtRecodingDulation.TabIndex = 8; @@ -301,7 +312,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(185, 12); + this.label1.Location = new System.Drawing.Point(174, 12); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(53, 12); this.label1.TabIndex = 9; @@ -310,7 +321,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(221, 30); + this.label2.Location = new System.Drawing.Point(210, 30); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(17, 12); this.label2.TabIndex = 10; @@ -319,7 +330,7 @@ // LblAvailableMemory // this.LblAvailableMemory.AutoSize = true; - this.LblAvailableMemory.Location = new System.Drawing.Point(258, 12); + this.LblAvailableMemory.Location = new System.Drawing.Point(245, 12); this.LblAvailableMemory.Name = "LblAvailableMemory"; this.LblAvailableMemory.Size = new System.Drawing.Size(101, 12); this.LblAvailableMemory.TabIndex = 11; @@ -328,7 +339,7 @@ // LblRecodingMemory // this.LblRecodingMemory.AutoSize = true; - this.LblRecodingMemory.Location = new System.Drawing.Point(258, 30); + this.LblRecodingMemory.Location = new System.Drawing.Point(245, 30); this.LblRecodingMemory.Name = "LblRecodingMemory"; this.LblRecodingMemory.Size = new System.Drawing.Size(96, 12); this.LblRecodingMemory.TabIndex = 12; @@ -336,7 +347,7 @@ // // TxtOutputDir // - this.TxtOutputDir.Location = new System.Drawing.Point(639, 8); + this.TxtOutputDir.Location = new System.Drawing.Point(610, 8); this.TxtOutputDir.Name = "TxtOutputDir"; this.TxtOutputDir.Size = new System.Drawing.Size(206, 19); this.TxtOutputDir.TabIndex = 13; @@ -345,7 +356,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(584, 12); + this.label3.Location = new System.Drawing.Point(555, 12); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(41, 12); this.label3.TabIndex = 14; @@ -353,7 +364,7 @@ // // BtnRecodeMovie // - this.BtnRecodeMovie.Location = new System.Drawing.Point(422, 12); + this.BtnRecodeMovie.Location = new System.Drawing.Point(393, 12); this.BtnRecodeMovie.Name = "BtnRecodeMovie"; this.BtnRecodeMovie.Size = new System.Drawing.Size(74, 34); this.BtnRecodeMovie.TabIndex = 15; @@ -363,7 +374,7 @@ // // TxtTriggerFPS // - this.TxtTriggerFPS.Location = new System.Drawing.Point(110, 27); + 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; @@ -373,7 +384,7 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(150, 30); + 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; @@ -381,7 +392,7 @@ // // BtnSnapImage // - this.BtnSnapImage.Location = new System.Drawing.Point(502, 12); + this.BtnSnapImage.Location = new System.Drawing.Point(473, 12); this.BtnSnapImage.Name = "BtnSnapImage"; this.BtnSnapImage.Size = new System.Drawing.Size(74, 34); this.BtnSnapImage.TabIndex = 18; @@ -391,7 +402,7 @@ // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(584, 36); + this.label5.Location = new System.Drawing.Point(555, 36); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(56, 12); this.label5.TabIndex = 19; @@ -399,7 +410,7 @@ // // TxtMovieRate // - this.TxtMovieRate.Location = new System.Drawing.Point(639, 33); + this.TxtMovieRate.Location = new System.Drawing.Point(610, 33); this.TxtMovieRate.Name = "TxtMovieRate"; this.TxtMovieRate.Size = new System.Drawing.Size(40, 19); this.TxtMovieRate.TabIndex = 20; @@ -409,7 +420,7 @@ // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(685, 36); + this.label6.Location = new System.Drawing.Point(656, 36); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(29, 12); this.label6.TabIndex = 17; @@ -418,7 +429,7 @@ // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(733, 36); + this.label7.Location = new System.Drawing.Point(704, 36); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(53, 12); this.label7.TabIndex = 19; @@ -431,12 +442,28 @@ "JPG", "BMP", "TIFF"}); - this.CboImageType.Location = new System.Drawing.Point(793, 34); + this.CboImageType.Location = new System.Drawing.Point(764, 34); this.CboImageType.Name = "CboImageType"; this.CboImageType.Size = new System.Drawing.Size(52, 20); this.CboImageType.TabIndex = 21; this.CboImageType.Text = "JPG"; // + // chart1 + // + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + this.chart1.Location = new System.Drawing.Point(3, 3); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series1.Name = "Series1"; + series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time; + series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32; + this.chart1.Series.Add(series1); + this.chart1.Size = new System.Drawing.Size(286, 245); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -476,6 +503,7 @@ this.splitContainer2.ResumeLayout(false); this.splitContainer3.Panel1.ResumeLayout(false); this.splitContainer3.Panel1.PerformLayout(); + this.splitContainer3.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit(); this.splitContainer3.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.icTop)).EndInit(); @@ -493,6 +521,7 @@ this.splitContainer5.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.icFront)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.icRight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -530,6 +559,8 @@ private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.ComboBox CboImageType; + private System.IO.Ports.SerialPort serialPort1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; } } diff --git a/ISCamRecorder/MainForm.cs b/ISCamRecorder/MainForm.cs index 07e8af8..e6f1bf2 100644 --- a/ISCamRecorder/MainForm.cs +++ b/ISCamRecorder/MainForm.cs @@ -11,13 +11,19 @@ using System.Reflection; using System.IO; using NAudio.MediaFoundation; +using System.Management; +using System.IO.Ports; +using System.Windows.Forms.DataVisualization.Charting; namespace ISCamRecorder { public partial class MainForm : Form { + readonly string SERIAL_PORT_NAME = "USB シリアル"; + private System.Threading.Timer _UITimer; // UI更新タイマー List _Cameras = new List (); // カメラオブジェクト bool _ExitSignal = false; // ソフトウェア終了シグナル Task _TriggerThread; // トリガースレッド + Task _SerialThread; // シリアル通信スレッド float _TriggerFrameRate = 30.0F; private ulong _availablePhysicalMemory; //合計物理メモリ @@ -44,9 +50,20 @@ _Cameras.Add(new ISCamera(icRight, "9220025")); _Cameras.ForEach(c => c.Connect()); + // グラフ初期化 + chart1.Series[0].Points.Clear(); + //chart1.ChartAreas.Clear(); + //chart1.Series.Clear(); + //var chartArea = new ChartArea("chartArea"); + //chart1.ChartAreas.Add(chartArea); + //var series = new Series(); + //series.ChartType = SeriesChartType.Line; + //chart1.Series.Add(series); + // タイマー起動 _UITimer = new System.Threading.Timer(UITimerCB, this, 0, 2000); _TriggerThread = Task.Run(TriggerThread); + _SerialThread = Task.Run(SerialThread); } /// @@ -67,6 +84,53 @@ } /// + /// シリアル通信スレッド + /// + private void SerialThread() { + // シリアルポート接続 + var portname = GetSerialPort(); + if (portname.Length < 1) { + MessageBox.Show("シリアルデバイスに接続できません", "Error", + MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + serialPort1.BaudRate = 9600; + serialPort1.Parity = Parity.None; + serialPort1.DataBits = 8; + serialPort1.StopBits = StopBits.One; + serialPort1.Handshake = Handshake.None; + serialPort1.RtsEnable = true; + serialPort1.PortName = portname; + serialPort1.Open(); + Debug.WriteLine(portname); + while (!_ExitSignal) { + var str = serialPort1.ReadLine(); + var val = int.Parse(str); + var dt = DateTime.Now; + AddPoint(dt, val); + } + } + + private void AddPoint(DateTime dt, int value) { + if (this.InvokeRequired) { + this.Invoke((MethodInvoker)delegate { AddPoint(dt, value); }); + return; + } + chart1.Series[0].Points.AddXY(dt, value); + } + + private string GetSerialPort() { + var portname = ""; + var mcW32SerPort = new ManagementClass("Win32_SerialPort"); + foreach (var port in mcW32SerPort.GetInstances()) { + if (port.GetPropertyValue("Caption").ToString().Contains(SERIAL_PORT_NAME)) { + portname = port.GetPropertyValue("DeviceID").ToString(); + } + } + return portname; + } + + /// /// タイマーイベント /// /// @@ -123,6 +187,7 @@ _ExitSignal = true; _UITimer.Dispose(); _TriggerThread.Wait(); + _SerialThread.Wait(); } /// diff --git a/ISCamRecorder/MainForm.resx b/ISCamRecorder/MainForm.resx index 8d6a7ab..1b87d9c 100644 --- a/ISCamRecorder/MainForm.resx +++ b/ISCamRecorder/MainForm.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + diff --git a/PhotoReflectorIF/PhotoReflectorIF.ino b/PhotoReflectorIF/PhotoReflectorIF.ino new file mode 100644 index 0000000..320ae3a --- /dev/null +++ b/PhotoReflectorIF/PhotoReflectorIF.ino @@ -0,0 +1,22 @@ +// フォトリフレクタ入力インターフェース +// 製作者:中口 製作日:2022/6/8 +// (Arduino)Seeeduino XIAO M0+ https://www.switch-science.com/catalog/6335/ +// (Sensor)TPR-105F https://akizukidenshi.com/download/tpr-105f.pdf +// フォトリフレクタ検出値(0-1023)をシリアルポートへ出力 + +// グローバル変数 +const int BAUD_RATE = 9600; // シリアル通信ボーレート +const int ANALOG_PIN = A7; // 入力ピン +const int LOOP_WAIT = 30; // ループ毎のウェイト(ms) + +// 初期化 +void setup() { + Serial.begin(BAUD_RATE); +} + +// メインループ +void loop() { + int val = analogRead(ANALOG_PIN); + Serial.println(val); + delay(LOOP_WAIT); +}