From c3c5cf3e4a28e723bff8364d2572a2066a7b9ee1 Mon Sep 17 00:00:00 2001 From: el124vip124 Date: Thu, 16 Jan 2025 16:34:50 +0800 Subject: [PATCH] =?UTF-8?q?UI=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Camera_connect/IDSCamera.cs | 9 +++-- Camera_connect/Main.Designer.cs | 70 +++++++++++++++++++++++++++------ Camera_connect/Main.cs | 40 ++++++++++++++++--- 3 files changed, 97 insertions(+), 22 deletions(-) diff --git a/Camera_connect/IDSCamera.cs b/Camera_connect/IDSCamera.cs index ec4be33..a666679 100644 --- a/Camera_connect/IDSCamera.cs +++ b/Camera_connect/IDSCamera.cs @@ -14,6 +14,7 @@ namespace Camera_connect { public class IDSCamera { + Device device1; NodeMap nodeMapRemoteDevice1; DataStream dataStream1; @@ -37,10 +38,10 @@ namespace Camera_connect device1 = deviceDescriptor.OpenDevice(DeviceAccessType.Control); nodeMapRemoteDevice1 = device1.RemoteDevice().NodeMaps().First(); - //nodeMapRemoteDevice1.FindNode("Width").SetValue(5472); - //nodeMapRemoteDevice1.FindNode("Height").SetValue(3648); - nodeMapRemoteDevice1.FindNode("Width").SetValue(1920); - nodeMapRemoteDevice1.FindNode("Height").SetValue(1200); + + //----------------------學長原程式需要設定相機的解析度---------------------- + //nodeMapRemoteDevice1.FindNode("Width").SetValue(5472); + //nodeMapRemoteDevice1.FindNode("Height").SetValue(3648); nodeMapRemoteDevice1.FindNode("OffsetX").SetValue(0); nodeMapRemoteDevice1.FindNode("OffsetY").SetValue(0); //nodeMapRemoteDevice1.FindNode("ExposureAuto").SetCurrentEntry("Off"); diff --git a/Camera_connect/Main.Designer.cs b/Camera_connect/Main.Designer.cs index b5b034a..081af3d 100644 --- a/Camera_connect/Main.Designer.cs +++ b/Camera_connect/Main.Designer.cs @@ -33,7 +33,11 @@ bt_KeepShot = new Button(); bt_Stop = new Button(); pictureBox1 = new PictureBox(); - label1 = new Label(); + Label_status = new Label(); + comboBox1 = new ComboBox(); + camera_serialnumber = new TextBox(); + label2 = new Label(); + label3 = new Label(); ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); SuspendLayout(); // @@ -81,25 +85,63 @@ // pictureBox1.Location = new Point(99, 342); pictureBox1.Name = "pictureBox1"; - pictureBox1.Size = new Size(772, 637); + pictureBox1.Size = new Size(1219, 940); pictureBox1.TabIndex = 4; pictureBox1.TabStop = false; // - // label1 + // Label_status // - label1.AutoSize = true; - label1.Location = new Point(99, 171); - label1.Name = "label1"; - label1.Size = new Size(61, 23); - label1.TabIndex = 5; - label1.Text = "label1"; + Label_status.AutoSize = true; + Label_status.Location = new Point(99, 171); + Label_status.Name = "Label_status"; + Label_status.Size = new Size(82, 23); + Label_status.TabIndex = 5; + Label_status.Text = "當前狀態"; + // + // comboBox1 + // + comboBox1.FormattingEnabled = true; + comboBox1.Items.AddRange(new object[] { "Basler", "IDS" }); + comboBox1.Location = new Point(300, 75); + comboBox1.Name = "comboBox1"; + comboBox1.Size = new Size(182, 31); + comboBox1.TabIndex = 6; + // + // camera_serialnumber + // + camera_serialnumber.Location = new Point(1279, 75); + camera_serialnumber.Name = "camera_serialnumber"; + camera_serialnumber.Size = new Size(182, 30); + camera_serialnumber.TabIndex = 7; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(1279, 29); + label2.Name = "label2"; + label2.Size = new Size(75, 23); + label2.TabIndex = 10; + label2.Text = "IDS參數"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(1172, 78); + label3.Name = "label3"; + label3.Size = new Size(82, 23); + label3.TabIndex = 11; + label3.Text = "相機序號"; // // Main // AutoScaleDimensions = new SizeF(11F, 23F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1512, 1078); - Controls.Add(label1); + ClientSize = new Size(1746, 1294); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(camera_serialnumber); + Controls.Add(comboBox1); + Controls.Add(Label_status); Controls.Add(pictureBox1); Controls.Add(bt_Stop); Controls.Add(bt_KeepShot); @@ -119,6 +161,10 @@ private Button bt_KeepShot; private Button bt_Stop; private PictureBox pictureBox1; - private Label label1; + private Label Label_status; + private ComboBox comboBox1; + private TextBox camera_serialnumber; + private Label label2; + private Label label3; } } diff --git a/Camera_connect/Main.cs b/Camera_connect/Main.cs index d25820e..c5c7d94 100644 --- a/Camera_connect/Main.cs +++ b/Camera_connect/Main.cs @@ -23,20 +23,48 @@ namespace Camera_connect { InitializeComponent(); } + //4103372214 - private void bt_connect_Click(object sender, EventArgs e) + private async void bt_connect_Click(object sender, EventArgs e) { - if (IDS_camera.CameraInit("4103372214")) + // ܳsuA + Label_status.Text = "IDSsu..."; + + // ŪΤJ + string IDS_serialnumber = camera_serialnumber.Text; + + // ˬdǦCO_ + if (string.IsNullOrWhiteSpace(IDS_serialnumber)) { - IDS_camera.SetExposureTime(10000); - label1.Text = "IDSsu\"; + Label_status.Text = "пJ۾Ǹ"; + MessageBox.Show("۾ǸରšI", "suT", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; } - else + + try { - label1.Text = "IDSsu"; + // Ұʳsu]BBzHOɭT^ + bool connectionResult = await Task.Run(() => IDS_camera.CameraInit(IDS_serialnumber)); + + if (connectionResult) + { + // ]mnɶ + IDS_camera.SetExposureTime(10000); + Label_status.Text = "IDSsu\"; + } + else + { + Label_status.Text = "IDSsu"; + } + } + catch (Exception ex) + { + Label_status.Text = "su"; + MessageBox.Show($"suɵoͿ~G{ex.Message}", "suT", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void bt_OneShot_Click(object sender, EventArgs e) { try