增加图像模式
This commit is contained in:
@@ -646,12 +646,6 @@ namespace JoyD.Windows.CS.Toprie
|
||||
v8Instance.Set_time(data);
|
||||
}
|
||||
|
||||
// 设置图像模式
|
||||
public void SetImageMode(int mode)
|
||||
{
|
||||
v8Instance.SetImageMode(mode);
|
||||
}
|
||||
|
||||
// 获取视频模式
|
||||
public int GetVideoMode()
|
||||
{
|
||||
|
||||
@@ -131,16 +131,6 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
// 设置为热图模式
|
||||
bool modeSet = false;
|
||||
try
|
||||
{
|
||||
_deviceManager.SetImageMode(ImageMode.Thermal);
|
||||
modeSet = true;
|
||||
Console.WriteLine("已设置热图模式");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"设置热图模式失败: {ex.Message}");
|
||||
}
|
||||
|
||||
// 启用自动重连
|
||||
_deviceManager.AutoReconnectEnabled = true;
|
||||
@@ -155,7 +145,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
try
|
||||
{
|
||||
_deviceManager.SetImageMode(ImageMode.Thermal);
|
||||
_deviceManager.SetImageMode(ImageMode.Infrared);
|
||||
Console.WriteLine("连接后已设置热图模式");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -680,7 +670,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
try
|
||||
{
|
||||
_deviceManager.SetImageMode(ImageMode.Thermal);
|
||||
_deviceManager.SetImageMode(ImageMode.Infrared);
|
||||
Console.WriteLine("首次连接,设置热图模式");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -27,14 +27,15 @@ namespace JoyD.Windows.CS.Toprie
|
||||
Reconnecting
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 图像模式枚举
|
||||
/// </summary>
|
||||
public enum ImageMode
|
||||
{
|
||||
Thermal,
|
||||
Visible,
|
||||
Fusion
|
||||
Infrared, // 红外模式
|
||||
Natural // 自然模式
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -175,7 +176,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
// 是否已释放
|
||||
private bool _isDisposed = false;
|
||||
// 图像模式
|
||||
private ImageMode _currentImageMode = ImageMode.Thermal;
|
||||
private ImageMode _currentImageMode = ImageMode.Infrared;
|
||||
// 当前色彩模式
|
||||
private PaletteType _currentPaletteType = PaletteType.WhiteHot;
|
||||
// 当前视频模式
|
||||
@@ -1425,11 +1426,6 @@ namespace JoyD.Windows.CS.Toprie
|
||||
if (_currentImageMode != value)
|
||||
{
|
||||
_currentImageMode = value;
|
||||
// 如果已连接,发送模式变更命令
|
||||
if (_connectionStatus == ConnectionStatus.Connected)
|
||||
{
|
||||
SendModeChangeCommand(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2618,95 +2614,6 @@ namespace JoyD.Windows.CS.Toprie
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送模式切换命令
|
||||
/// </summary>
|
||||
/// <param name="mode">图像模式</param>
|
||||
private bool SendModeChangeCommand(ImageMode mode)
|
||||
{
|
||||
// 使用相同的线程锁保护SDK操作
|
||||
lock (_sdkOperationLock)
|
||||
{
|
||||
// 最大重试次数
|
||||
const int maxRetries = 3;
|
||||
// 重试间隔(毫秒)
|
||||
const int retryDelayMs = 100;
|
||||
|
||||
for (int attempt = 0; attempt < maxRetries; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查对象状态和连接状态
|
||||
if (_a8Sdk == null || _connectionStatus != ConnectionStatus.Connected)
|
||||
{
|
||||
Log($"图像模式切换失败: {(attempt > 0 ? "重试中" : "")}SDK实例为空或设备未连接");
|
||||
Thread.Sleep(retryDelayMs);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 将ImageMode枚举转换为int类型
|
||||
_a8Sdk.SetImageMode((int)mode);
|
||||
|
||||
// 短暂延迟,确保设置生效
|
||||
Thread.Sleep(50);
|
||||
|
||||
// 简单验证:尝试读取一个基本属性确认SDK仍在正常工作
|
||||
try
|
||||
{
|
||||
// 使用一个简单的只读操作验证SDK状态
|
||||
int testValue = _a8Sdk.Color_plate; // 使用Color_plate作为验证点
|
||||
Log($"读取色彩模式值用于验证: {testValue}");
|
||||
Log($"图像模式 {mode} 切换成功 (尝试 {attempt + 1}/{maxRetries})");
|
||||
return true;
|
||||
}
|
||||
catch (Exception verifyEx)
|
||||
{
|
||||
// 验证失败,记录日志并准备重试
|
||||
Log($"图像模式切换验证失败 (尝试 {attempt + 1}/{maxRetries}): {verifyEx.Message}");
|
||||
|
||||
// 重试前等待
|
||||
Thread.Sleep(retryDelayMs);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"切换图像模式异常 (尝试 {attempt + 1}/{maxRetries}): {ex.Message}");
|
||||
|
||||
// 增加SDK状态检查,判断是否真的需要触发连接异常
|
||||
try
|
||||
{
|
||||
// 简单的SDK状态检查
|
||||
if (_a8Sdk != null)
|
||||
{
|
||||
// 只读操作,确认SDK仍在响应
|
||||
int testValue = _a8Sdk.Color_plate;
|
||||
Log($"SDK状态检查: 读取色彩模式值 = {testValue}");
|
||||
}
|
||||
}
|
||||
catch (Exception checkEx)
|
||||
{
|
||||
Log($"SDK状态检查失败: {checkEx.Message}");
|
||||
|
||||
// 只有在最后一次尝试且确认SDK状态异常时,才触发连接异常
|
||||
if (attempt == maxRetries - 1)
|
||||
{
|
||||
Log("所有尝试失败且SDK状态异常,触发连接异常事件");
|
||||
OnConnectionException(new ConnectionExceptionEventArgs(checkEx, "图像模式切换导致SDK状态异常"));
|
||||
}
|
||||
}
|
||||
|
||||
// 重试前等待
|
||||
Thread.Sleep(retryDelayMs);
|
||||
}
|
||||
}
|
||||
|
||||
// 所有尝试都失败
|
||||
Log($"图像模式切换最终失败: 已尝试{maxRetries}次");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始接收图像(已弃用,使用HTTP方式替代)
|
||||
/// </summary>
|
||||
|
||||
@@ -2383,30 +2383,6 @@ namespace JoyD.Windows.CS.Toprie
|
||||
Console.WriteLine($"设置系统时间失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 新增方法:设置图像模式
|
||||
public void SetImageMode(int mode)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用SET_IMAGE_MODE命令设置图像模式 - SDK格式
|
||||
string command = $"{CMD_HEAD}:{(int)CMD_TYPE.SET_IMAGE_MODE},{mode}$";
|
||||
|
||||
if (SendCommand(command, out string response))
|
||||
{
|
||||
// 验证响应是否成功
|
||||
if (response != null)
|
||||
{
|
||||
Console.WriteLine($"设置图像模式为: {mode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"设置图像模式失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取视频模式
|
||||
public int GetVideoMode()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user