From b48bd591dc418c2f08e8caa1b182a791d40f0007 Mon Sep 17 00:00:00 2001 From: fajiao <1519100073@qq.com> Date: Thu, 8 Jun 2023 14:57:30 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E5=AE=87=E8=A7=86=E9=A2=84=E7=BD=AE?= =?UTF-8?q?=E7=82=B9=20NETDEV=5FPTZPreset=5FOther?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EC.Util/CameraSDK/YuShi/YuShiOriSDK.cs | 24 ++++++++++++++++++++++++ EC.Util/CameraSDK/YuShi/YuShiSDK.cs | 18 +++++++++++++++--- JiLinApp/Pages/Main/MainWindow.xaml.cs | 5 ----- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/EC.Util/CameraSDK/YuShi/YuShiOriSDK.cs b/EC.Util/CameraSDK/YuShi/YuShiOriSDK.cs index 495aea7..ff38d01 100644 --- a/EC.Util/CameraSDK/YuShi/YuShiOriSDK.cs +++ b/EC.Util/CameraSDK/YuShi/YuShiOriSDK.cs @@ -49,6 +49,7 @@ public static class YuShiOriSDK public const int PtzSpeedMax = 9; /* Common length */ + public const int NETDEV_LEN_32 = 32; public const int NETDEV_LEN_64 = 64; public const int NETDEV_LEN_128 = 128; public const int NETDEV_LEN_132 = 132; @@ -83,6 +84,8 @@ public static class YuShiOriSDK public const int PRESET_SET = 0; /* Set preset */ public const int PRESET_CLE = 1; /* Clear preset */ public const int PRESET_GOTO = 2; /* Go to preset */ + /* Maximum number of presets */ + public const int NETDEV_MAX_PRESET_NUM = 255; public enum NETDEV_LIVE_STREAM_INDEX_E : int { @@ -188,6 +191,24 @@ public static class YuShiOriSDK public byte[] szReserve; /* Reserved */ } + [StructLayout(LayoutKind.Sequential)] + public struct NETDEV_PTZ_ALLPRESETS_S + { + public Int32 dwSize; /* Total number of presets */ + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = NETDEV_MAX_PRESET_NUM)] + public NETDEV_PTZ_PRESET_S[] astPreset; /* Structure of preset information */ + } + + [StructLayout(LayoutKind.Sequential)] + public struct NETDEV_PTZ_PRESET_S + { + public Int32 dwPresetID; /* ID Preset ID */ + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = NETDEV_LEN_32)] + public byte[] szPresetName; /** Preset name */ + } + #endregion SDK Struct #region Common Method @@ -227,5 +248,8 @@ public static class YuShiOriSDK [DllImport(LibYsNetSDK, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] public static extern int NETDEV_StopRealPlay(IntPtr lpRealHandle); + [DllImport(LibYsNetSDK, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 NETDEV_GetPTZPresetList(IntPtr lpUserID, Int32 dwChannelID, ref NETDEV_PTZ_ALLPRESETS_S lpOutBuffer); + #endregion Common Method } \ No newline at end of file diff --git a/EC.Util/CameraSDK/YuShi/YuShiSDK.cs b/EC.Util/CameraSDK/YuShi/YuShiSDK.cs index 7e37652..fd37e57 100644 --- a/EC.Util/CameraSDK/YuShi/YuShiSDK.cs +++ b/EC.Util/CameraSDK/YuShi/YuShiSDK.cs @@ -1,4 +1,7 @@ -namespace EC.Util.CameraSDK; +using System.Runtime.InteropServices; +using static EC.Util.CameraSDK.YuShiOriSDK; + +namespace EC.Util.CameraSDK; public class YuShiSDK : ICameraSDK { @@ -30,7 +33,11 @@ public class YuShiSDK : ICameraSDK YuShiOriSDK.NETDEV_SELOG_INFO_S logInfo = new(); LoginId = YuShiOriSDK.NETDEV_Login_V30(ref loginInfo, ref logInfo); ret = ConnectSuccess(); - if(!ret) BuildException(); + if (!ret) BuildException(); + //别删 NETDEV_QueryVideoChlDetailList,否则 NETDEV_PTZPreset_Other 教做人 + int pdwChlCount = 16; + IntPtr pstVideoChlList = Marshal.AllocHGlobal(pdwChlCount * Marshal.SizeOf(typeof(NETDEV_VIDEO_CHL_DETAIL_INFO_S))); + YuShiOriSDK.NETDEV_QueryVideoChlDetailList(LoginId, ref pdwChlCount, pstVideoChlList); return ret; } @@ -94,8 +101,13 @@ public class YuShiSDK : ICameraSDK public override bool PtzPreset(int cmd, int presetId) { if (!ConnectSuccess()) return false; - int retNum = YuShiOriSDK.NETDEV_PTZPreset_Other(LoginId, Channel, cmd, Array.Empty(), presetId); + NETDEV_PTZ_ALLPRESETS_S ptzPresets = new(); + int retNum = YuShiOriSDK.NETDEV_GetPTZPresetList(LoginId, Channel, ref ptzPresets); bool ret = retNum == YuShiOriSDK.TRUE; + Console.WriteLine($"NETDEV_GetPTZPresetList:{retNum}, handle:{LoginId}, ptzPresets.dwSize:{ptzPresets.dwSize}"); + if (!ret) BuildException(); + retNum = YuShiOriSDK.NETDEV_PTZPreset_Other(LoginId, Channel, cmd, new byte[32], presetId); + ret = retNum == YuShiOriSDK.TRUE; if (!ret) BuildException(); return ret; } diff --git a/JiLinApp/Pages/Main/MainWindow.xaml.cs b/JiLinApp/Pages/Main/MainWindow.xaml.cs index 6c1508e..f8c2abf 100644 --- a/JiLinApp/Pages/Main/MainWindow.xaml.cs +++ b/JiLinApp/Pages/Main/MainWindow.xaml.cs @@ -39,9 +39,4 @@ public partial class MainWindow : Window private static extern bool AttachConsole(int dwProcessId); #endregion - - private void Button_Click(object sender, RoutedEventArgs e) - { - Console.WriteLine("test"); - } } \ No newline at end of file