项目基础代码完成

This commit is contained in:
zqm
2026-03-16 17:05:54 +08:00
parent f3dd091d2c
commit e4502c338a
23 changed files with 1930 additions and 142 deletions

View File

@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Threading;
using XCamera;
using XCamera.Models;
namespace XCamera.TestApp
{
/// <summary>
/// XCamera库简单测试程序
/// </summary>
class Program
{
static void Main(string[] args)
{
Console.WriteLine("XCamera LED灯识别库测试程序");
Console.WriteLine("==========================================");
try
{
// 订阅事件
XCamera.LedStatusUpdated += OnLedStatusUpdated;
XCamera.ConnectionStateChanged += OnConnectionStateChanged;
XCamera.ErrorOccurred += OnErrorOccurred;
// 1. 初始化
Console.WriteLine("正在初始化...");
if (!XCamera.Initialize("config\\sample_config.json"))
{
Console.WriteLine("初始化失败!");
return;
}
Console.WriteLine("初始化成功!");
// 显示当前配置
var config = XCamera.GetCurrentConfig();
if (config != null)
{
Console.WriteLine($"摄像头IP: {config.IpAddress}");
Console.WriteLine($"TCP端口: {config.TcpPort}");
Console.WriteLine($"LED区域数: {config.LedRegions.Count}");
}
// 2. 启动摄像头
Console.WriteLine("正在启动摄像头...");
if (!XCamera.StartCamera())
{
Console.WriteLine("启动摄像头失败!");
return;
}
Console.WriteLine("摄像头启动成功!");
// 3. 手动检测一次LED状态
Console.WriteLine("正在检测LED状态...");
var statuses = XCamera.DetectLeds();
Console.WriteLine($"检测到 {statuses.Count} 个LED灯:");
foreach (var status in statuses)
{
Console.WriteLine($" {status.GetStatusDescription()}");
}
// 4. 开始循环捕获(可选)
Console.WriteLine("\n是否开始循环捕获 (y/n)");
string response = Console.ReadLine();
if (response.ToLower() == "y")
{
Console.WriteLine("开始循环捕获,按任意键停止...");
XCamera.StartCapture(2000); // 2秒间隔
// 等待用户输入
Console.ReadKey();
XCamera.StopCapture();
Console.WriteLine("停止捕获");
}
// 5. 显示区域编辑器(可选)
Console.WriteLine("\n是否显示区域编辑器 (y/n)");
response = Console.ReadLine();
if (response.ToLower() == "y")
{
Console.WriteLine("显示区域编辑器...");
XCamera.ShowRegionEditor();
}
// 6. 关闭资源
Console.WriteLine("正在关闭资源...");
XCamera.Shutdown();
Console.WriteLine("资源已释放");
}
catch (Exception ex)
{
Console.WriteLine($"程序异常: {ex.Message}");
Console.WriteLine($"堆栈跟踪: {ex.StackTrace}");
}
finally
{
XCamera.Shutdown();
}
Console.WriteLine("\n测试程序结束按任意键退出...");
Console.ReadKey();
}
/// <summary>
/// LED状态更新事件处理
/// </summary>
private static void OnLedStatusUpdated(object sender, LedStatusEventArgs e)
{
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] LED状态更新:");
foreach (var status in e.Statuses)
{
Console.WriteLine($" {status.GetStatusDescription()}");
}
}
/// <summary>
/// 连接状态变更事件处理
/// </summary>
private static void OnConnectionStateChanged(object sender, ConnectionStateEventArgs e)
{
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 摄像头连接状态: {(e.IsConnected ? "" : "")}");
}
/// <summary>
/// 错误事件处理
/// </summary>
private static void OnErrorOccurred(object sender, ErrorEventArgs e)
{
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 错误: {e.ErrorMessage}");
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("XCamera.TestApp")]
[assembly: AssemblyDescription("XCamera库测试程序")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("JoyD")]
[assembly: AssemblyProduct("XCamera.TestApp")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("c9d8e7f6-5b4a-4c3d-8e2f-1a0b9c8d7e6f")]
// 程序集的版本信息由下列四个值组成: 1.0.0.0
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用"生成号"和"修订号"的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,65 @@
<?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>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C9D8E7F6-5B4A-4C3D-8E2F-1A0B9C8D7E6F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XCamera.TestApp</RootNamespace>
<AssemblyName>XCamera.TestApp</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XCamera\XCamera.csproj">
<Project>{B8E762E5-4A3B-4F7D-9C2E-8F3A7B9C5D1E}</Project>
<Name>XCamera</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\XCamera\config\sample_config.json">
<Link>config\sample_config.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\XCamera\lib\XCloudSDK\XCloudSDK.dll">
<Link>XCloudSDK.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>