diff --git a/Windows/CS/Framework4.0/XCamera/Test/Form1.Designer.cs b/Windows/CS/Framework4.0/XCamera/Test/Form1.Designer.cs
new file mode 100644
index 0000000..2099df9
--- /dev/null
+++ b/Windows/CS/Framework4.0/XCamera/Test/Form1.Designer.cs
@@ -0,0 +1,261 @@
+namespace Test
+{
+ partial class Form1
+ {
+ ///
+ /// 必需的设计器变量。
+ ///
+ 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 窗体设计器生成的代码
+
+ ///
+ /// 设计器支持所需的方法 - 不要修改
+ /// 使用代码编辑器修改此方法的内容。
+ ///
+ private void InitializeComponent()
+ {
+ this.LedImage = new System.Windows.Forms.PictureBox();
+ this.btnInitialize = new System.Windows.Forms.Button();
+ this.btnSetConfigFile = new System.Windows.Forms.Button();
+ this.btnStartCamera = new System.Windows.Forms.Button();
+ this.btnStartCapture = new System.Windows.Forms.Button();
+ this.btnDetectLeds = new System.Windows.Forms.Button();
+ this.btnGetLedStatuses = new System.Windows.Forms.Button();
+ this.btnShowRegionEditor = new System.Windows.Forms.Button();
+ this.btnShutdown = new System.Windows.Forms.Button();
+ this.btnStopCapture = new System.Windows.Forms.Button();
+ this.btnStopCamera = new System.Windows.Forms.Button();
+ this.statusStrip1 = new System.Windows.Forms.StatusStrip();
+ this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
+ this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.txtLog = new System.Windows.Forms.TextBox();
+ this.lblStatus = new System.Windows.Forms.Label();
+ ((System.ComponentModel.ISupportInitialize)(this.LedImage)).BeginInit();
+ this.statusStrip1.SuspendLayout();
+ this.groupBox1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // LedImage
+ //
+ this.LedImage.BackColor = System.Drawing.SystemColors.ControlDark;
+ this.LedImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.LedImage.Location = new System.Drawing.Point(12, 12);
+ this.LedImage.Name = "LedImage";
+ this.LedImage.Size = new System.Drawing.Size(557, 426);
+ this.LedImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
+ this.LedImage.TabIndex = 0;
+ this.LedImage.TabStop = false;
+ //
+ // btnInitialize
+ //
+ this.btnInitialize.Location = new System.Drawing.Point(608, 38);
+ this.btnInitialize.Name = "btnInitialize";
+ this.btnInitialize.Size = new System.Drawing.Size(111, 31);
+ this.btnInitialize.TabIndex = 1;
+ this.btnInitialize.Text = "1. 初始化";
+ this.btnInitialize.UseVisualStyleBackColor = true;
+ this.btnInitialize.Click += new System.EventHandler(this.btnInitialize_Click);
+ //
+ // btnSetConfigFile
+ //
+ this.btnSetConfigFile.Location = new System.Drawing.Point(608, 89);
+ this.btnSetConfigFile.Name = "btnSetConfigFile";
+ this.btnSetConfigFile.Size = new System.Drawing.Size(111, 31);
+ this.btnSetConfigFile.TabIndex = 2;
+ this.btnSetConfigFile.Text = "2. 设置配置文件";
+ this.btnSetConfigFile.UseVisualStyleBackColor = true;
+ this.btnSetConfigFile.Click += new System.EventHandler(this.btnSetConfigFile_Click);
+ //
+ // btnStartCamera
+ //
+ this.btnStartCamera.Location = new System.Drawing.Point(608, 140);
+ this.btnStartCamera.Name = "btnStartCamera";
+ this.btnStartCamera.Size = new System.Drawing.Size(111, 31);
+ this.btnStartCamera.TabIndex = 3;
+ this.btnStartCamera.Text = "3. 启动摄像头";
+ this.btnStartCamera.UseVisualStyleBackColor = true;
+ this.btnStartCamera.Click += new System.EventHandler(this.btnStartCamera_Click);
+ //
+ // btnStartCapture
+ //
+ this.btnStartCapture.Location = new System.Drawing.Point(608, 191);
+ this.btnStartCapture.Name = "btnStartCapture";
+ this.btnStartCapture.Size = new System.Drawing.Size(111, 31);
+ this.btnStartCapture.TabIndex = 4;
+ this.btnStartCapture.Text = "4. 开始捕获";
+ this.btnStartCapture.UseVisualStyleBackColor = true;
+ this.btnStartCapture.Click += new System.EventHandler(this.btnStartCapture_Click);
+ //
+ // btnDetectLeds
+ //
+ this.btnDetectLeds.Location = new System.Drawing.Point(608, 242);
+ this.btnDetectLeds.Name = "btnDetectLeds";
+ this.btnDetectLeds.Size = new System.Drawing.Size(111, 31);
+ this.btnDetectLeds.TabIndex = 5;
+ this.btnDetectLeds.Text = "5. LED识别";
+ this.btnDetectLeds.UseVisualStyleBackColor = true;
+ this.btnDetectLeds.Click += new System.EventHandler(this.btnDetectLeds_Click);
+ //
+ // btnGetLedStatuses
+ //
+ this.btnGetLedStatuses.Location = new System.Drawing.Point(608, 293);
+ this.btnGetLedStatuses.Name = "btnGetLedStatuses";
+ this.btnGetLedStatuses.Size = new System.Drawing.Size(111, 31);
+ this.btnGetLedStatuses.TabIndex = 6;
+ this.btnGetLedStatuses.Text = "6. 状态查询";
+ this.btnGetLedStatuses.UseVisualStyleBackColor = true;
+ this.btnGetLedStatuses.Click += new System.EventHandler(this.btnGetLedStatuses_Click);
+ //
+ // btnShowRegionEditor
+ //
+ this.btnShowRegionEditor.Location = new System.Drawing.Point(608, 344);
+ this.btnShowRegionEditor.Name = "btnShowRegionEditor";
+ this.btnShowRegionEditor.Size = new System.Drawing.Size(111, 31);
+ this.btnShowRegionEditor.TabIndex = 7;
+ this.btnShowRegionEditor.Text = "7. 区域编辑器";
+ this.btnShowRegionEditor.UseVisualStyleBackColor = true;
+ this.btnShowRegionEditor.Click += new System.EventHandler(this.btnShowRegionEditor_Click);
+ //
+ // btnShutdown
+ //
+ this.btnShutdown.Location = new System.Drawing.Point(608, 395);
+ this.btnShutdown.Name = "btnShutdown";
+ this.btnShutdown.Size = new System.Drawing.Size(111, 31);
+ this.btnShutdown.TabIndex = 8;
+ this.btnShutdown.Text = "8. 关闭";
+ this.btnShutdown.UseVisualStyleBackColor = true;
+ this.btnShutdown.Click += new System.EventHandler(this.btnShutdown_Click);
+ //
+ // btnStopCapture
+ //
+ this.btnStopCapture.Location = new System.Drawing.Point(725, 191);
+ this.btnStopCapture.Name = "btnStopCapture";
+ this.btnStopCapture.Size = new System.Drawing.Size(63, 31);
+ this.btnStopCapture.TabIndex = 9;
+ this.btnStopCapture.Text = "停止";
+ this.btnStopCapture.UseVisualStyleBackColor = true;
+ this.btnStopCapture.Click += new System.EventHandler(this.btnStopCapture_Click);
+ //
+ // btnStopCamera
+ //
+ this.btnStopCamera.Location = new System.Drawing.Point(725, 140);
+ this.btnStopCamera.Name = "btnStopCamera";
+ this.btnStopCamera.Size = new System.Drawing.Size(63, 31);
+ this.btnStopCamera.TabIndex = 10;
+ this.btnStopCamera.Text = "停止";
+ this.btnStopCamera.UseVisualStyleBackColor = true;
+ this.btnStopCamera.Click += new System.EventHandler(this.btnStopCamera_Click);
+ //
+ // statusStrip1
+ //
+ this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabel1});
+ this.statusStrip1.Location = new System.Drawing.Point(0, 451);
+ this.statusStrip1.Name = "statusStrip1";
+ this.statusStrip1.Size = new System.Drawing.Size(800, 22);
+ this.statusStrip1.TabIndex = 11;
+ this.statusStrip1.Text = "statusStrip1";
+ //
+ // toolStripStatusLabel1
+ //
+ this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
+ this.toolStripStatusLabel1.Size = new System.Drawing.Size(44, 17);
+ this.toolStripStatusLabel1.Text = "状态栏";
+ //
+ // groupBox1
+ //
+ this.groupBox1.Controls.Add(this.txtLog);
+ this.groupBox1.Location = new System.Drawing.Point(12, 444);
+ this.groupBox1.Name = "groupBox1";
+ this.groupBox1.Size = new System.Drawing.Size(557, 100);
+ this.groupBox1.TabIndex = 12;
+ this.groupBox1.TabStop = false;
+ this.groupBox1.Text = "日志";
+ //
+ // txtLog
+ //
+ this.txtLog.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.txtLog.Location = new System.Drawing.Point(3, 17);
+ this.txtLog.Multiline = true;
+ this.txtLog.Name = "txtLog";
+ this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
+ this.txtLog.Size = new System.Drawing.Size(551, 80);
+ this.txtLog.TabIndex = 0;
+ //
+ // lblStatus
+ //
+ this.lblStatus.AutoSize = true;
+ this.lblStatus.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+ this.lblStatus.ForeColor = System.Drawing.Color.Red;
+ this.lblStatus.Location = new System.Drawing.Point(12, 550);
+ this.lblStatus.Name = "lblStatus";
+ this.lblStatus.Size = new System.Drawing.Size(96, 12);
+ this.lblStatus.TabIndex = 13;
+ this.lblStatus.Text = "状态: 未初始化";
+ //
+ // Form1
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 574);
+ this.Controls.Add(this.lblStatus);
+ this.Controls.Add(this.groupBox1);
+ this.Controls.Add(this.statusStrip1);
+ this.Controls.Add(this.btnStopCamera);
+ this.Controls.Add(this.btnStopCapture);
+ this.Controls.Add(this.btnShutdown);
+ this.Controls.Add(this.btnShowRegionEditor);
+ this.Controls.Add(this.btnGetLedStatuses);
+ this.Controls.Add(this.btnDetectLeds);
+ this.Controls.Add(this.btnStartCapture);
+ this.Controls.Add(this.btnStartCamera);
+ this.Controls.Add(this.btnSetConfigFile);
+ this.Controls.Add(this.btnInitialize);
+ this.Controls.Add(this.LedImage);
+ this.Name = "Form1";
+ this.Text = "XCamera LED灯识别测试程序";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
+ ((System.ComponentModel.ISupportInitialize)(this.LedImage)).EndInit();
+ this.statusStrip1.ResumeLayout(false);
+ this.statusStrip1.PerformLayout();
+ this.groupBox1.ResumeLayout(false);
+ this.groupBox1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PictureBox LedImage;
+ private System.Windows.Forms.Button btnInitialize;
+ private System.Windows.Forms.Button btnSetConfigFile;
+ private System.Windows.Forms.Button btnStartCamera;
+ private System.Windows.Forms.Button btnStartCapture;
+ private System.Windows.Forms.Button btnDetectLeds;
+ private System.Windows.Forms.Button btnGetLedStatuses;
+ private System.Windows.Forms.Button btnShowRegionEditor;
+ private System.Windows.Forms.Button btnShutdown;
+ private System.Windows.Forms.Button btnStopCapture;
+ private System.Windows.Forms.Button btnStopCamera;
+ private System.Windows.Forms.StatusStrip statusStrip1;
+ private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
+ private System.Windows.Forms.GroupBox groupBox1;
+ private System.Windows.Forms.TextBox txtLog;
+ private System.Windows.Forms.Label lblStatus;
+ }
+}
\ No newline at end of file
diff --git a/Windows/CS/Framework4.0/XCamera/Test/Form1.cs b/Windows/CS/Framework4.0/XCamera/Test/Form1.cs
new file mode 100644
index 0000000..1341bb7
--- /dev/null
+++ b/Windows/CS/Framework4.0/XCamera/Test/Form1.cs
@@ -0,0 +1,567 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using XCamera;
+using XCamera.Models;
+
+namespace Test
+{
+ public partial class Form1 : Form
+ {
+ private bool _isInitialized = false;
+ private bool _isConnected = false;
+ private bool _isCapturing = false;
+ private Thread _captureThread;
+ private bool _shouldStopCapture = false;
+
+ public Form1()
+ {
+ InitializeComponent();
+ InitializeEvents();
+ UpdateUI();
+ }
+
+ ///
+ /// 初始化事件处理
+ ///
+ private void InitializeEvents()
+ {
+ // 订阅XCamera事件
+ XCamera.LedStatusUpdated += OnLedStatusUpdated;
+ XCamera.ConnectionStateChanged += OnConnectionStateChanged;
+ XCamera.CaptureStateChanged += OnCaptureStateChanged;
+ XCamera.ErrorOccurred += OnErrorOccurred;
+ }
+
+ ///
+ /// 1. 初始化
+ ///
+ private void btnInitialize_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ LogMessage("正在初始化...");
+
+ // 使用默认配置文件路径
+ string configPath = System.IO.Path.Combine(Application.StartupPath, "config", "sample_config.json");
+
+ if (XCamera.Initialize(configPath))
+ {
+ _isInitialized = true;
+ LogMessage("初始化成功!");
+
+ // 显示配置信息
+ var config = XCamera.GetCurrentConfig();
+ if (config != null)
+ {
+ LogMessage($"摄像头IP: {config.IpAddress}");
+ LogMessage($"TCP端口: {config.TcpPort}");
+ LogMessage($"LED区域数: {config.LedRegions.Count}");
+ }
+ }
+ else
+ {
+ LogMessage("初始化失败!");
+ }
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"初始化错误: {ex.Message}");
+ }
+
+ UpdateUI();
+ }
+
+ ///
+ /// 2. 设置配置文件路径
+ ///
+ private void btnSetConfigFile_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ using (OpenFileDialog openFileDialog = new OpenFileDialog())
+ {
+ openFileDialog.Filter = "JSON文件|*.json|所有文件|*.*";
+ openFileDialog.Title = "选择配置文件";
+
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ LogMessage($"正在加载配置文件: {openFileDialog.FileName}");
+
+ if (XCamera.SetConfigFile(openFileDialog.FileName))
+ {
+ LogMessage("配置文件加载成功!");
+
+ // 显示配置信息
+ var config = XCamera.GetCurrentConfig();
+ if (config != null)
+ {
+ LogMessage($"摄像头IP: {config.IpAddress}");
+ LogMessage($"LED区域数: {config.LedRegions.Count}");
+ }
+ }
+ else
+ {
+ LogMessage("配置文件加载失败!");
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"配置文件加载错误: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 3. 启动摄像头
+ ///
+ private void btnStartCamera_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (!_isInitialized)
+ {
+ LogMessage("请先初始化!");
+ return;
+ }
+
+ LogMessage("正在启动摄像头...");
+
+ if (XCamera.StartCamera())
+ {
+ LogMessage("摄像头启动成功!");
+ }
+ else
+ {
+ LogMessage("摄像头启动失败!");
+ }
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"启动摄像头错误: {ex.Message}");
+ }
+
+ UpdateUI();
+ }
+
+ ///
+ /// 4. 开始捕获图像
+ ///
+ private void btnStartCapture_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (!_isConnected)
+ {
+ LogMessage("请先连接摄像头!");
+ return;
+ }
+
+ if (_isCapturing)
+ {
+ LogMessage("已经在捕获中!");
+ return;
+ }
+
+ LogMessage("正在开始捕获图像...");
+
+ if (XCamera.StartCapture(1000)) // 1秒间隔
+ {
+ LogMessage("开始捕获图像成功!");
+ }
+ else
+ {
+ LogMessage("开始捕获图像失败!");
+ }
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"开始捕获错误: {ex.Message}");
+ }
+
+ UpdateUI();
+ }
+
+ ///
+ /// 5. LED灯识别
+ ///
+ private void btnDetectLeds_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (!_isConnected)
+ {
+ LogMessage("请先连接摄像头!");
+ return;
+ }
+
+ LogMessage("正在识别LED灯...");
+
+ var statuses = XCamera.DetectLeds();
+ LogMessage($"检测到 {statuses.Count} 个LED灯:");
+
+ foreach (var status in statuses)
+ {
+ LogMessage($" {status.GetStatusDescription()}");
+ }
+
+ // 显示图像(如果有的话)
+ DisplayLedImage(statuses);
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"LED识别错误: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 6. 状态查询
+ ///
+ private void btnGetLedStatuses_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (!_isConnected)
+ {
+ LogMessage("请先连接摄像头!");
+ return;
+ }
+
+ LogMessage("正在查询LED状态...");
+
+ var statuses = XCamera.GetLedStatuses();
+ LogMessage($"当前LED状态 ({statuses.Count} 个):");
+
+ foreach (var status in statuses)
+ {
+ LogMessage($" {status.GetStatusDescription()}");
+ }
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"状态查询错误: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 7. 区域设置窗口
+ ///
+ private void btnShowRegionEditor_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ LogMessage("正在打开区域编辑器...");
+ XCamera.ShowRegionEditor();
+ LogMessage("区域编辑器已关闭");
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"区域编辑器错误: {ex.Message}");
+ }
+ }
+
+ ///
+ /// 8. 资源释放
+ ///
+ private void btnShutdown_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ LogMessage("正在释放资源...");
+
+ if (_isCapturing)
+ {
+ XCamera.StopCapture();
+ }
+
+ if (_isConnected)
+ {
+ XCamera.StopCamera();
+ }
+
+ XCamera.Shutdown();
+
+ _isInitialized = false;
+ _isConnected = false;
+ _isCapturing = false;
+
+ LogMessage("资源已释放");
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"资源释放错误: {ex.Message}");
+ }
+
+ UpdateUI();
+ }
+
+ ///
+ /// 停止捕获
+ ///
+ private void btnStopCapture_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (!_isCapturing)
+ {
+ LogMessage("当前未在捕获中!");
+ return;
+ }
+
+ LogMessage("正在停止捕获...");
+ XCamera.StopCapture();
+ LogMessage("捕获已停止");
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"停止捕获错误: {ex.Message}");
+ }
+
+ UpdateUI();
+ }
+
+ ///
+ /// 停止摄像头
+ ///
+ private void btnStopCamera_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (!_isConnected)
+ {
+ LogMessage("摄像头未连接!");
+ return;
+ }
+
+ LogMessage("正在停止摄像头...");
+
+ if (_isCapturing)
+ {
+ XCamera.StopCapture();
+ }
+
+ XCamera.StopCamera();
+ LogMessage("摄像头已停止");
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"停止摄像头错误: {ex.Message}");
+ }
+
+ UpdateUI();
+ }
+
+ ///
+ /// LED状态更新事件处理
+ ///
+ private void OnLedStatusUpdated(object sender, LedStatusEventArgs e)
+ {
+ if (InvokeRequired)
+ {
+ BeginInvoke(new Action