This commit is contained in:
el124vip124 2025-01-16 16:34:50 +08:00
parent a2988b17ee
commit c3c5cf3e4a
3 changed files with 97 additions and 22 deletions

View File

@ -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<IntegerNode>("Width").SetValue(5472);
//nodeMapRemoteDevice1.FindNode<IntegerNode>("Height").SetValue(3648);
nodeMapRemoteDevice1.FindNode<IntegerNode>("Width").SetValue(1920);
nodeMapRemoteDevice1.FindNode<IntegerNode>("Height").SetValue(1200);
nodeMapRemoteDevice1.FindNode<IntegerNode>("OffsetX").SetValue(0);
nodeMapRemoteDevice1.FindNode<IntegerNode>("OffsetY").SetValue(0);
//nodeMapRemoteDevice1.FindNode<EnumerationNode>("ExposureAuto").SetCurrentEntry("Off");

View File

@ -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;
}
}

View File

@ -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"))
// 顯示連線狀態
Label_status.Text = "IDS連線中...";
// 讀取用戶輸入
string IDS_serialnumber = camera_serialnumber.Text;
// 檢查序列號是否為空
if (string.IsNullOrWhiteSpace(IDS_serialnumber))
{
IDS_camera.SetExposureTime(10000);
label1.Text = "IDS連線成功";
Label_status.Text = "請輸入相機序號";
MessageBox.Show("相機序號不能為空!", "連線資訊", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
try
{
label1.Text = "IDS連線失敗";
// 啟動連線(異步處理以保持界面響應)
bool connectionResult = await Task.Run(() => IDS_camera.CameraInit(IDS_serialnumber));
if (connectionResult)
{
// 設置曝光時間
IDS_camera.SetExposureTime(10000);
Label_status.Text = "IDS連線成功";
}
else
{
Label_status.Text = "IDS連線失敗";
}
}
catch (Exception ex)
{
Label_status.Text = "連線失敗";
MessageBox.Show($"連線時發生錯誤:{ex.Message}", "連線資訊", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void bt_OneShot_Click(object sender, EventArgs e)
{
try