基础测试代码
This commit is contained in:
@@ -40,10 +40,9 @@ namespace Test
|
||||
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.lblStatus = 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();
|
||||
@@ -163,18 +162,18 @@ namespace Test
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabel1});
|
||||
this.lblStatus});
|
||||
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
|
||||
// lblStatus
|
||||
//
|
||||
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
|
||||
this.toolStripStatusLabel1.Size = new System.Drawing.Size(44, 17);
|
||||
this.toolStripStatusLabel1.Text = "状态栏";
|
||||
this.lblStatus.Name = "lblStatus";
|
||||
this.lblStatus.Size = new System.Drawing.Size(68, 17);
|
||||
this.lblStatus.Text = "状态: 未初始化";
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
@@ -196,23 +195,11 @@ namespace Test
|
||||
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);
|
||||
@@ -253,9 +240,8 @@ namespace Test
|
||||
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.ToolStripStatusLabel lblStatus;
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.TextBox txtLog;
|
||||
private System.Windows.Forms.Label lblStatus;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using XCamera;
|
||||
using XCamera.Models;
|
||||
|
||||
namespace Test
|
||||
@@ -16,13 +16,17 @@ namespace Test
|
||||
private bool _isInitialized = false;
|
||||
private bool _isConnected = false;
|
||||
private bool _isCapturing = false;
|
||||
private Thread _captureThread;
|
||||
private bool _shouldStopCapture = false;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// 检查是否处于设计模式
|
||||
if (!DesignMode)
|
||||
{
|
||||
InitializeEvents();
|
||||
}
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
@@ -31,11 +35,15 @@ namespace Test
|
||||
/// </summary>
|
||||
private void InitializeEvents()
|
||||
{
|
||||
// 避免在设计模式下订阅事件
|
||||
if (DesignMode)
|
||||
return;
|
||||
|
||||
// 订阅XCamera事件
|
||||
XCamera.LedStatusUpdated += OnLedStatusUpdated;
|
||||
XCamera.ConnectionStateChanged += OnConnectionStateChanged;
|
||||
XCamera.CaptureStateChanged += OnCaptureStateChanged;
|
||||
XCamera.ErrorOccurred += OnErrorOccurred;
|
||||
global::XCamera.XCamera.LedStatusUpdated += OnLedStatusUpdated;
|
||||
global::XCamera.XCamera.ConnectionStateChanged += OnConnectionStateChanged;
|
||||
global::XCamera.XCamera.CaptureStateChanged += OnCaptureStateChanged;
|
||||
global::XCamera.XCamera.ErrorOccurred += OnErrorOccurred;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,13 +58,13 @@ namespace Test
|
||||
// 使用默认配置文件路径
|
||||
string configPath = System.IO.Path.Combine(Application.StartupPath, "config", "sample_config.json");
|
||||
|
||||
if (XCamera.Initialize(configPath))
|
||||
if (global::XCamera.XCamera.Initialize(configPath))
|
||||
{
|
||||
_isInitialized = true;
|
||||
LogMessage("初始化成功!");
|
||||
|
||||
// 显示配置信息
|
||||
var config = XCamera.GetCurrentConfig();
|
||||
var config = global::XCamera.XCamera.GetCurrentConfig();
|
||||
if (config != null)
|
||||
{
|
||||
LogMessage($"摄像头IP: {config.IpAddress}");
|
||||
@@ -93,12 +101,12 @@ namespace Test
|
||||
{
|
||||
LogMessage($"正在加载配置文件: {openFileDialog.FileName}");
|
||||
|
||||
if (XCamera.SetConfigFile(openFileDialog.FileName))
|
||||
if (global::XCamera.XCamera.SetConfigFile(openFileDialog.FileName))
|
||||
{
|
||||
LogMessage("配置文件加载成功!");
|
||||
|
||||
// 显示配置信息
|
||||
var config = XCamera.GetCurrentConfig();
|
||||
var config = global::XCamera.XCamera.GetCurrentConfig();
|
||||
if (config != null)
|
||||
{
|
||||
LogMessage($"摄像头IP: {config.IpAddress}");
|
||||
@@ -133,7 +141,7 @@ namespace Test
|
||||
|
||||
LogMessage("正在启动摄像头...");
|
||||
|
||||
if (XCamera.StartCamera())
|
||||
if (global::XCamera.XCamera.StartCamera())
|
||||
{
|
||||
LogMessage("摄像头启动成功!");
|
||||
}
|
||||
@@ -171,7 +179,7 @@ namespace Test
|
||||
|
||||
LogMessage("正在开始捕获图像...");
|
||||
|
||||
if (XCamera.StartCapture(1000)) // 1秒间隔
|
||||
if (global::XCamera.XCamera.StartCapture(1000)) // 1秒间隔
|
||||
{
|
||||
LogMessage("开始捕获图像成功!");
|
||||
}
|
||||
@@ -203,7 +211,7 @@ namespace Test
|
||||
|
||||
LogMessage("正在识别LED灯...");
|
||||
|
||||
var statuses = XCamera.DetectLeds();
|
||||
var statuses = global::XCamera.XCamera.DetectLeds();
|
||||
LogMessage($"检测到 {statuses.Count} 个LED灯:");
|
||||
|
||||
foreach (var status in statuses)
|
||||
@@ -235,7 +243,7 @@ namespace Test
|
||||
|
||||
LogMessage("正在查询LED状态...");
|
||||
|
||||
var statuses = XCamera.GetLedStatuses();
|
||||
var statuses = global::XCamera.XCamera.GetLedStatuses();
|
||||
LogMessage($"当前LED状态 ({statuses.Count} 个):");
|
||||
|
||||
foreach (var status in statuses)
|
||||
@@ -257,7 +265,7 @@ namespace Test
|
||||
try
|
||||
{
|
||||
LogMessage("正在打开区域编辑器...");
|
||||
XCamera.ShowRegionEditor();
|
||||
global::XCamera.XCamera.ShowRegionEditor();
|
||||
LogMessage("区域编辑器已关闭");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -277,15 +285,15 @@ namespace Test
|
||||
|
||||
if (_isCapturing)
|
||||
{
|
||||
XCamera.StopCapture();
|
||||
global::XCamera.XCamera.StopCapture();
|
||||
}
|
||||
|
||||
if (_isConnected)
|
||||
{
|
||||
XCamera.StopCamera();
|
||||
global::XCamera.XCamera.StopCamera();
|
||||
}
|
||||
|
||||
XCamera.Shutdown();
|
||||
global::XCamera.XCamera.Shutdown();
|
||||
|
||||
_isInitialized = false;
|
||||
_isConnected = false;
|
||||
@@ -315,7 +323,7 @@ namespace Test
|
||||
}
|
||||
|
||||
LogMessage("正在停止捕获...");
|
||||
XCamera.StopCapture();
|
||||
global::XCamera.XCamera.StopCapture();
|
||||
LogMessage("捕获已停止");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -343,10 +351,10 @@ namespace Test
|
||||
|
||||
if (_isCapturing)
|
||||
{
|
||||
XCamera.StopCapture();
|
||||
global::XCamera.XCamera.StopCapture();
|
||||
}
|
||||
|
||||
XCamera.StopCamera();
|
||||
global::XCamera.XCamera.StopCamera();
|
||||
LogMessage("摄像头已停止");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -532,7 +540,9 @@ namespace Test
|
||||
else
|
||||
lblStatus.Text = "状态: 未初始化";
|
||||
|
||||
lblStatus.ForeColor = _isConnected ? Color.Green : Color.Red;
|
||||
// ToolStripStatusLabel没有ForeColor属性,我们可以使用BackColor或者保持默认样式
|
||||
// 如果需要颜色变化,可以考虑使用BackColor
|
||||
// lblStatus.BackColor = _isConnected ? Color.LightGreen : Color.LightPink;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -542,20 +552,24 @@ namespace Test
|
||||
{
|
||||
try
|
||||
{
|
||||
// 避免在设计模式下执行外部代码
|
||||
if (DesignMode)
|
||||
return;
|
||||
|
||||
// 确保释放资源
|
||||
if (_isCapturing)
|
||||
{
|
||||
XCamera.StopCapture();
|
||||
global::XCamera.XCamera.StopCapture();
|
||||
}
|
||||
|
||||
if (_isConnected)
|
||||
{
|
||||
XCamera.StopCamera();
|
||||
global::XCamera.XCamera.StopCamera();
|
||||
}
|
||||
|
||||
if (_isInitialized)
|
||||
{
|
||||
XCamera.Shutdown();
|
||||
global::XCamera.XCamera.Shutdown();
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
@@ -43,6 +43,12 @@
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\XCamera\XCamera.csproj">
|
||||
<Project>{B8E762E5-4A3B-4F7D-9C2E-8F3A7B9C5D1E}</Project>
|
||||
<Name>XCamera</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
||||
Reference in New Issue
Block a user