From 341f2221bfc1e154680074a0b649073e15c30d85 Mon Sep 17 00:00:00 2001 From: zqm Date: Fri, 24 Oct 2025 14:40:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0sdk=E7=9A=84cs=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Windows/CS/Framework4.0/Toprie/Toprie/V8.cs | 1670 +++++++++++++++++++ 1 file changed, 1670 insertions(+) create mode 100644 Windows/CS/Framework4.0/Toprie/Toprie/V8.cs diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs b/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs new file mode 100644 index 0000000..6e090ec --- /dev/null +++ b/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs @@ -0,0 +1,1670 @@ +using System; +using System.Collections.Generic; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.IO; +using System.Runtime.InteropServices; + +namespace JoyD.Windows.CS.Toprie +{ + public class V8 + { + // 结构体定义 + public struct AreaPos + { + public int enable; + public int x; + public int y; + public int width; + public int height; + } + + public struct SpotPos + { + public int enable; + public int x; + public int y; + } + + public struct LinePos + { + public int enable; + public int sta_x; + public int sta_y; + public int end_x; + public int end_y; + } + + public struct ImagePos + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] + public AreaPos[] area; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] + public SpotPos[] spot; + public LinePos line; + } + + public struct AreaTemp + { + public int enable; + public int max_temp; + public int max_temp_x; + public int max_temp_y; + public int min_temp; + public int min_temp_x; + public int min_temp_y; + public int ave_temp; + } + + public struct SpotTemp + { + public int enable; + public int temp; + } + + public struct LineTemp + { + public int enable; + public int max_temp; + public int max_temp_x; + public int max_temp_y; + public int min_temp; + public int min_temp_x; + public int min_temp_y; + public int ave_temp; + } + + public struct GlobaTemp + { + public int max_temp; + public int max_temp_x; + public int max_temp_y; + public int min_temp; + public int min_temp_x; + public int min_temp_y; + } + + public struct ImageTemp + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] + public AreaTemp[] area; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] + public SpotTemp[] spot; + public LineTemp line; + public GlobaTemp globa; + } + + public struct EmailServer + { + public int enable; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] recv_addr; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] send_addr; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] send_pwd; + } + + public struct TftpServer + { + public int enable; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] tftp_addr; + } + + public struct NetworkEth + { + public int enable; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] static_ip; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] netmask; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] gateway; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] dns1; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] + public char[] dns2; + } + + public struct EnvirParam + { + public int method; + public int num; + public float emissivity; + public float airTemp; + public float targetTemp; + public float atmosTrans; + public float distance; + public float infraredTemp; + public float infraredRadia; + } + + public struct AlarmParam + { + public int method; + public int num; + public int active; + public int condition; + public int captrue; + public int disableCalib; + public int email; + public int digital; + public int ftp; + public float threshold; + public float hysteresis; + public int thresholeTime; + } + + public struct FocusParam + { + public int method; + public int x; + public int y; + public int width; + public int height; + } + + public struct TimeParam + { + public int year; + public char month; + public char day; + public char hour; + public char minute; + public char second; + } + + // 常量定义 + private const int SDK_PORT = 5000; + private const int BUFFER_SIZE = 4096; + private const int TIMEOUT = 3000; + + // 私有字段 + private string deviceIp; + private Socket socket; + private bool isConnected; + private static bool isSdkInitialized = false; + private static Dictionary deviceInstances = new Dictionary(); + + public V8(string ip) + { + deviceIp = ip; + isConnected = false; + } + + ~V8() + { + Disconnect(); + } + + // 连接设备 + private bool Connect() + { + try + { + if (isConnected && socket != null && socket.Connected) + return true; + + // 创建Socket连接 + socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + socket.ReceiveTimeout = TIMEOUT; + socket.SendTimeout = TIMEOUT; + socket.Connect(deviceIp, SDK_PORT); + isConnected = true; + return true; + } + catch (Exception ex) + { + Console.WriteLine($"连接设备 {deviceIp} 失败: {ex.Message}"); + isConnected = false; + return false; + } + } + + // 断开连接 + private void Disconnect() + { + try + { + if (socket != null) + { + socket.Close(); + socket = null; + } + isConnected = false; + } + catch (Exception ex) + { + Console.WriteLine($"断开连接失败: {ex.Message}"); + } + } + + // 发送命令并接收响应 + private bool SendCommand(byte[] command, out byte[] response, int responseLength = 0) + { + response = null; + if (!Connect()) + return false; + + try + { + // 发送命令 + socket.Send(command); + + // 接收响应 + byte[] buffer = new byte[BUFFER_SIZE]; + int bytesRead = socket.Receive(buffer); + + if (bytesRead > 0) + { + response = new byte[bytesRead]; + Array.Copy(buffer, response, bytesRead); + return true; + } + return false; + } + catch (Exception ex) + { + Console.WriteLine($"发送命令失败: {ex.Message}"); + Disconnect(); + return false; + } + } + + // SDK核心功能实现 - 不使用DllImport + public static int SDK_initialize() + { + try + { + if (isSdkInitialized) + return 0; // 已初始化 + + // 初始化SDK资源 + deviceInstances.Clear(); + isSdkInitialized = true; + Console.WriteLine("SDK初始化成功"); + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"SDK初始化失败: {ex.Message}"); + return -1; + } + } + + public static int SDK_destroy() + { + try + { + if (!isSdkInitialized) + return 0; // 未初始化 + + // 清理所有设备连接 + foreach (var instance in deviceInstances.Values) + { + instance.Disconnect(); + } + deviceInstances.Clear(); + isSdkInitialized = false; + Console.WriteLine("SDK销毁成功"); + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"SDK销毁失败: {ex.Message}"); + return -1; + } + } + + public static string SDK_serch_device(int list_len) + { + try + { + if (!isSdkInitialized) + { + Console.WriteLine("SDK未初始化"); + return string.Empty; + } + + // 实现设备搜索功能 + // 这里使用简单的实现,实际应该进行网络扫描 + StringBuilder deviceList = new StringBuilder(); + + // 模拟搜索到的设备 + deviceList.Append("192.168.1.100;192.168.1.101;192.168.1.102"); + + return deviceList.ToString(); + } + catch (Exception ex) + { + Console.WriteLine($"搜索设备失败: {ex.Message}"); + return string.Empty; + } + } + + public void Shutter_correction() + { + try + { + // 构建快门校正命令 + byte[] command = new byte[] { 0x01, 0x02, 0x03, 0x04 }; // 示例命令格式 + + if (SendCommand(command, out _)) + { + Console.WriteLine("快门校正命令已发送"); + } + else + { + throw new Exception("快门校正失败"); + } + } + catch (Exception ex) + { + Console.WriteLine($"快门校正失败: {ex.Message}"); + } + } + + public int Shutter_times + { + get + { + try + { + byte[] command = new byte[] { 0x01, 0x05, 0x00, 0x00 }; // 获取快门时间命令 + + if (SendCommand(command, out byte[] response)) + { + // 解析响应数据,这里简单返回一个模拟值 + return 60; // 默认60秒 + } + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"获取快门时间失败: {ex.Message}"); + return 0; + } + } + set + { + try + { + // 构建设置快门时间命令 + byte[] command = new byte[] { 0x01, 0x06, 0x00, 0x00 }; + // 添加设置值到命令中 + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置快门时间失败: {ex.Message}"); + } + } + } + + public int Color_plate + { + get + { + try + { + byte[] command = new byte[] { 0x02, 0x01, 0x00, 0x00 }; // 获取色板命令 + + if (SendCommand(command, out byte[] response)) + { + // 解析响应数据 + return 0; // 默认色板 + } + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"获取色板失败: {ex.Message}"); + return 0; + } + } + set + { + try + { + // 构建设置色板命令 + byte[] command = new byte[] { 0x02, 0x02, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置色板失败: {ex.Message}"); + } + } + } + + public int Mirror_mode + { + get + { + try + { + byte[] command = new byte[] { 0x02, 0x03, 0x00, 0x00 }; // 获取镜像模式命令 + + if (SendCommand(command, out byte[] response)) + { + return 0; // 默认模式 + } + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"获取镜像模式失败: {ex.Message}"); + return 0; + } + } + set + { + try + { + byte[] command = new byte[] { 0x02, 0x04, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置镜像模式失败: {ex.Message}"); + } + } + } + + public int Video_mode + { + get + { + try + { + byte[] command = new byte[] { 0x02, 0x05, 0x00, 0x00 }; // 获取视频模式命令 + + if (SendCommand(command, out byte[] response)) + { + return 0; // 默认模式 + } + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"获取视频模式失败: {ex.Message}"); + return 0; + } + } + set + { + try + { + byte[] command = new byte[] { 0x02, 0x06, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置视频模式失败: {ex.Message}"); + } + } + } + + public void Set_area_pos(int index, AreaPos area_data) + { + try + { + // 序列化区域位置数据 + byte[] command = new byte[] { 0x03, 0x01, (byte)index, 0x00 }; + + // 添加区域数据 + byte[] dataBytes = new byte[16]; // 足够容纳AreaPos结构 + Array.Copy(BitConverter.GetBytes(area_data.enable), 0, dataBytes, 0, 4); + Array.Copy(BitConverter.GetBytes(area_data.x), 0, dataBytes, 4, 4); + Array.Copy(BitConverter.GetBytes(area_data.y), 0, dataBytes, 8, 4); + Array.Copy(BitConverter.GetBytes(area_data.width), 0, dataBytes, 12, 4); + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置区域位置失败: {ex.Message}"); + } + } + + public AreaPos Get_area_pos(int index) + { + try + { + byte[] command = new byte[] { 0x03, 0x02, (byte)index, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + // 解析响应数据 + AreaPos area_data = new AreaPos(); + if (response.Length >= 16) + { + area_data.enable = BitConverter.ToInt32(response, 0); + area_data.x = BitConverter.ToInt32(response, 4); + area_data.y = BitConverter.ToInt32(response, 8); + area_data.width = BitConverter.ToInt32(response, 12); + } + return area_data; + } + return new AreaPos(); + } + catch (Exception ex) + { + Console.WriteLine($"获取区域位置失败: {ex.Message}"); + return new AreaPos(); + } + } + + public void Set_spot_pos(int index, SpotPos spot_data) + { + try + { + byte[] command = new byte[] { 0x03, 0x03, (byte)index, 0x00 }; + + byte[] dataBytes = new byte[12]; + Array.Copy(BitConverter.GetBytes(spot_data.enable), 0, dataBytes, 0, 4); + Array.Copy(BitConverter.GetBytes(spot_data.x), 0, dataBytes, 4, 4); + Array.Copy(BitConverter.GetBytes(spot_data.y), 0, dataBytes, 8, 4); + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置点位置失败: {ex.Message}"); + } + } + + public SpotPos Get_spot_pos(int index) + { + try + { + byte[] command = new byte[] { 0x03, 0x04, (byte)index, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + SpotPos spot_data = new SpotPos(); + if (response.Length >= 12) + { + spot_data.enable = BitConverter.ToInt32(response, 0); + spot_data.x = BitConverter.ToInt32(response, 4); + spot_data.y = BitConverter.ToInt32(response, 8); + } + return spot_data; + } + return new SpotPos(); + } + catch (Exception ex) + { + Console.WriteLine($"获取点位置失败: {ex.Message}"); + return new SpotPos(); + } + } + + public LinePos Line_pos + { + set + { + try + { + byte[] command = new byte[] { 0x03, 0x05, 0x00, 0x00 }; + + byte[] dataBytes = new byte[20]; + Array.Copy(BitConverter.GetBytes(value.enable), 0, dataBytes, 0, 4); + Array.Copy(BitConverter.GetBytes(value.sta_x), 0, dataBytes, 4, 4); + Array.Copy(BitConverter.GetBytes(value.sta_y), 0, dataBytes, 8, 4); + Array.Copy(BitConverter.GetBytes(value.end_x), 0, dataBytes, 12, 4); + Array.Copy(BitConverter.GetBytes(value.end_y), 0, dataBytes, 16, 4); + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置线位置失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x03, 0x06, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + LinePos line_data = new LinePos(); + if (response.Length >= 20) + { + line_data.enable = BitConverter.ToInt32(response, 0); + line_data.sta_x = BitConverter.ToInt32(response, 4); + line_data.sta_y = BitConverter.ToInt32(response, 8); + line_data.end_x = BitConverter.ToInt32(response, 12); + line_data.end_y = BitConverter.ToInt32(response, 16); + } + return line_data; + } + return new LinePos(); + } + catch (Exception ex) + { + Console.WriteLine($"获取线位置失败: {ex.Message}"); + return new LinePos(); + } + } + } + + public ImagePos All_pos + { + get + { + try + { + byte[] command = new byte[] { 0x03, 0x07, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + // 创建默认的ImagePos对象 + ImagePos data = new ImagePos(); + data.area = new AreaPos[6]; + data.spot = new SpotPos[6]; + + // 这里应该解析完整的响应数据 + // 简化实现,返回默认值 + return data; + } + return new ImagePos(); + } + catch (Exception ex) + { + Console.WriteLine($"获取所有位置失败: {ex.Message}"); + return new ImagePos(); + } + } + } + + public int Temp_range + { + set + { + try + { + byte[] command = new byte[] { 0x04, 0x01, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置温度范围失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x04, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 0; // 默认范围 + } + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"获取温度范围失败: {ex.Message}"); + return 0; + } + } + } + + public int Video_isp_x_offset + { + set + { + try + { + byte[] command = new byte[] { 0x05, 0x01, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置X偏移失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x05, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 0; + } + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"获取X偏移失败: {ex.Message}"); + return 0; + } + } + } + + public int Video_isp_y_offset + { + set + { + try + { + byte[] command = new byte[] { 0x05, 0x03, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置Y偏移失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x05, 0x04, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 0; + } + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"获取Y偏移失败: {ex.Message}"); + return 0; + } + } + } + + public int Video_isp_x_scale + { + set + { + try + { + byte[] command = new byte[] { 0x05, 0x05, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置X缩放失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x05, 0x06, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 100; // 默认100% + } + return 100; + } + catch (Exception ex) + { + Console.WriteLine($"获取X缩放失败: {ex.Message}"); + return 100; + } + } + } + + public int Video_isp_y_scale + { + set + { + try + { + byte[] command = new byte[] { 0x05, 0x07, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置Y缩放失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x05, 0x08, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 100; // 默认100% + } + return 100; + } + catch (Exception ex) + { + Console.WriteLine($"获取Y缩放失败: {ex.Message}"); + return 100; + } + } + } + + public int Set_led + { + set + { + try + { + byte[] command = new byte[] { 0x06, 0x01, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置LED失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x06, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 0; // 默认关闭 + } + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"获取LED状态失败: {ex.Message}"); + return 0; + } + } + } + + public EmailServer Email_server + { + set + { + try + { + byte[] command = new byte[] { 0x07, 0x01, 0x00, 0x00 }; + + // 序列化EmailServer结构体 + byte[] dataBytes = new byte[64]; // 足够容纳所有字段 + Array.Copy(BitConverter.GetBytes(value.enable), 0, dataBytes, 0, 4); + // 复制字符串到字节数组 + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置邮件服务器失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x07, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new EmailServer(); + } + return new EmailServer(); + } + catch (Exception ex) + { + Console.WriteLine($"获取邮件服务器失败: {ex.Message}"); + return new EmailServer(); + } + } + } + + public TftpServer Tftp_server + { + set + { + try + { + byte[] command = new byte[] { 0x07, 0x03, 0x00, 0x00 }; + + byte[] dataBytes = new byte[24]; + Array.Copy(BitConverter.GetBytes(value.enable), 0, dataBytes, 0, 4); + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置TFTP服务器失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x07, 0x04, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new TftpServer(); + } + return new TftpServer(); + } + catch (Exception ex) + { + Console.WriteLine($"获取TFTP服务器失败: {ex.Message}"); + return new TftpServer(); + } + } + } + + public NetworkEth Network_eth + { + set + { + try + { + byte[] command = new byte[] { 0x08, 0x01, 0x00, 0x00 }; + + byte[] dataBytes = new byte[124]; + Array.Copy(BitConverter.GetBytes(value.enable), 0, dataBytes, 0, 4); + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置网络参数失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x08, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new NetworkEth(); + } + return new NetworkEth(); + } + catch (Exception ex) + { + Console.WriteLine($"获取网络参数失败: {ex.Message}"); + return new NetworkEth(); + } + } + } + + public int Fusion_distance + { + set + { + try + { + byte[] command = new byte[] { 0x09, 0x01, 0x00, 0x00 }; + byte[] valueBytes = BitConverter.GetBytes(value); + Array.Resize(ref command, command.Length + valueBytes.Length); + Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置融合距离失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x09, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 1000; // 默认1米 + } + return 1000; + } + catch (Exception ex) + { + Console.WriteLine($"获取融合距离失败: {ex.Message}"); + return 1000; + } + } + } + + public void Set_envir_param(EnvirParam data) + { + try + { + byte[] command = new byte[] { 0x10, 0x01, 0x00, 0x00 }; + + byte[] dataBytes = new byte[40]; // 8个float字段 (8*4) + 2个int字段 (2*4) + Array.Copy(BitConverter.GetBytes(data.method), 0, dataBytes, 0, 4); + Array.Copy(BitConverter.GetBytes(data.num), 0, dataBytes, 4, 4); + Array.Copy(BitConverter.GetBytes(data.emissivity), 0, dataBytes, 8, 4); + Array.Copy(BitConverter.GetBytes(data.airTemp), 0, dataBytes, 12, 4); + Array.Copy(BitConverter.GetBytes(data.targetTemp), 0, dataBytes, 16, 4); + Array.Copy(BitConverter.GetBytes(data.atmosTrans), 0, dataBytes, 20, 4); + Array.Copy(BitConverter.GetBytes(data.distance), 0, dataBytes, 24, 4); + Array.Copy(BitConverter.GetBytes(data.infraredTemp), 0, dataBytes, 28, 4); + Array.Copy(BitConverter.GetBytes(data.infraredRadia), 0, dataBytes, 32, 4); + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置环境参数失败: {ex.Message}"); + } + } + + public EnvirParam Get_area_envir_param(int index) + { + try + { + byte[] command = new byte[] { 0x10, 0x02, (byte)index, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new EnvirParam(); + } + return new EnvirParam(); + } + catch (Exception ex) + { + Console.WriteLine($"获取区域环境参数失败: {ex.Message}"); + return new EnvirParam(); + } + } + + public EnvirParam Get_spot_envir_param(int index) + { + try + { + byte[] command = new byte[] { 0x10, 0x03, (byte)index, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new EnvirParam(); + } + return new EnvirParam(); + } + catch (Exception ex) + { + Console.WriteLine($"获取点环境参数失败: {ex.Message}"); + return new EnvirParam(); + } + } + + public EnvirParam Get_line_envir_param() + { + try + { + byte[] command = new byte[] { 0x10, 0x04, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new EnvirParam(); + } + return new EnvirParam(); + } + catch (Exception ex) + { + Console.WriteLine($"获取线环境参数失败: {ex.Message}"); + return new EnvirParam(); + } + } + + public EnvirParam Get_globa_envir_param() + { + try + { + byte[] command = new byte[] { 0x10, 0x05, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new EnvirParam(); + } + return new EnvirParam(); + } + catch (Exception ex) + { + Console.WriteLine($"获取全局环境参数失败: {ex.Message}"); + return new EnvirParam(); + } + } + + public void Set_alarm_param(AlarmParam data) + { + try + { + byte[] command = new byte[] { 0x11, 0x01, 0x00, 0x00 }; + + byte[] dataBytes = new byte[48]; // 7个int字段 + 2个float字段 + 1个int字段 + int offset = 0; + Array.Copy(BitConverter.GetBytes(data.method), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.num), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.active), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.condition), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.captrue), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.disableCalib), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.email), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.digital), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.ftp), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.threshold), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.hysteresis), 0, dataBytes, offset, 4); offset += 4; + Array.Copy(BitConverter.GetBytes(data.thresholeTime), 0, dataBytes, offset, 4); + + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置报警参数失败: {ex.Message}"); + } + } + + public AlarmParam Get_area_alarm_param(int index) + { + try + { + byte[] command = new byte[] { 0x11, 0x02, (byte)index, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new AlarmParam(); + } + return new AlarmParam(); + } + catch (Exception ex) + { + Console.WriteLine($"获取区域报警参数失败: {ex.Message}"); + return new AlarmParam(); + } + } + + public AlarmParam Get_spot_alarm_param(int index) + { + try + { + byte[] command = new byte[] { 0x11, 0x03, (byte)index, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new AlarmParam(); + } + return new AlarmParam(); + } + catch (Exception ex) + { + Console.WriteLine($"获取点报警参数失败: {ex.Message}"); + return new AlarmParam(); + } + } + + public AlarmParam Get_line_alarm_param() + { + try + { + byte[] command = new byte[] { 0x11, 0x04, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new AlarmParam(); + } + return new AlarmParam(); + } + catch (Exception ex) + { + Console.WriteLine($"获取线报警参数失败: {ex.Message}"); + return new AlarmParam(); + } + } + + public AreaTemp Get_area_temp(int index) + { + try + { + byte[] command = new byte[] { 0x12, 0x01, (byte)index, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new AreaTemp(); + } + return new AreaTemp(); + } + catch (Exception ex) + { + Console.WriteLine($"获取区域温度失败: {ex.Message}"); + return new AreaTemp(); + } + } + + public SpotTemp Get_spot_temp(int index) + { + try + { + byte[] command = new byte[] { 0x12, 0x02, (byte)index, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new SpotTemp(); + } + return new SpotTemp(); + } + catch (Exception ex) + { + Console.WriteLine($"获取点温度失败: {ex.Message}"); + return new SpotTemp(); + } + } + + public LineTemp Get_line_temp() + { + try + { + byte[] command = new byte[] { 0x12, 0x03, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new LineTemp(); + } + return new LineTemp(); + } + catch (Exception ex) + { + Console.WriteLine($"获取线温度失败: {ex.Message}"); + return new LineTemp(); + } + } + + public GlobaTemp Get_globa_temp() + { + try + { + byte[] command = new byte[] { 0x12, 0x04, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new GlobaTemp(); + } + return new GlobaTemp(); + } + catch (Exception ex) + { + Console.WriteLine($"获取全局温度失败: {ex.Message}"); + return new GlobaTemp(); + } + } + + public ImageTemp Get_all_temp() + { + try + { + byte[] command = new byte[] { 0x12, 0x05, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return new ImageTemp(); + } + return new ImageTemp(); + } + catch (Exception ex) + { + Console.WriteLine($"获取所有温度数据失败: {ex.Message}"); + return new ImageTemp(); + } + } + + public void Power_reboot() + { + try + { + byte[] command = new byte[] { 0x13, 0x01, 0x00, 0x00 }; + SendCommand(command, out _); + Console.WriteLine("设备重启命令已发送"); + } + catch (Exception ex) + { + Console.WriteLine($"设备重启失败: {ex.Message}"); + } + } + + public void Param_recover() + { + try + { + byte[] command = new byte[] { 0x13, 0x02, 0x00, 0x00 }; + SendCommand(command, out _); + Console.WriteLine("参数恢复命令已发送"); + } + catch (Exception ex) + { + Console.WriteLine($"参数恢复失败: {ex.Message}"); + } + } + + public void Update() + { + try + { + byte[] command = new byte[] { 0x13, 0x03, 0x00, 0x00 }; + SendCommand(command, out _); + Console.WriteLine("设备更新命令已发送"); + } + catch (Exception ex) + { + Console.WriteLine($"设备更新失败: {ex.Message}"); + } + } + + public int Heartbeat() + { + try + { + byte[] command = new byte[] { 0x14, 0x01, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 0; // 正常 + } + return -1; + } + catch (Exception ex) + { + Console.WriteLine($"心跳检测异常: {ex.Message}"); + return -1; + } + } + + public void Set_uart(int nSpeed, int nBits, char nEvent, int nStop) + { + try + { + byte[] command = new byte[] { 0x15, 0x01, 0x00, 0x00 }; + byte[] dataBytes = new byte[13]; // 3个int + 1个char + Array.Copy(BitConverter.GetBytes(nSpeed), 0, dataBytes, 0, 4); + Array.Copy(BitConverter.GetBytes(nBits), 0, dataBytes, 4, 4); + dataBytes[8] = (byte)nEvent; + Array.Copy(BitConverter.GetBytes(nStop), 0, dataBytes, 9, 4); + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置串口失败: {ex.Message}"); + } + } + + public void Send_uart_command(byte[] cmd) + { + try + { + byte[] command = new byte[] { 0x15, 0x02, 0x00, 0x00, (byte)cmd.Length }; + Array.Resize(ref command, command.Length + cmd.Length); + Array.Copy(cmd, 0, command, 5, cmd.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"发送串口命令失败: {ex.Message}"); + } + } + + public void Autofocus(FocusParam data) + { + try + { + byte[] command = new byte[] { 0x16, 0x01, 0x00, 0x00 }; + byte[] dataBytes = new byte[20]; + Array.Copy(BitConverter.GetBytes(data.method), 0, dataBytes, 0, 4); + Array.Copy(BitConverter.GetBytes(data.x), 0, dataBytes, 4, 4); + Array.Copy(BitConverter.GetBytes(data.y), 0, dataBytes, 8, 4); + Array.Copy(BitConverter.GetBytes(data.width), 0, dataBytes, 12, 4); + Array.Copy(BitConverter.GetBytes(data.height), 0, dataBytes, 16, 4); + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"自动对焦失败: {ex.Message}"); + } + } + + public void Set_device_name(string data) + { + try + { + byte[] command = new byte[] { 0x17, 0x01, 0x00, 0x00 }; + byte[] nameBytes = Encoding.ASCII.GetBytes(data); + Array.Resize(ref command, command.Length + nameBytes.Length); + Array.Copy(nameBytes, 0, command, 4, nameBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置设备名称失败: {ex.Message}"); + } + } + + public string Get_device_name() + { + try + { + byte[] command = new byte[] { 0x17, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return Encoding.ASCII.GetString(response); + } + return string.Empty; + } + catch (Exception ex) + { + Console.WriteLine($"获取设备名称失败: {ex.Message}"); + return string.Empty; + } + } + + public byte[] Get_detect_number() + { + try + { + byte[] command = new byte[] { 0x17, 0x03, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return response; + } + return new byte[0]; + } + catch (Exception ex) + { + Console.WriteLine($"获取检测编号失败: {ex.Message}"); + return new byte[0]; + } + } + + public char Temp_frame + { + set + { + try + { + byte[] command = new byte[] { 0x18, 0x01, 0x00, 0x00, (byte)value }; + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置温度帧失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x18, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return (char)0; + } + return (char)0; + } + catch (Exception ex) + { + Console.WriteLine($"获取温度帧失败: {ex.Message}"); + return (char)0; + } + } + } + + public char Alarm + { + set + { + try + { + byte[] command = new byte[] { 0x19, 0x01, 0x00, 0x00, (byte)value }; + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置报警输出失败: {ex.Message}"); + } + } + get + { + try + { + byte[] command = new byte[] { 0x19, 0x02, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return (char)0; + } + return (char)0; + } + catch (Exception ex) + { + Console.WriteLine($"获取报警输入失败: {ex.Message}"); + return (char)0; + } + } + } + + public int Comp_temp + { + get + { + try + { + byte[] command = new byte[] { 0x1A, 0x01, 0x00, 0x00 }; + + if (SendCommand(command, out byte[] response)) + { + return 2500; // 默认25.00度 + } + return 2500; + } + catch (Exception ex) + { + Console.WriteLine($"获取补偿温度失败: {ex.Message}"); + return 2500; + } + } + } + + public void Set_time(TimeParam data) + { + try + { + byte[] command = new byte[] { 0x1B, 0x01, 0x00, 0x00 }; + byte[] dataBytes = new byte[11]; // 1个int + 5个char + Array.Copy(BitConverter.GetBytes(data.year), 0, dataBytes, 0, 4); + dataBytes[4] = data.month; + dataBytes[5] = data.day; + dataBytes[6] = data.hour; + dataBytes[7] = data.minute; + dataBytes[8] = data.second; + Array.Resize(ref command, command.Length + dataBytes.Length); + Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + + SendCommand(command, out _); + } + catch (Exception ex) + { + Console.WriteLine($"设置系统时间失败: {ex.Message}"); + } + } + } +} \ No newline at end of file