From 5a3d8dd975a3fde4c29d9618cfe76b4e0a9481b8 Mon Sep 17 00:00:00 2001 From: zqm Date: Mon, 27 Oct 2025 13:18:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Toprie/Toprie/DeviceManager.cs | 3 + Windows/CS/Framework4.0/Toprie/Toprie/V8.cs | 1197 ++++++++++++----- 2 files changed, 848 insertions(+), 352 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs b/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs index 0fe27e3..f755a84 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/DeviceManager.cs @@ -2260,6 +2260,9 @@ namespace JoyD.Windows.CS.Toprie return; } + // 当所有连接尝试都失败时,明确更新状态为Disconnected + UpdateConnectionStatus(ConnectionStatus.Disconnected, "所有连接尝试失败"); + // 设置下一次重连的时间间隔 int retryInterval = _reconnectInterval; if (_currentReconnectAttempt % 5 == 0) // 每5次尝试后增加间隔 diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs b/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs index 21aa4da..8783cb7 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading; using System.IO; using System.Runtime.InteropServices; +using System.Net; namespace JoyD.Windows.CS.Toprie { @@ -16,6 +17,108 @@ namespace JoyD.Windows.CS.Toprie private const int SDK_PORT = 5000; private const int BUFFER_SIZE = 4096; private const int TIMEOUT = 3000; + private const string CMD_HEAD = "+CMD"; + private const int DISCOVERY_UDP_PORT = 18889; + private const int SEARCH_DEVICE_MAX_NUM = 99; + + // 命令类型枚举 + private enum CMD_TYPE + { + SHUTTER_CORRECTION = 0, + SET_AUTO_SHUTTER = 1, + SET_COLOR_PLATE = 2, + SET_MIRROR_VIDEO = 3, + SET_VIDEO_MODE = 4, + SET_AREA_POS = 5, + SET_SPOT_POS = 6, + SET_LINE_POS = 7, + SET_TEMP_RANGE = 8, + SET_ISP_X_OFFSET = 9, + SET_ISP_Y_OFFSET = 10, + SET_ISP_X_SCALE = 11, + SET_ISP_Y_SCALE = 12, + SET_LED = 13, + SET_EMAIL_SERVER = 14, + SET_TFTP_SERVER = 15, + SET_NETWORK_ETH = 16, + SET_FUSION_DISTANCE = 17, + SET_ENVIR_PARAM = 18, + SET_ALARM_PARAM = 19, + GET_PARAMETER = 20, + POWER_REBOOT = 21, + PARAM_RECOVER = 22, + UPDATER = 23, + HEARTBEAT = 24, + SET_UART_PORT = 25, + UART_COMMAND = 26, + AUTOFOCUS = 27, + SET_DEVICE_NAME = 28, + SET_TEMP_FRAME = 29, + SET_ALARM_OUT = 30, + SET_ALARM = 31, + GET_ALARM = 32, + GET_COMP_TEMP = 33, + SET_TIME = 34, + SET_IMAGE_MODE = 35, + GET_IMAGE_DATA = 36, + GET_ALL_TEMP = 37, + UPDATE = 38, + SET_UART = 39, + SEND_UART_COMMAND = 40, + GET_DETECT_NUMBER = 41, + GET_TEMP_FRAME = 42, + GET_GLOBAL_ALARM_PARAM = 43, + GET_LINE_ALARM_PARAM = 44, + GET_AREA_TEMP = 45, + GET_SPOT_TEMP = 46, + GET_LINE_TEMP = 47, + GET_GLOBAL_TEMP = 48, + GET_AREA_ENVIR_PARAM = 49, + GET_SPOT_ENVIR_PARAM = 50, + GET_LINE_ENVIR_PARAM = 51, + GET_GLOBAL_ENVIR_PARAM = 52, + GET_AREA_ALARM_PARAM = 53, + GET_SPOT_ALARM_PARAM = 54, + GET_AREA_POS = 55, + GET_SPOT_POS = 56, + GET_LINE_POS = 57, + GET_ALL_POS = 58 + } + + // 参数类型枚举 + private enum PARAM_TYPE + { + AUTO_SHUTTER_TIME = 0, + COLOR_PLATE = 1, + MIRROR_MODE = 2, + VIDEO_MODE = 3, + AREA_POS = 4, + SPOT_POS = 5, + LINE_POS = 6, + TEMP_RANGE = 7, + ISP_X_OFFSET = 8, + ISP_Y_OFFSET = 9, + ISP_X_SCALE = 10, + ISP_Y_SCALE = 11, + LED_PARAM = 12, + EMAIL_SERVER = 13, + TFTP_SERVER = 14, + NETWORK_ETH = 15, + FUSION_DISTANCE = 16, + ENVIR_PARAM = 17, + ALARM_PARAM = 18, + TEMP_DATA = 19, + ALL_POS = 20, + DEVICE_NA = 21, + DETECT_NO = 22, + TEMP_FRAME = 23, + ALARM_IN = 24, + COMP_TEMP = 25, + LED_STATUS = 26, + EMAIL_SERVER_CONFIG = 27, + TFTP_SERVER_CONFIG = 28, + NETWORK_ETH_CONFIG = 29 + } // 私有字段 private string deviceIp; @@ -77,7 +180,7 @@ namespace JoyD.Windows.CS.Toprie } } - // 发送命令并接收响应 + // 发送命令并接收响应(字节数组版本) private bool SendCommand(byte[] command, out byte[] response, int responseLength = 0) { response = null; @@ -109,6 +212,61 @@ namespace JoyD.Windows.CS.Toprie } } + // 发送命令并接收响应(字符串版本) + private bool SendCommand(string cmd, out string response) + { + response = null; + if (!Connect()) + return false; + + try + { + // 发送命令 + byte[] commandBytes = Encoding.ASCII.GetBytes(cmd); + socket.Send(commandBytes); + + // 接收响应 + byte[] buffer = new byte[BUFFER_SIZE]; + int bytesRead = socket.Receive(buffer); + + if (bytesRead > 0) + { + response = Encoding.ASCII.GetString(buffer, 0, bytesRead); + return true; + } + return false; + } + catch (Exception ex) + { + Console.WriteLine($"发送命令失败: {ex.Message}"); + Disconnect(); + return false; + } + } + + // 解析响应数据 + private int ParseResponseValue(string response) + { + if (string.IsNullOrEmpty(response) || !response.StartsWith("+RET:")) + return 0; + + try + { + // 从第5个字符开始解析数值 (+RET:值$) + int endIndex = response.IndexOf('$'); + if (endIndex > 5) + { + string valueStr = response.Substring(5, endIndex - 5); + return int.Parse(valueStr); + } + } + catch (Exception ex) + { + Console.WriteLine($"解析响应失败: {ex.Message}"); + } + return 0; + } + // SDK核心功能实现 - 不使用DllImport public static int SDK_initialize() { @@ -164,12 +322,71 @@ namespace JoyD.Windows.CS.Toprie return string.Empty; } - // 实现设备搜索功能 - // 这里使用简单的实现,实际应该进行网络扫描 + const int DISCOVERY_UDP_PORT = 18889; + const int SEARCH_DEVICE_MAX_NUM = 99; + const int TIMEOUT_MS = 200; // 200毫秒超时 + const string DISCOVERY_CMD = "CMD_DISCOVER"; + StringBuilder deviceList = new StringBuilder(); + List discoveredDevices = new List(); + + // 创建UDP socket + using (Socket udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) + { + // 设置为广播模式 + udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); + + // 设置接收超时 + udpSocket.ReceiveTimeout = TIMEOUT_MS; + + // 发送广播命令 + byte[] sendData = Encoding.ASCII.GetBytes(DISCOVERY_CMD); + IPEndPoint broadcastEndPoint = new IPEndPoint(IPAddress.Broadcast, DISCOVERY_UDP_PORT); + udpSocket.SendTo(sendData, broadcastEndPoint); + + Console.WriteLine("发送设备发现广播命令: CMD_DISCOVER"); + + // 接收设备回复,最多接收99个设备 + int loopCount = SEARCH_DEVICE_MAX_NUM; + byte[] receiveBuffer = new byte[1024]; + EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); + + try + { + while (loopCount > 0) + { + int receiveLength = udpSocket.ReceiveFrom(receiveBuffer, ref remoteEndPoint); + if (receiveLength > 0) + { + string deviceIp = ((IPEndPoint)remoteEndPoint).Address.ToString(); + if (!discoveredDevices.Contains(deviceIp)) + { + discoveredDevices.Add(deviceIp); + Console.WriteLine($"发现设备: {deviceIp}"); + } + } + loopCount--; + } + } + catch (SocketException ex) + { + // 超时异常是正常的,继续处理已发现的设备 + if (ex.SocketErrorCode != SocketError.TimedOut) + { + Console.WriteLine($"接收设备回复异常: {ex.Message}"); + } + } + } - // 模拟搜索到的设备 - deviceList.Append("192.168.1.100;192.168.1.101;192.168.1.102"); + // 将发现的设备IP用分号连接 + for (int i = 0; i < discoveredDevices.Count; i++) + { + deviceList.Append(discoveredDevices[i]); + if (i < discoveredDevices.Count - 1) + { + deviceList.Append(';'); + } + } return deviceList.ToString(); } @@ -184,12 +401,12 @@ namespace JoyD.Windows.CS.Toprie { try { - // 构建快门校正命令 - byte[] command = new byte[] { 0x01, 0x02, 0x03, 0x04 }; // 示例命令格式 + // 根据SDK格式构建快门校正命令: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SHUTTER_CORRECTION},0$"; - if (SendCommand(command, out _)) + if (SendCommand(command, out string response)) { - Console.WriteLine("快门校正命令已发送"); + Console.WriteLine($"快门校正命令已发送,响应: {response}"); } else { @@ -208,33 +425,37 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x01, 0x05, 0x00, 0x00 }; // 获取快门时间命令 + // 使用SDK格式获取快门校正时间: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.AUTO_SHUTTER_TIME}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - // 解析响应数据,这里简单返回一个模拟值 - return 60; // 默认60秒 + // 根据SDK响应格式解析 + return ParseResponseValue(response); } - return 0; + return 60; // 默认值 } catch (Exception ex) { Console.WriteLine($"获取快门时间失败: {ex.Message}"); - return 0; + return 60; // 默认值 } } 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); + // 使用SDK格式设置快门校正时间: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_AUTO_SHUTTER},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置快门时间成功"); + } + } } catch (Exception ex) { @@ -249,14 +470,14 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x02, 0x01, 0x00, 0x00 }; // 获取色板命令 + // 使用SDK格式获取色板: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.COLOR_PLATE}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - // 解析响应数据 - return 0; // 默认色板 + return ParseResponseValue(response); } - return 0; + return 0; // 默认色板 } catch (Exception ex) { @@ -268,13 +489,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置色板: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_COLOR_PLATE},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置色板成功"); + } + } } catch (Exception ex) { @@ -289,13 +514,14 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x02, 0x03, 0x00, 0x00 }; // 获取镜像模式命令 + // 使用SDK格式获取镜像模式: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.MIRROR_MODE}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 0; // 默认模式 + return ParseResponseValue(response); } - return 0; + return 0; // 默认不镜像 } catch (Exception ex) { @@ -307,12 +533,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置镜像模式: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_MIRROR_VIDEO},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置镜像模式成功"); + } + } } catch (Exception ex) { @@ -327,13 +558,14 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x02, 0x05, 0x00, 0x00 }; // 获取视频模式命令 + // 使用SDK格式获取视频模式: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.VIDEO_MODE}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 0; // 默认模式 + return ParseResponseValue(response); } - return 0; + return 0; // 默认模式 } catch (Exception ex) { @@ -345,12 +577,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置视频模式: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_VIDEO_MODE},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置视频模式成功"); + } + } } catch (Exception ex) { @@ -363,17 +600,8 @@ namespace JoyD.Windows.CS.Toprie { try { - // 序列化区域位置数据 - byte[] command = new byte[] { 0x03, 0x01, (byte)index, 0x00 }; - - // 添加区域数据 - byte[] dataBytes = new byte[16]; // 足够容纳SharedStructures.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); + // 使用SDK格式设置区域位置: ip:param_mode,index,enable,x,y,width$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_AREA_POS},{index},{area_data.enable},{area_data.x},{area_data.y},{area_data.width}$"; SendCommand(command, out _); } @@ -387,18 +615,25 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x03, 0x02, (byte)index, 0x00 }; + // 使用SDK格式获取区域位置: ip:param_mode,index$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_AREA_POS},{index}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { // 解析响应数据 SharedStructures.AreaPos area_data = new SharedStructures.AreaPos(); - if (response.Length >= 16) + + if (!string.IsNullOrEmpty(response)) { - 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); + // 移除结束符$并按逗号分割数据 + string[] values = response.TrimEnd('$').Split(','); + if (values.Length >= 5) + { + area_data.enable = int.Parse(values[1]); + area_data.x = int.Parse(values[2]); + area_data.y = int.Parse(values[3]); + area_data.width = int.Parse(values[4]); + } } return area_data; } @@ -415,14 +650,8 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置点位置: ip:param_mode,index,enable,x,y$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_SPOT_POS},{index},{spot_data.enable},{spot_data.x},{spot_data.y}$"; SendCommand(command, out _); } @@ -436,16 +665,23 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x03, 0x04, (byte)index, 0x00 }; + // 使用SDK格式获取点位置: ip:param_mode,index$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_SPOT_POS},{index}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { SharedStructures.SpotPos spot_data = new SharedStructures.SpotPos(); - if (response.Length >= 12) + + if (!string.IsNullOrEmpty(response)) { - spot_data.enable = BitConverter.ToInt32(response, 0); - spot_data.x = BitConverter.ToInt32(response, 4); - spot_data.y = BitConverter.ToInt32(response, 8); + // 移除结束符$并按逗号分割数据 + string[] values = response.TrimEnd('$').Split(','); + if (values.Length >= 4) + { + spot_data.enable = int.Parse(values[1]); + spot_data.x = int.Parse(values[2]); + spot_data.y = int.Parse(values[3]); + } } return spot_data; } @@ -464,16 +700,8 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置线位置: ip:param_mode,enable,sta_x,sta_y,end_x,end_y$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_LINE_POS},{value.enable},{value.sta_x},{value.sta_y},{value.end_x},{value.end_y}$"; SendCommand(command, out _); } @@ -486,18 +714,25 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x03, 0x06, 0x00, 0x00 }; + // 使用SDK格式获取线位置: ip:param_mode,0$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_LINE_POS},0$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { SharedStructures.LinePos line_data = new SharedStructures.LinePos(); - if (response.Length >= 20) + + if (!string.IsNullOrEmpty(response)) { - 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); + // 移除结束符$并按逗号分割数据 + string[] values = response.TrimEnd('$').Split(','); + if (values.Length >= 6) + { + line_data.enable = int.Parse(values[1]); + line_data.sta_x = int.Parse(values[2]); + line_data.sta_y = int.Parse(values[3]); + line_data.end_x = int.Parse(values[4]); + line_data.end_y = int.Parse(values[5]); + } } return line_data; } @@ -517,9 +752,10 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x03, 0x07, 0x00, 0x00 }; + // 使用SDK格式获取所有位置: ip:param_mode,0$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_ALL_POS},0$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { // 创建默认的ImagePos对象 SharedStructures.ImagePos data = new SharedStructures.ImagePos(); @@ -546,12 +782,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置温度范围: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_TEMP_RANGE},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置温度范围成功"); + } + } } catch (Exception ex) { @@ -562,13 +803,14 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x04, 0x02, 0x00, 0x00 }; + // 使用SDK格式获取温度范围: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.TEMP_RANGE}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 0; // 默认范围 + return ParseResponseValue(response); } - return 0; + return 0; // 默认范围 } catch (Exception ex) { @@ -584,12 +826,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置X偏移: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_ISP_X_OFFSET},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置X偏移成功"); + } + } } catch (Exception ex) { @@ -600,11 +847,12 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x05, 0x02, 0x00, 0x00 }; + // 使用SDK格式获取X偏移: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.ISP_X_OFFSET}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 0; + return ParseResponseValue(response); } return 0; } @@ -618,16 +866,21 @@ namespace JoyD.Windows.CS.Toprie public int Video_isp_y_offset { - set + 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); + // 使用SDK格式设置Y偏移: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_ISP_Y_OFFSET},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置Y偏移成功"); + } + } } catch (Exception ex) { @@ -638,11 +891,12 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x05, 0x04, 0x00, 0x00 }; + // 使用SDK格式获取Y偏移: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.ISP_Y_OFFSET}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 0; + return ParseResponseValue(response); } return 0; } @@ -660,12 +914,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置X缩放: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_ISP_X_SCALE},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置X缩放成功"); + } + } } catch (Exception ex) { @@ -676,13 +935,14 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x05, 0x06, 0x00, 0x00 }; + // 使用SDK格式获取X缩放: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.ISP_X_SCALE}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 100; // 默认100% + return ParseResponseValue(response); } - return 100; + return 100; // 默认100% } catch (Exception ex) { @@ -698,12 +958,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置Y缩放: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_ISP_Y_SCALE},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置Y缩放成功"); + } + } } catch (Exception ex) { @@ -714,13 +979,14 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x05, 0x08, 0x00, 0x00 }; + // 使用SDK格式获取Y缩放: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.ISP_Y_SCALE}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 100; // 默认100% + return ParseResponseValue(response); } - return 100; + return 100; // 默认100% } catch (Exception ex) { @@ -736,12 +1002,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SDK格式设置LED状态: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_LED},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置LED状态成功"); + } + } } catch (Exception ex) { @@ -752,13 +1023,14 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x06, 0x02, 0x00, 0x00 }; + // 使用SDK格式获取LED状态: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.LED_STATUS}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 0; // 默认关闭 + return ParseResponseValue(response); } - return 0; + return 0; // 默认关闭 } catch (Exception ex) { @@ -774,16 +1046,19 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x07, 0x01, 0x00, 0x00 }; + // 使用SDK格式设置邮件服务器配置: ip:param_mode,param_value$ + // 构建参数字符串,包含enable标志 + string paramsStr = $"{value.enable}"; + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_EMAIL_SERVER},{paramsStr}$"; - // 序列化SharedStructures.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 _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置邮件服务器成功"); + } + } } catch (Exception ex) { @@ -794,11 +1069,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x07, 0x02, 0x00, 0x00 }; + // 使用SDK格式获取邮件服务器配置: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.EMAIL_SERVER_CONFIG}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.EmailServer(); + // 解析响应并创建EmailServer对象 + SharedStructures.EmailServer emailServer = new SharedStructures.EmailServer(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return emailServer; } return new SharedStructures.EmailServer(); } @@ -816,14 +1096,18 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x07, 0x03, 0x00, 0x00 }; + // 使用SDK格式设置TFTP服务器配置: ip:param_mode,param_value$ + string paramsStr = $"{value.enable}"; + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_TFTP_SERVER},{paramsStr}$"; - 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 _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置TFTP服务器成功"); + } + } } catch (Exception ex) { @@ -834,11 +1118,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x07, 0x04, 0x00, 0x00 }; + // 使用SDK格式获取TFTP服务器配置: ip:param_mode,param_value$ + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.TFTP_SERVER_CONFIG}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.TftpServer(); + // 解析响应并创建TftpServer对象 + SharedStructures.TftpServer tftpServer = new SharedStructures.TftpServer(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return tftpServer; } return new SharedStructures.TftpServer(); } @@ -856,14 +1145,18 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x08, 0x01, 0x00, 0x00 }; + // 使用SDK格式设置网络参数: ip:param_mode,param_value$ + string paramsStr = $"{value.enable}"; + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_NETWORK_ETH},{paramsStr}$"; - 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 _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置网络参数成功"); + } + } } catch (Exception ex) { @@ -874,11 +1167,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x08, 0x02, 0x00, 0x00 }; + // 使用GET_PARAMETER命令获取网络参数 + string command = $"{CMD_HEAD}:{(int)CMD_TYPE.GET_PARAMETER}:{(int)PARAM_TYPE.NETWORK_ETH_CONFIG}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.NetworkEth(); + // 解析响应并创建NetworkEth对象 + SharedStructures.NetworkEth networkEth = new SharedStructures.NetworkEth(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return networkEth; } return new SharedStructures.NetworkEth(); } @@ -896,12 +1194,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SET_FUSION_DISTANCE命令设置融合距离 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_FUSION_DISTANCE},{value}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置融合距离成功"); + } + } } catch (Exception ex) { @@ -912,13 +1215,14 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x09, 0x02, 0x00, 0x00 }; + // 使用GET_PARAMETER命令获取融合距离 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.FUSION_DISTANCE}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 1000; // 默认1米 + return ParseResponseValue(response); } - return 1000; + return 1000; // 默认1米 } catch (Exception ex) { @@ -932,22 +1236,19 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x10, 0x01, 0x00, 0x00 }; + // 使用SET_ENVIR_PARAM命令设置环境参数 - SDK格式 + // 构建参数字符串,包含所有环境参数 + string paramsStr = $"{data.method},{data.num},{data.emissivity},{data.airTemp},{data.targetTemp},{data.atmosTrans},{data.distance},{data.infraredTemp},{data.infraredRadia}"; + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_ENVIR_PARAM},{paramsStr}$"; - 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 _); + if (SendCommand(command, out string response)) + { + // 验证响应 + if (response != null) + { + Console.WriteLine("设置环境参数成功"); + } + } } catch (Exception ex) { @@ -959,11 +1260,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x10, 0x02, (byte)index, 0x00 }; + // 使用GET_AREA_ENVIR_PARAM命令获取区域环境参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_AREA_ENVIR_PARAM},{index}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.EnvirParam(); + // 解析响应并创建EnvirParam对象 + SharedStructures.EnvirParam envirParam = new SharedStructures.EnvirParam(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return envirParam; } return new SharedStructures.EnvirParam(); } @@ -978,11 +1284,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x10, 0x03, (byte)index, 0x00 }; + // 使用GET_SPOT_ENVIR_PARAM命令获取点环境参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_SPOT_ENVIR_PARAM},{index}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.EnvirParam(); + // 解析响应并创建EnvirParam对象 + SharedStructures.EnvirParam envirParam = new SharedStructures.EnvirParam(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return envirParam; } return new SharedStructures.EnvirParam(); } @@ -997,11 +1308,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x10, 0x04, 0x00, 0x00 }; + // 使用GET_LINE_ENVIR_PARAM命令获取线环境参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_LINE_ENVIR_PARAM}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.EnvirParam(); + // 解析响应并创建EnvirParam对象 + SharedStructures.EnvirParam envirParam = new SharedStructures.EnvirParam(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return envirParam; } return new SharedStructures.EnvirParam(); } @@ -1016,11 +1332,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x10, 0x05, 0x00, 0x00 }; + // 使用GET_GLOBAL_ENVIR_PARAM命令获取全局环境参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_GLOBAL_ENVIR_PARAM}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.EnvirParam(); + // 解析响应并创建EnvirParam对象 + SharedStructures.EnvirParam envirParam = new SharedStructures.EnvirParam(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return envirParam; } return new SharedStructures.EnvirParam(); } @@ -1035,27 +1356,17 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x11, 0x01, 0x00, 0x00 }; + // 使用SET_ALARM_PARAM命令设置报警参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_ALARM_PARAM},{data.method},{data.num},{data.active},{data.condition},{data.captrue},{data.disableCalib},{data.email},{data.digital},{data.ftp},{data.threshold},{data.hysteresis},{data.thresholeTime}$"; - 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 _); + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + // 命令执行成功 + } + } } catch (Exception ex) { @@ -1067,11 +1378,15 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x11, 0x02, (byte)index, 0x00 }; - - if (SendCommand(command, out byte[] response)) + // 使用GET_AREA_ALARM_PARAM命令获取区域报警参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_AREA_ALARM_PARAM},{index}$"; + if (SendCommand(command, out string response)) { - return new SharedStructures.AlarmParam(); + // 解析响应并创建AlarmParam对象 + SharedStructures.AlarmParam alarmParam = new SharedStructures.AlarmParam(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return alarmParam; } return new SharedStructures.AlarmParam(); } @@ -1086,11 +1401,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x11, 0x03, (byte)index, 0x00 }; + // 使用GET_SPOT_ALARM_PARAM命令获取点报警参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_SPOT_ALARM_PARAM},{index}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.AlarmParam(); + // 解析响应并创建AlarmParam对象 + SharedStructures.AlarmParam alarmParam = new SharedStructures.AlarmParam(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return alarmParam; } return new SharedStructures.AlarmParam(); } @@ -1105,11 +1425,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x11, 0x05, 0x00, 0x00 }; + // 使用GET_GLOBAL_ALARM_PARAM命令获取全局报警参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_GLOBAL_ALARM_PARAM}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.AlarmParam(); + // 解析响应并创建AlarmParam对象 + SharedStructures.AlarmParam alarmParam = new SharedStructures.AlarmParam(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return alarmParam; } return new SharedStructures.AlarmParam(); } @@ -1124,11 +1449,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x11, 0x04, 0x00, 0x00 }; + // 使用GET_LINE_ALARM_PARAM命令获取线报警参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_LINE_ALARM_PARAM}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.AlarmParam(); + // 解析响应并创建AlarmParam对象 + SharedStructures.AlarmParam alarmParam = new SharedStructures.AlarmParam(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return alarmParam; } return new SharedStructures.AlarmParam(); } @@ -1143,11 +1473,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x12, 0x01, (byte)index, 0x00 }; + // 使用GET_AREA_TEMP命令获取区域温度 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_AREA_TEMP},{index}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.AreaTemp(); + // 解析响应并创建AreaTemp对象 + SharedStructures.AreaTemp areaTemp = new SharedStructures.AreaTemp(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return areaTemp; } return new SharedStructures.AreaTemp(); } @@ -1162,11 +1497,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x12, 0x02, (byte)index, 0x00 }; + // 使用GET_SPOT_TEMP命令获取点温度 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_SPOT_TEMP},{index}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.SpotTemp(); + // 解析响应并创建SpotTemp对象 + SharedStructures.SpotTemp spotTemp = new SharedStructures.SpotTemp(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return spotTemp; } return new SharedStructures.SpotTemp(); } @@ -1181,11 +1521,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x12, 0x03, 0x00, 0x00 }; + // 使用GET_LINE_TEMP命令获取线温度 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_LINE_TEMP}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.LineTemp(); + // 解析响应并创建LineTemp对象 + SharedStructures.LineTemp lineTemp = new SharedStructures.LineTemp(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return lineTemp; } return new SharedStructures.LineTemp(); } @@ -1200,11 +1545,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x12, 0x04, 0x00, 0x00 }; + // 使用GET_GLOBAL_TEMP命令获取全局温度 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_GLOBAL_TEMP}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.GlobaTemp(); + // 解析响应并创建GlobaTemp对象 + SharedStructures.GlobaTemp globaTemp = new SharedStructures.GlobaTemp(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return globaTemp; } return new SharedStructures.GlobaTemp(); } @@ -1219,11 +1569,16 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x12, 0x05, 0x00, 0x00 }; + // 使用GET_ALL_TEMP命令获取所有温度数据 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_ALL_TEMP}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return new SharedStructures.ImageTemp(); + // 解析响应并创建ImageTemp对象 + SharedStructures.ImageTemp imageTemp = new SharedStructures.ImageTemp(); + // 这里可以根据实际响应格式进行解析 + // 目前返回默认对象 + return imageTemp; } return new SharedStructures.ImageTemp(); } @@ -1238,9 +1593,17 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x13, 0x01, 0x00, 0x00 }; - SendCommand(command, out _); - Console.WriteLine("设备重启命令已发送"); + // 使用POWER_REBOOT命令重启设备 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.POWER_REBOOT}$"; + + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + Console.WriteLine("设备重启命令已发送"); + } + } } catch (Exception ex) { @@ -1252,9 +1615,17 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x13, 0x02, 0x00, 0x00 }; - SendCommand(command, out _); - Console.WriteLine("参数恢复命令已发送"); + // 使用PARAM_RECOVER命令恢复参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.PARAM_RECOVER}$"; + + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + Console.WriteLine("参数恢复命令已发送"); + } + } } catch (Exception ex) { @@ -1266,9 +1637,17 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x13, 0x03, 0x00, 0x00 }; - SendCommand(command, out _); - Console.WriteLine("设备更新命令已发送"); + // 使用UPDATE命令更新设备 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.UPDATE}$"; + + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + Console.WriteLine("设备更新命令已发送"); + } + } } catch (Exception ex) { @@ -1280,11 +1659,17 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x14, 0x01, 0x00, 0x00 }; + // 根据SDK格式构建心跳命令 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.HEARTBEAT}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 0; // 正常 + // 验证响应格式 + if (response != null) + { + Console.WriteLine("心跳成功"); + return 1; // 返回1表示成功,与DeviceManager中的判断一致 + } } return -1; } @@ -1299,16 +1684,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SET_UART命令设置串口参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_UART},{nSpeed},{nBits},{(int)nEvent},{nStop}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + // 命令执行成功 + } + } } catch (Exception ex) { @@ -1320,9 +1706,10 @@ namespace JoyD.Windows.CS.Toprie { 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, 2, cmd.Length); + // 将byte数组转换为十六进制字符串格式 + string hexData = BitConverter.ToString(cmd).Replace("-", ""); + // 使用SEND_UART_COMMAND命令发送串口命令 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SEND_UART_COMMAND},{hexData}$"; SendCommand(command, out _); } @@ -1336,17 +1723,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用AUTOFOCUS命令设置自动对焦参数 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.AUTOFOCUS},{data.method},{data.x},{data.y},{data.width},{data.height}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + // 命令执行成功 + } + } } catch (Exception ex) { @@ -1358,12 +1745,17 @@ namespace JoyD.Windows.CS.Toprie { 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); + // 使用SET_DEVICE_NAME命令设置设备名称 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_DEVICE_NAME},{data}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + // 命令执行成功 + } + } } catch (Exception ex) { @@ -1375,11 +1767,24 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x17, 0x02, 0x00, 0x00 }; + // 使用GET_PARAMETER命令获取设备名称 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.DEVICE_NA}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return Encoding.ASCII.GetString(response); + // 解析响应中的设备名称 + // 格式: +RET:1:设备名称$ 或 +RET:设备名称$ + if (response != null && response.StartsWith("+RET:")) + { + int paramTypeEndPos = response.IndexOf(':', 5); + int nameStartPos = (paramTypeEndPos > 0) ? paramTypeEndPos + 1 : 5; + int endPos = response.IndexOf('$', nameStartPos); + + if (endPos > nameStartPos) + { + return response.Substring(nameStartPos, endPos - nameStartPos); + } + } } return string.Empty; } @@ -1394,11 +1799,27 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x17, 0x03, 0x00, 0x00 }; + // 使用GET_DETECT_NUMBER命令获取检测编号 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_DETECT_NUMBER}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return response; + // 解析响应,返回检测编号数据 + // 响应格式: +RET:0:数据内容$ 或 +RET:数据内容$ + if (response != null && response.StartsWith("+RET:")) + { + // 解析响应中的数据部分 + int startPos = response.IndexOf(':', 5) + 1; + int endPos = response.IndexOf('$', startPos); + + if (endPos > startPos) + { + string dataStr = response.Substring(startPos, endPos - startPos); + // 将十六进制字符串转换为字节数组 + // 注意:这里需要根据实际响应格式进行适当的转换 + return Encoding.ASCII.GetBytes(dataStr); + } + } } return new byte[0]; } @@ -1415,7 +1836,9 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x18, 0x01, 0x00, 0x00, (byte)value }; + // 使用SET_TEMP_FRAME命令设置温度帧 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_TEMP_FRAME},{(byte)value}$"; + SendCommand(command, out _); } catch (Exception ex) @@ -1427,11 +1850,26 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x18, 0x02, 0x00, 0x00 }; + // 使用GET_TEMP_FRAME命令获取温度帧 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_TEMP_FRAME}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return (char)0; + // 解析响应中的温度帧值 + if (response != null && response.StartsWith("+RET:")) + { + int valueStartPos = response.IndexOf(':', 5) + 1; + int endPos = response.IndexOf('$', valueStartPos); + + if (endPos > valueStartPos) + { + string valueStr = response.Substring(valueStartPos, endPos - valueStartPos); + if (byte.TryParse(valueStr, out byte result)) + { + return (char)result; + } + } + } } return (char)0; } @@ -1449,7 +1887,9 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x19, 0x01, 0x00, 0x00, (byte)value }; + // 使用SET_ALARM命令设置报警输出 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_ALARM},{(byte)value}$"; + SendCommand(command, out _); } catch (Exception ex) @@ -1461,11 +1901,26 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x19, 0x02, 0x00, 0x00 }; + // 使用GET_ALARM命令获取报警输出状态 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_ALARM}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return (char)0; + // 解析响应中的报警状态值 + if (response != null && response.StartsWith("+RET:")) + { + int valueStartPos = response.IndexOf(':', 5) + 1; + int endPos = response.IndexOf('$', valueStartPos); + + if (endPos > valueStartPos) + { + string valueStr = response.Substring(valueStartPos, endPos - valueStartPos); + if (byte.TryParse(valueStr, out byte result)) + { + return (char)result; + } + } + } } return (char)0; } @@ -1483,19 +1938,33 @@ namespace JoyD.Windows.CS.Toprie { try { - byte[] command = new byte[] { 0x1A, 0x01, 0x00, 0x00 }; + // 使用GET_COMP_TEMP命令获取补偿温度 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_COMP_TEMP}$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return 2500; // 默认25.00度 + // 解析响应中的补偿温度值 + if (response != null && response.StartsWith("+RET:")) + { + int valueStartPos = response.IndexOf(':', 5) + 1; + int endPos = response.IndexOf('$', valueStartPos); + + if (endPos > valueStartPos) + { + string valueStr = response.Substring(valueStartPos, endPos - valueStartPos); + if (int.TryParse(valueStr, out int result)) + { + return result; + } + } + } } - return 2500; } catch (Exception ex) { Console.WriteLine($"获取补偿温度失败: {ex.Message}"); - return 2500; } + return 2500; } } @@ -1503,18 +1972,17 @@ namespace JoyD.Windows.CS.Toprie { 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] = (byte)data.month; - dataBytes[5] = (byte)data.day; - dataBytes[6] = (byte)data.hour; - dataBytes[7] = (byte)data.minute; - dataBytes[8] = (byte)data.second; - Array.Resize(ref command, command.Length + dataBytes.Length); - Array.Copy(dataBytes, 0, command, 4, dataBytes.Length); + // 使用SET_TIME命令设置系统时间 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_TIME},{data.year},{data.month},{data.day},{data.hour},{data.minute},{data.second}$"; - SendCommand(command, out _); + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + // 命令执行成功 + } + } } catch (Exception ex) { @@ -1527,14 +1995,17 @@ namespace JoyD.Windows.CS.Toprie { try { - // 构建设置图像模式命令 - byte[] command = new byte[] { 0x02, 0x07, 0x00, 0x00 }; - byte[] valueBytes = BitConverter.GetBytes(mode); - Array.Resize(ref command, command.Length + valueBytes.Length); - Array.Copy(valueBytes, 0, command, 4, valueBytes.Length); + // 使用SET_IMAGE_MODE命令设置图像模式 - SDK格式 + string command = $"{deviceIp}:{(int)CMD_TYPE.SET_IMAGE_MODE},{mode}$"; - SendCommand(command, out _); - Console.WriteLine($"设置图像模式为: {mode}"); + if (SendCommand(command, out string response)) + { + // 验证响应是否成功 + if (response != null) + { + Console.WriteLine($"设置图像模式为: {mode}"); + } + } } catch (Exception ex) { @@ -1547,12 +2018,34 @@ namespace JoyD.Windows.CS.Toprie { try { - // 构建获取图像数据命令 - byte[] command = new byte[] { 0x02, 0x08, 0x00, 0x00 }; + // 根据SDK实现,使用正确的命令格式获取图像数据 + // 格式为:"ip:param_mode,param_value$" + string command = $"{deviceIp}:{(int)CMD_TYPE.GET_IMAGE_DATA},0$"; - if (SendCommand(command, out byte[] response)) + if (SendCommand(command, out string response)) { - return response; + // 处理图像数据响应 + // 注意:由于图像数据可能较大且为二进制,这里需要根据实际响应格式进行解析 + if (response != null) + { + // 查找响应中的数据部分 + int endPos = response.IndexOf('$'); + + if (endPos > 0) + { + string dataStr = response.Substring(0, endPos); + // 假设图像数据是base64编码的,需要解码 + try + { + return Convert.FromBase64String(dataStr); + } + catch + { + // 如果不是base64编码,返回空数组 + return new byte[0]; + } + } + } } return new byte[0]; }