From 261eddd3503ca7286ded6bb2ce384b5d92db0565 Mon Sep 17 00:00:00 2001 From: JEFF Date: Sat, 18 Jan 2025 14:03:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=B0=88=E6=A1=88=E6=AA=94?= =?UTF-8?q?=E6=A1=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WindowsFormsApp1.sln | 25 ++ WindowsFormsApp1/App.config | 6 + WindowsFormsApp1/Basler.cs | 299 ++++++++++++++++++ WindowsFormsApp1/Form1.Designer.cs | 261 +++++++++++++++ WindowsFormsApp1/Form1.cs | 140 ++++++++ WindowsFormsApp1/Form1.resx | 120 +++++++ WindowsFormsApp1/Program.cs | 22 ++ WindowsFormsApp1/Properties/AssemblyInfo.cs | 36 +++ .../Properties/Resources.Designer.cs | 71 +++++ WindowsFormsApp1/Properties/Resources.resx | 117 +++++++ .../Properties/Settings.Designer.cs | 30 ++ WindowsFormsApp1/Properties/Settings.settings | 7 + WindowsFormsApp1/WindowsFormsApp1.csproj | 88 ++++++ 13 files changed, 1222 insertions(+) create mode 100644 WindowsFormsApp1.sln create mode 100644 WindowsFormsApp1/App.config create mode 100644 WindowsFormsApp1/Basler.cs create mode 100644 WindowsFormsApp1/Form1.Designer.cs create mode 100644 WindowsFormsApp1/Form1.cs create mode 100644 WindowsFormsApp1/Form1.resx create mode 100644 WindowsFormsApp1/Program.cs create mode 100644 WindowsFormsApp1/Properties/AssemblyInfo.cs create mode 100644 WindowsFormsApp1/Properties/Resources.Designer.cs create mode 100644 WindowsFormsApp1/Properties/Resources.resx create mode 100644 WindowsFormsApp1/Properties/Settings.Designer.cs create mode 100644 WindowsFormsApp1/Properties/Settings.settings create mode 100644 WindowsFormsApp1/WindowsFormsApp1.csproj diff --git a/WindowsFormsApp1.sln b/WindowsFormsApp1.sln new file mode 100644 index 0000000..b393917 --- /dev/null +++ b/WindowsFormsApp1.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34916.146 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsFormsApp1", "WindowsFormsApp1\WindowsFormsApp1.csproj", "{9126E2B4-E759-4070-BEC2-E81E8E3DC6AA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9126E2B4-E759-4070-BEC2-E81E8E3DC6AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9126E2B4-E759-4070-BEC2-E81E8E3DC6AA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9126E2B4-E759-4070-BEC2-E81E8E3DC6AA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9126E2B4-E759-4070-BEC2-E81E8E3DC6AA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9F9BD2E3-07E9-4EBE-AAD0-7D84442D1888} + EndGlobalSection +EndGlobal diff --git a/WindowsFormsApp1/App.config b/WindowsFormsApp1/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/WindowsFormsApp1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/WindowsFormsApp1/Basler.cs b/WindowsFormsApp1/Basler.cs new file mode 100644 index 0000000..1f35215 --- /dev/null +++ b/WindowsFormsApp1/Basler.cs @@ -0,0 +1,299 @@ +using System; +using System.Collections.Generic; +using System.Drawing.Imaging; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Basler.Pylon; +using System.Windows.Forms; +using System.Diagnostics; +using System.Threading; + +namespace WindowsFormsApp1 +{ + public class Basler + { + private readonly Form1 form; + public Basler(Form1 form) + { + + this.form = form; + + } + //連接相機各數 + public int CameraNumber = CameraFinder.Enumerate().Count; + // 共享的鎖 + private readonly object lockObject = new object(); + //委託+事件=回調函數,用於傳遞相機抓取的圖像 + public delegate void CameraImage(Bitmap bmp, int cameraIndex); + public event CameraImage CameraImageEvent; + + //委託+事件=回調函數,用於傳遞相機抓取的圖像 + //public delegate void CameraImage1(Bitmap bmp1); + //public event CameraImage1 CameraImageEvent1; + + + // 創建一個列表來儲存所有的相機 + List allCameras = new List(); + //Basler裡將相機採集到的圖像轉換成位圖 + PixelDataConverter pxConvert = new PixelDataConverter(); + + //控制相機採集圖片的過程! + public bool Graber; + public bool freed; + public bool trigger; + //第一步初始化相機 所用的cameras里的事件然后绑定自己寫好的事件 + public void CameraInit() + { + // 獲取所有可用相機的列表 + List allCameraInfos = CameraFinder.Enumerate(); + // 創建一個字典來儲存每個相機的識別碼和相機物件 + Dictionary cameras = new Dictionary(); + foreach (ICameraInfo cameraInfo in allCameraInfos) + { + // 創建一個新的相機物件 + Camera camera0 = new Camera(cameraInfo); + + // 獲取相機的識別碼 + string id = camera0.CameraInfo[CameraInfoKey.SerialNumber]; + Console.WriteLine(id); + // 將相機物件儲存到字典中 + cameras[id] = camera0; + } + Graber = true; + freed = true; + //相當於初始化了一下相機的動態鏈庫 可以調用Camera裡面的東西 + // 清空 allCameras 列表 + allCameras.Clear(); + // 將字典中的所有相機添加到列表中 + foreach (string id in cameras.Keys) + { + allCameras.Add(cameras[id]); + } + // 為每個相機設定事件處理程序 + for (int i = 0; i < allCameras.Count; i++) + { + //自由連接模式 + //當連接到像機自動適應此配置 + //打开後,添加到Basler.Pylon.ICamera中。 + allCameras[i].CameraOpened += Configuration.AcquireContinuous; + //抓取开始事件 + allCameras[i].StreamGrabber.GrabStarted += StreamGrabber_GrabStarted; + //抓取圖片事件 + //allCameras[i].StreamGrabber.ImageGrabbed += (sender, e) => StreamGrabber_ImageGrabbed(sender, e, i); + //打开相機 + allCameras[i].Open(); + } + + + } + /// + /// 斷開連接 + /// + public void Close() + { + for (int i = 0; i < allCameras.Count; i++) + { + //停止連接 + allCameras[i].StreamGrabber.Stop(); + } + //釋放相機資源 + DestroyCamera(); + } + + /// + /// 擷取圖片 + /// + /// + /// + // 創建一個Bitmap類型的陣列來存儲影像 + private readonly Bitmap[] images; + // 定義一個可以存放 IGrabResult 物件的陣列 + private readonly IGrabResult[] grabResults; + + + + private void StreamGrabber_ImageGrabbed(object sender, ImageGrabbedEventArgs e, int cameraIndex) + { + + lock (lockObject) + { + IGrabResult grabResult = e.GrabResult; + if (grabResult.IsValid && Graber) + { + //委托就用到了! + CameraImageEvent(GrabResult2Bmp(grabResult), cameraIndex); + } + } + } + + //private void StreamGrabber_ImageGrabbed1(object sender, ImageGrabbedEventArgs e) + //{ + // lock (lockObject) + // { + // IGrabResult grabResult1 = e.GrabResult; + // if (grabResult1.IsValid && Graber) + // { + // // 將 IGrabResult 物件存入陣列 + // grabResults[1] = grabResult1; + // // 在需要時轉換為 Bitmap 物件 + // images[1] = GrabResult2Bmp(grabResults[1]); + // //委托就用到了! + // CameraImageEvent1(images[1]); + // } + // } + //} + + + /// + /// 開始擷取 + /// + /// + /// + private void StreamGrabber_GrabStarted(object sender, EventArgs e) + { + Graber = true; + + } + + /// + /// 釋放相機 + /// + public void DestroyCamera() + { + if (freed == true) + { + for (int i = 0; i < allCameras.Count; i++) + { + allCameras[i].Close(); + allCameras[i].Dispose(); + } + freed = false; + Graber = false; + trigger = false; + MessageBox.Show("相機已斷開連接"); + } + else + { + return; + } + } + + /// + /// 將相機圖相轉成Bitmap + /// + /// + /// + + Bitmap GrabResult2Bmp(IGrabResult grabResult) + { + // PixelFormat format:新的像素格式 System.Drawing.Bitmap。 这必须指定一个值,开头 Format。(参1:图宽,参2:图高,参3:像素格式) + Bitmap b = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format32bppArgb); + //BitmapData:指定位图像的属性 + BitmapData bitmapData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, b.PixelFormat); + //PixelType.BGRA8packed:抓取结果返回像素类型,由图像处理支持类使用 + pxConvert.OutputPixelFormat = PixelType.BGRA8packed; + IntPtr bmpIntpr = bitmapData.Scan0; + pxConvert.Convert(bmpIntpr, bitmapData.Stride * b.Height, grabResult); + b.UnlockBits(bitmapData); + return b; + } + public void judge(int i) + { + if (trigger == false) + { + trigger = true; + allCameras[i].StreamGrabber.ImageGrabbed += (sender, e) => StreamGrabber_ImageGrabbed(sender, e, i); + } + else + { + return; + } + } + + + public void OneShot(int i) + { + + judge(i); + + if (Graber == true) + { + if (i + /// 設計工具所需的變數。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清除任何使用中的資源。 + /// + /// 如果應該處置受控資源則為 true,否則為 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form 設計工具產生的程式碼 + + /// + /// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器修改 + /// 這個方法的內容。 + /// + private void InitializeComponent() + { + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.button6 = new System.Windows.Forms.Button(); + this.button7 = new System.Windows.Forms.Button(); + this.button8 = new System.Windows.Forms.Button(); + this.pictureBox3 = new System.Windows.Forms.PictureBox(); + this.pictureBox4 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(257, 139); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(405, 297); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 1; + this.pictureBox1.TabStop = false; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(334, 101); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(103, 32); + this.button2.TabIndex = 2; + this.button2.Text = "拍一張照"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Enabled = false; + this.button3.Location = new System.Drawing.Point(566, 101); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(104, 30); + this.button3.TabIndex = 3; + this.button3.Text = "停止"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(447, 101); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(113, 30); + this.button4.TabIndex = 4; + this.button4.Text = "連續拍"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(230, 15); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(98, 47); + this.button1.TabIndex = 5; + this.button1.Text = "斷開連接"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(12, 12); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(98, 50); + this.button5.TabIndex = 6; + this.button5.Text = "相機連接"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(117, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(65, 12); + this.label1.TabIndex = 7; + this.label1.Text = "相機連接數"; + // + // textBox1 + // + this.textBox1.Enabled = false; + this.textBox1.Location = new System.Drawing.Point(116, 40); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(100, 22); + this.textBox1.TabIndex = 8; + // + // pictureBox2 + // + this.pictureBox2.Location = new System.Drawing.Point(697, 139); + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.Size = new System.Drawing.Size(405, 297); + this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox2.TabIndex = 9; + this.pictureBox2.TabStop = false; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("標楷體", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label2.Location = new System.Drawing.Point(232, 101); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(96, 27); + this.label2.TabIndex = 10; + this.label2.Text = "相機一"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("標楷體", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136))); + this.label3.Location = new System.Drawing.Point(692, 103); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(96, 27); + this.label3.TabIndex = 11; + this.label3.Text = "相機二"; + // + // button6 + // + this.button6.Location = new System.Drawing.Point(907, 101); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(115, 23); + this.button6.TabIndex = 14; + this.button6.Text = "連續拍"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.button6_Click); + // + // button7 + // + this.button7.Enabled = false; + this.button7.Location = new System.Drawing.Point(1026, 101); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(106, 23); + this.button7.TabIndex = 13; + this.button7.Text = "停止"; + this.button7.UseVisualStyleBackColor = true; + this.button7.Click += new System.EventHandler(this.button7_Click); + // + // button8 + // + this.button8.Location = new System.Drawing.Point(794, 101); + this.button8.Name = "button8"; + this.button8.Size = new System.Drawing.Size(105, 25); + this.button8.TabIndex = 12; + this.button8.Text = "拍一張照"; + this.button8.UseVisualStyleBackColor = true; + this.button8.Click += new System.EventHandler(this.button8_Click); + // + // pictureBox3 + // + this.pictureBox3.Location = new System.Drawing.Point(257, 442); + this.pictureBox3.Name = "pictureBox3"; + this.pictureBox3.Size = new System.Drawing.Size(405, 297); + this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox3.TabIndex = 15; + this.pictureBox3.TabStop = false; + // + // pictureBox4 + // + this.pictureBox4.Location = new System.Drawing.Point(697, 442); + this.pictureBox4.Name = "pictureBox4"; + this.pictureBox4.Size = new System.Drawing.Size(405, 297); + this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox4.TabIndex = 16; + this.pictureBox4.TabStop = false; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1137, 756); + this.Controls.Add(this.pictureBox4); + this.Controls.Add(this.pictureBox3); + this.Controls.Add(this.button6); + this.Controls.Add(this.button7); + this.Controls.Add(this.button8); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.pictureBox2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Controls.Add(this.button5); + this.Controls.Add(this.button1); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.pictureBox1); + this.Name = "Form1"; + this.Text = "Form1"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed); + this.Load += new System.EventHandler(this.Form1_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Button button2; + public System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.PictureBox pictureBox2; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button button6; + public System.Windows.Forms.Button button7; + private System.Windows.Forms.Button button8; + private System.Windows.Forms.PictureBox pictureBox3; + private System.Windows.Forms.PictureBox pictureBox4; + } +} + diff --git a/WindowsFormsApp1/Form1.cs b/WindowsFormsApp1/Form1.cs new file mode 100644 index 0000000..7b69bf5 --- /dev/null +++ b/WindowsFormsApp1/Form1.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using Basler.Pylon; + +namespace WindowsFormsApp1 +{ + public partial class Form1 : Form + { + //public class DoubleBufferedPictureBox : PictureBox + //{ + // public DoubleBufferedPictureBox() + // { + // this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); + // this.UpdateStyles(); + // } + //} + private readonly Basler Basler; + // 定義一個 PictureBox 的列表 + public List pictureBoxes; + public Form1() + { + InitializeComponent(); + //// 使用自定義的PictureBox類 + //DoubleBufferedPictureBox pictureBox1 = new DoubleBufferedPictureBox(); + //DoubleBufferedPictureBox pictureBox2 = new DoubleBufferedPictureBox(); + Basler = new Basler(this); + Basler.CameraImageEvent += Camera_CameraImageEvent; + //Basler.CameraImageEvent1 += Camera_CameraImageEvent1; + // 在構造函數中初始化 pictureBoxes 列表 + pictureBoxes = new List { pictureBox1, pictureBox2 /*, 其他 PictureBox 控件 */ }; + } + private void Form1_Load(object sender, EventArgs e) + { + + } + + private void button5_Click(object sender, EventArgs e) + { + textBox1.Text = Basler.CameraNumber.ToString(); + //如果连接相机个数大于0的话 初始化之前写的CameraInit(); + if (Basler.CameraNumber > 0) + { + Basler.CameraInit(); + } + else + { + MessageBox.Show("未連接到相機"); + Unable(); + } + } + + private void Form1_FormClosed(object sender, FormClosedEventArgs e) + { + + Basler.DestroyCamera(); + pictureBox1.Image?.Dispose(); + pictureBox2.Image?.Dispose(); + } + void Unable() + { + this.button1.Enabled = false; + this.button2.Enabled = false; + this.button3.Enabled = false; + this.button4.Enabled = false; + } + + + private void Camera_CameraImageEvent(Bitmap bmp, int cameraIndex) + { + // 確保 cameraIndex 不超出範圍 + if (cameraIndex >= 0 && cameraIndex < pictureBoxes.Count) + { + // 根據 cameraIndex 決定要更新哪個 pictureBox + PictureBox pictureBoxToUpdate = pictureBoxes[cameraIndex]; + + //使用委托进行跨线程交互 防止线程卡死状态在Invoke前面加一个Begin + pictureBoxToUpdate.BeginInvoke(new MethodInvoker(delegate + { + Bitmap old = pictureBoxToUpdate.Image as Bitmap; + pictureBoxToUpdate.Image = bmp; + if (old != null) + old.Dispose(); + })); + } + else + { + Console.WriteLine($"無效的相機索引:{cameraIndex}"); + } + } + + private void button2_Click(object sender, EventArgs e) + { + Basler.OneShot(0); + } + private void button8_Click(object sender, EventArgs e) + { + + Basler.OneShot(1); + } + private void button3_Click(object sender, EventArgs e) + { + Basler.Stop(0); + button3.Enabled = false; + button4.Enabled = true; + button2.Enabled = true; + } + private void button7_Click(object sender, EventArgs e) + { + Basler.Stop(1); + button7.Enabled = false; + button6.Enabled = true; + button8.Enabled = true; + } + private void button4_Click(object sender, EventArgs e) + { + Basler.KeepShot(0); + button4.Enabled = false; + button2.Enabled = false; + } + private void button6_Click(object sender, EventArgs e) + { + Basler.KeepShot(1); + button6.Enabled = false; + button8.Enabled = false; + } + private void button1_Click(object sender, EventArgs e) + { + Basler.Close(); + } + + + } +} diff --git a/WindowsFormsApp1/Form1.resx b/WindowsFormsApp1/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WindowsFormsApp1/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFormsApp1/Program.cs b/WindowsFormsApp1/Program.cs new file mode 100644 index 0000000..52e6d9b --- /dev/null +++ b/WindowsFormsApp1/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WindowsFormsApp1 +{ + internal static class Program + { + /// + /// 應用程式的主要進入點。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/WindowsFormsApp1/Properties/AssemblyInfo.cs b/WindowsFormsApp1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..687e99d --- /dev/null +++ b/WindowsFormsApp1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 組件的一般資訊是由下列的屬性集控制。 +// 變更這些屬性的值即可修改組件的相關 +// 資訊。 +[assembly: AssemblyTitle("WindowsFormsApp1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsFormsApp1")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 將 ComVisible 設為 false 可對 COM 元件隱藏 +// 組件中的類型。若必須從 COM 存取此組件中的類型, +// 的類型,請在該類型上將 ComVisible 屬性設定為 true。 +[assembly: ComVisible(false)] + +// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID +[assembly: Guid("9126e2b4-e759-4070-bec2-e81e8e3dc6aa")] + +// 組件的版本資訊由下列四個值所組成: +// +// 主要版本 +// 次要版本 +// 組建編號 +// 修訂編號 +// +// 您可以指定所有的值,也可以使用 '*' 將組建和修訂編號 +// 設為預設,如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WindowsFormsApp1/Properties/Resources.Designer.cs b/WindowsFormsApp1/Properties/Resources.Designer.cs new file mode 100644 index 0000000..1055548 --- /dev/null +++ b/WindowsFormsApp1/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 這段程式碼是由工具產生的。 +// 執行階段版本:4.0.30319.42000 +// +// 變更這個檔案可能會導致不正確的行為,而且如果已重新產生 +// 程式碼,則會遺失變更。 +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsApp1.Properties +{ + + + /// + /// 用於查詢當地語系化字串等的強類型資源類別 + /// + // 這個類別是自動產生的,是利用 StronglyTypedResourceBuilder + // 類別透過 ResGen 或 Visual Studio 這類工具產生。 + // 若要加入或移除成員,請編輯您的 .ResX 檔,然後重新執行 ResGen + // (利用 /str 選項),或重建您的 VS 專案。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 傳回這個類別使用的快取的 ResourceManager 執行個體。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsApp1.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 覆寫目前執行緒的 CurrentUICulture 屬性,對象是所有 + /// 使用這個強類型資源類別的資源查閱。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/WindowsFormsApp1/Properties/Resources.resx b/WindowsFormsApp1/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/WindowsFormsApp1/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFormsApp1/Properties/Settings.Designer.cs b/WindowsFormsApp1/Properties/Settings.Designer.cs new file mode 100644 index 0000000..438df21 --- /dev/null +++ b/WindowsFormsApp1/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsApp1.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/WindowsFormsApp1/Properties/Settings.settings b/WindowsFormsApp1/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/WindowsFormsApp1/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/WindowsFormsApp1/WindowsFormsApp1.csproj b/WindowsFormsApp1/WindowsFormsApp1.csproj new file mode 100644 index 0000000..d1d50d2 --- /dev/null +++ b/WindowsFormsApp1/WindowsFormsApp1.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {9126E2B4-E759-4070-BEC2-E81E8E3DC6AA} + WinExe + WindowsFormsApp1 + WindowsFormsApp1 + v4.8 + 512 + true + true + + + x64 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\Windows\Microsoft.NET\assembly\GAC_64\Basler.Pylon\v4.0_1.2.0.0__e389355f398382ab\Basler.Pylon.dll + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file