增加图像模式
This commit is contained in:
@@ -652,6 +652,18 @@ namespace JoyD.Windows.CS.Toprie
|
||||
v8Instance.SetImageMode(mode);
|
||||
}
|
||||
|
||||
// 获取视频模式
|
||||
public int GetVideoMode()
|
||||
{
|
||||
return v8Instance.GetVideoMode();
|
||||
}
|
||||
|
||||
// 设置视频模式
|
||||
public void SetVideoMode(int mode)
|
||||
{
|
||||
v8Instance.SetVideoMode(mode);
|
||||
}
|
||||
|
||||
// 获取图像数据
|
||||
public byte[] GetImageData()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace JoyD.Windows.CS.Toprie
|
||||
namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
partial class Camera
|
||||
{
|
||||
@@ -18,6 +18,14 @@
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.imageBox = new System.Windows.Forms.PictureBox();
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.imageModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.thermalModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.visibleModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fusionMode1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fusionMode2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fusionMode3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fusionMode4ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fusionMode5ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.colorModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.whiteHotToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.blackHotToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@@ -45,9 +53,73 @@
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.imageModeToolStripMenuItem,
|
||||
this.colorModeToolStripMenuItem});
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(161, 48);
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(161, 74);
|
||||
//
|
||||
// imageModeToolStripMenuItem
|
||||
//
|
||||
this.imageModeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.thermalModeToolStripMenuItem,
|
||||
this.visibleModeToolStripMenuItem,
|
||||
this.fusionMode1ToolStripMenuItem,
|
||||
this.fusionMode2ToolStripMenuItem,
|
||||
this.fusionMode3ToolStripMenuItem,
|
||||
this.fusionMode4ToolStripMenuItem,
|
||||
this.fusionMode5ToolStripMenuItem});
|
||||
this.imageModeToolStripMenuItem.Name = "imageModeToolStripMenuItem";
|
||||
this.imageModeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.imageModeToolStripMenuItem.Text = "图像模式";
|
||||
//
|
||||
// thermalModeToolStripMenuItem
|
||||
//
|
||||
this.thermalModeToolStripMenuItem.Name = "thermalModeToolStripMenuItem";
|
||||
this.thermalModeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.thermalModeToolStripMenuItem.Text = "红外模式";
|
||||
this.thermalModeToolStripMenuItem.Click += new System.EventHandler(this.thermalModeToolStripMenuItem_Click);
|
||||
//
|
||||
// visibleModeToolStripMenuItem
|
||||
//
|
||||
this.visibleModeToolStripMenuItem.Name = "visibleModeToolStripMenuItem";
|
||||
this.visibleModeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.visibleModeToolStripMenuItem.Text = "自然模式";
|
||||
this.visibleModeToolStripMenuItem.Click += new System.EventHandler(this.visibleModeToolStripMenuItem_Click);
|
||||
//
|
||||
// fusionMode1ToolStripMenuItem
|
||||
//
|
||||
this.fusionMode1ToolStripMenuItem.Name = "fusionMode1ToolStripMenuItem";
|
||||
this.fusionMode1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.fusionMode1ToolStripMenuItem.Text = "融合模式1";
|
||||
this.fusionMode1ToolStripMenuItem.Click += new System.EventHandler(this.fusionMode1ToolStripMenuItem_Click);
|
||||
//
|
||||
// fusionMode2ToolStripMenuItem
|
||||
//
|
||||
this.fusionMode2ToolStripMenuItem.Name = "fusionMode2ToolStripMenuItem";
|
||||
this.fusionMode2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.fusionMode2ToolStripMenuItem.Text = "融合模式2";
|
||||
this.fusionMode2ToolStripMenuItem.Click += new System.EventHandler(this.fusionMode2ToolStripMenuItem_Click);
|
||||
//
|
||||
// fusionMode3ToolStripMenuItem
|
||||
//
|
||||
this.fusionMode3ToolStripMenuItem.Name = "fusionMode3ToolStripMenuItem";
|
||||
this.fusionMode3ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.fusionMode3ToolStripMenuItem.Text = "融合模式3";
|
||||
this.fusionMode3ToolStripMenuItem.Click += new System.EventHandler(this.fusionMode3ToolStripMenuItem_Click);
|
||||
//
|
||||
// fusionMode4ToolStripMenuItem
|
||||
//
|
||||
this.fusionMode4ToolStripMenuItem.Name = "fusionMode4ToolStripMenuItem";
|
||||
this.fusionMode4ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.fusionMode4ToolStripMenuItem.Text = "融合模式4";
|
||||
this.fusionMode4ToolStripMenuItem.Click += new System.EventHandler(this.fusionMode4ToolStripMenuItem_Click);
|
||||
//
|
||||
// fusionMode5ToolStripMenuItem
|
||||
//
|
||||
this.fusionMode5ToolStripMenuItem.Name = "fusionMode5ToolStripMenuItem";
|
||||
this.fusionMode5ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.fusionMode5ToolStripMenuItem.Text = "融合模式5";
|
||||
this.fusionMode5ToolStripMenuItem.Click += new System.EventHandler(this.fusionMode5ToolStripMenuItem_Click);
|
||||
//
|
||||
// colorModeToolStripMenuItem
|
||||
//
|
||||
@@ -149,5 +221,13 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem ironGrayToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem redHotToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem rainbow2ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem imageModeToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem thermalModeToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem visibleModeToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem fusionMode1ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem fusionMode2ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem fusionMode3ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem fusionMode4ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem fusionMode5ToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -977,7 +977,16 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
try
|
||||
{
|
||||
// 首先清除所有菜单项的选中状态
|
||||
// 清除视频模式菜单项的选中状态
|
||||
thermalModeToolStripMenuItem.Checked = false;
|
||||
visibleModeToolStripMenuItem.Checked = false;
|
||||
fusionMode1ToolStripMenuItem.Checked = false;
|
||||
fusionMode2ToolStripMenuItem.Checked = false;
|
||||
fusionMode3ToolStripMenuItem.Checked = false;
|
||||
fusionMode4ToolStripMenuItem.Checked = false;
|
||||
fusionMode5ToolStripMenuItem.Checked = false;
|
||||
|
||||
// 清除色彩模式菜单项的选中状态
|
||||
whiteHotToolStripMenuItem.Checked = false;
|
||||
blackHotToolStripMenuItem.Checked = false;
|
||||
ironRedToolStripMenuItem.Checked = false;
|
||||
@@ -1028,6 +1037,40 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
Console.WriteLine("获取当前色彩模式失败: " + ex.Message);
|
||||
}
|
||||
|
||||
// 更新视频模式菜单项的选中状态
|
||||
try
|
||||
{
|
||||
int currentMode = _deviceManager.GetCurrentVideoMode();
|
||||
switch (currentMode)
|
||||
{
|
||||
case 0:
|
||||
thermalModeToolStripMenuItem.Checked = true;
|
||||
break;
|
||||
case 1:
|
||||
visibleModeToolStripMenuItem.Checked = true;
|
||||
break;
|
||||
case 2:
|
||||
fusionMode1ToolStripMenuItem.Checked = true;
|
||||
break;
|
||||
case 3:
|
||||
fusionMode2ToolStripMenuItem.Checked = true;
|
||||
break;
|
||||
case 4:
|
||||
fusionMode3ToolStripMenuItem.Checked = true;
|
||||
break;
|
||||
case 5:
|
||||
fusionMode4ToolStripMenuItem.Checked = true;
|
||||
break;
|
||||
case 6:
|
||||
fusionMode5ToolStripMenuItem.Checked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("获取当前视频模式失败: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1192,6 +1235,150 @@ namespace JoyD.Windows.CS.Toprie
|
||||
|
||||
#endregion
|
||||
|
||||
#region 视频模式切换方法
|
||||
|
||||
/// <summary>
|
||||
/// 红外模式
|
||||
/// </summary>
|
||||
private void thermalModeToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_deviceManager != null)
|
||||
{
|
||||
Console.WriteLine("切换到红外模式");
|
||||
_deviceManager.SetVideoMode(0);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("切换到红外模式失败: " + ex.Message);
|
||||
ShowError("切换到红外模式失败");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自然模式
|
||||
/// </summary>
|
||||
private void visibleModeToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_deviceManager != null)
|
||||
{
|
||||
Console.WriteLine("切换到自然模式");
|
||||
_deviceManager.SetVideoMode(1);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("切换到自然模式失败: " + ex.Message);
|
||||
ShowError("切换到自然模式失败");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合模式1
|
||||
/// </summary>
|
||||
private void fusionMode1ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_deviceManager != null)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式1");
|
||||
_deviceManager.SetVideoMode(2);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式1失败: " + ex.Message);
|
||||
ShowError("切换到融合模式1失败");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合模式2
|
||||
/// </summary>
|
||||
private void fusionMode2ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_deviceManager != null)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式2");
|
||||
_deviceManager.SetVideoMode(3);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式2失败: " + ex.Message);
|
||||
ShowError("切换到融合模式2失败");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合模式3
|
||||
/// </summary>
|
||||
private void fusionMode3ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_deviceManager != null)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式3");
|
||||
_deviceManager.SetVideoMode(4);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式3失败: " + ex.Message);
|
||||
ShowError("切换到融合模式3失败");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合模式4
|
||||
/// </summary>
|
||||
private void fusionMode4ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_deviceManager != null)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式4");
|
||||
_deviceManager.SetVideoMode(5);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式4失败: " + ex.Message);
|
||||
ShowError("切换到融合模式4失败");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合模式5
|
||||
/// </summary>
|
||||
private void fusionMode5ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_deviceManager != null)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式5");
|
||||
_deviceManager.SetVideoMode(6);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("切换到融合模式5失败: " + ex.Message);
|
||||
ShowError("切换到融合模式5失败");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 清理资源
|
||||
/// </summary>
|
||||
|
||||
@@ -2229,6 +2229,98 @@ namespace JoyD.Windows.CS.Toprie
|
||||
CurrentImageMode = mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置视频模式
|
||||
/// </summary>
|
||||
/// <param name="videoMode">视频模式(0:红外,1:自然,2-6:融合模式1-5)</param>
|
||||
public void SetVideoMode(int videoMode)
|
||||
{
|
||||
// 验证参数范围
|
||||
if (videoMode < 0 || videoMode > 6)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("videoMode", "视频模式必须在0-6范围内");
|
||||
}
|
||||
|
||||
// 调用SDK设置视频模式
|
||||
SendVideoModeCommand(videoMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前视频模式
|
||||
/// </summary>
|
||||
/// <returns>当前视频模式值(0-6)</returns>
|
||||
public int GetCurrentVideoMode()
|
||||
{
|
||||
lock (_sdkOperationLock)
|
||||
{
|
||||
// 验证连接状态
|
||||
if (_connectionStatus != ConnectionStatus.Connected || _a8Sdk == null)
|
||||
{
|
||||
throw new InvalidOperationException("设备未连接");
|
||||
}
|
||||
|
||||
// 调用SDK获取视频模式
|
||||
return _a8Sdk.GetVideoMode();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送视频模式变更命令到设备
|
||||
/// </summary>
|
||||
/// <param name="videoMode">视频模式值</param>
|
||||
private void SendVideoModeCommand(int videoMode)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// 调用SDK设置视频模式
|
||||
_a8Sdk.SetVideoMode(videoMode);
|
||||
|
||||
// 短暂延迟,确保设置生效
|
||||
Thread.Sleep(50);
|
||||
|
||||
// 简单验证:尝试读取视频模式确认设置成功
|
||||
int currentMode = _a8Sdk.GetVideoMode();
|
||||
if (currentMode == videoMode)
|
||||
{
|
||||
Log($"视频模式切换成功,当前模式: {videoMode}");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"视频模式验证失败,期望: {videoMode},实际: {currentMode}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"视频模式切换异常 (尝试 {attempt + 1}/{maxRetries}): {ex.Message}");
|
||||
}
|
||||
|
||||
// 重试前短暂延迟
|
||||
if (attempt < maxRetries - 1)
|
||||
{
|
||||
Thread.Sleep(retryDelayMs);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception($"视频模式切换失败,已重试 {maxRetries} 次");
|
||||
}
|
||||
}
|
||||
|
||||
// 用于保护SDK操作的线程锁
|
||||
private readonly object _sdkOperationLock = new object();
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
SET_AUTO_SHUTTER = 1, // 保持为1,不要与其他命令冲突
|
||||
SET_MIRROR_VIDEO = 3,
|
||||
SET_VIDEO_MODE = 4,
|
||||
GET_VIDEO_MODE = 28,
|
||||
SET_AREA_POS = 5,
|
||||
SET_SPOT_POS = 6,
|
||||
SET_LINE_POS = 7,
|
||||
@@ -2247,6 +2248,33 @@ namespace JoyD.Windows.CS.Toprie
|
||||
}
|
||||
}
|
||||
|
||||
// 获取视频模式
|
||||
public int GetVideoMode()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Video_mode;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"获取视频模式失败: {ex.Message}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置视频模式
|
||||
public void SetVideoMode(int mode)
|
||||
{
|
||||
try
|
||||
{
|
||||
Video_mode = mode;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"设置视频模式失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 新增方法:获取图像数据
|
||||
public byte[] GetImageData()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user