diff --git a/TIASshot/Form1.Designer.cs b/TIASshot/Form1.Designer.cs index f7141dc..9a7a4ad 100644 --- a/TIASshot/Form1.Designer.cs +++ b/TIASshot/Form1.Designer.cs @@ -44,6 +44,7 @@ this.txtMultiShotsInterval = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); this.btnOpenDataFolder = new System.Windows.Forms.Button(); + this.btnLightSW = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.picPreview)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picDisplay)).BeginInit(); this.SuspendLayout(); @@ -262,11 +263,23 @@ this.btnOpenDataFolder.UseVisualStyleBackColor = true; this.btnOpenDataFolder.Click += new System.EventHandler(this.btnOpenDataFolder_Click); // + // btnLightSW + // + this.btnLightSW.AllowDrop = true; + this.btnLightSW.Location = new System.Drawing.Point(173, 517); + this.btnLightSW.Name = "btnLightSW"; + this.btnLightSW.Size = new System.Drawing.Size(110, 37); + this.btnLightSW.TabIndex = 21; + this.btnLightSW.Text = "照明 OFF"; + this.btnLightSW.UseVisualStyleBackColor = true; + this.btnLightSW.Click += new System.EventHandler(this.btnLightSW_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(753, 634); + this.Controls.Add(this.btnLightSW); this.Controls.Add(this.btnOpenDataFolder); this.Controls.Add(this.label8); this.Controls.Add(this.txtMultiShotsInterval); @@ -322,6 +335,7 @@ private System.Windows.Forms.TextBox txtMultiShotsInterval; private System.Windows.Forms.Label label8; private System.Windows.Forms.Button btnOpenDataFolder; + private System.Windows.Forms.Button btnLightSW; } } diff --git a/TIASshot/Form1.cs b/TIASshot/Form1.cs index cf1953c..ed7eae3 100644 --- a/TIASshot/Form1.cs +++ b/TIASshot/Form1.cs @@ -19,6 +19,7 @@ public static string APP_NAME = "TIAS Shot"; private Lucam _lucam; private LightSource _light = new LightSource(); + private bool _isLightOn = true; /// /// コンストラクタ @@ -55,7 +56,9 @@ EnableShots(false); _lucam.StartStopPreview(); - _light.Open(); + if (_light.Open()) { + _light.SetLight(); + } } /// @@ -167,5 +170,17 @@ private void btnOpenDataFolder_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start(txtSaveFolder.Text); } + + private void btnLightSW_Click(object sender, EventArgs e) { + if (_isLightOn) { + _light.TurnOff(); + btnLightSW.Text = "照明 ON"; + _isLightOn = false; + } else { + _light.SetLight(); + btnLightSW.Text = "照明 OFF"; + _isLightOn = true; + } + } } } diff --git a/TIASshot/LightSource.cs b/TIASshot/LightSource.cs index 60bb193..927c626 100644 --- a/TIASshot/LightSource.cs +++ b/TIASshot/LightSource.cs @@ -10,11 +10,20 @@ namespace TIASshot { internal class LightSource { SerialPort _serial; + public bool IsOpen { get { return _serial.IsOpen; } } + /// + /// コンストラクタ + /// public LightSource() { _serial = new SerialPort(); } + /// + /// ポートを探す + /// + /// + /// private string FindPort(string deviceName) { var portname = ""; var mcW32SerPort = new ManagementClass("Win32_SerialPort"); @@ -28,13 +37,34 @@ return portname; } + /// + /// 接続 + /// + /// public bool Open() { var portName = FindPort(Config.GetString("LightSourceDevice")); - //if (portName == "") return false; - //_serial.PortName = portName; - //_serial.BaudRate = baudRate; - //_serial.Open(); + if (portName == "") return false; + _serial.PortName = portName; + _serial.BaudRate = Config.GetInt("LSBaudRate"); + _serial.DataBits = 8; + _serial.StopBits = StopBits.One; + _serial.Parity = Parity.None; + _serial.Open(); return true; } + + public void TurnOff() { + byte[] buf = new byte[] { 0x02, 0x44, 0x41, 0x58, 0x32, 0x3A, + 0x44, 0x41, 0x20, 0x30, 0x03, 0x31, 0x45, 0x04 }; + var str = Encoding.ASCII.GetString(buf); + _serial.Write(str); + } + + public void SetLight() { + byte[] buf = new byte[] { 0x02, 0x44, 0x41, 0x58, 0x32, 0x3A, 0x44, + 0x45, 0x46, 0x20, 0x33, 0x30, 0x37, 0x32, 0x03, 0x30, 0x34, 0x04 }; + var str = Encoding.ASCII.GetString(buf); + _serial.Write(str); + } } } diff --git a/TIASshot/config.xml b/TIASshot/config.xml index 92179a8..88c0b5d 100644 --- a/TIASshot/config.xml +++ b/TIASshot/config.xml @@ -26,4 +26,5 @@ conv_srgb_xyz.csv C:\TIAS_Data Silicon Labs CP210x + 38400