├── .vscode └── settings.json ├── src ├── QuickNV.HikvisionNetSDK.Native │ ├── lib │ │ └── netstandard1.0 │ │ │ └── _._ │ ├── runtimes │ │ ├── win-x64 │ │ │ └── native │ │ │ │ ├── LocalSensorAdd.dat │ │ │ │ ├── HXVA.dll │ │ │ │ ├── NPQos.dll │ │ │ │ ├── hlog.dll │ │ │ │ ├── hpr.dll │ │ │ │ ├── zlib1.dll │ │ │ │ ├── GdiPlus.dll │ │ │ │ ├── HCCore.dll │ │ │ │ ├── HmMerge.dll │ │ │ │ ├── libmmd.dll │ │ │ │ ├── HCNetSDK.dll │ │ │ │ ├── LocalXml.zip │ │ │ │ ├── MP_Render.dll │ │ │ │ ├── OpenAL32.dll │ │ │ │ ├── PlayCtrl.dll │ │ │ │ ├── YUVProcess.dll │ │ │ │ ├── AudioRender.dll │ │ │ │ ├── SuperRender.dll │ │ │ │ ├── libssl-1_1-x64.dll │ │ │ │ ├── libcrypto-1_1-x64.dll │ │ │ │ └── HCNetSDKCom │ │ │ │ ├── HCAlarm.dll │ │ │ │ ├── OpenAL32.dll │ │ │ │ ├── HCDisplay.dll │ │ │ │ ├── HCIndustry.dll │ │ │ │ ├── HCPlayBack.dll │ │ │ │ ├── HCPreview.dll │ │ │ │ ├── libiconv2.dll │ │ │ │ ├── AnalyzeData.dll │ │ │ │ ├── AudioIntercom.dll │ │ │ │ ├── AudioRender.dll │ │ │ │ ├── HCCoreDevCfg.dll │ │ │ │ ├── HCVoiceTalk.dll │ │ │ │ ├── HCGeneralCfgMgr.dll │ │ │ │ ├── SystemTransform.dll │ │ │ │ └── StreamTransClient.dll │ │ ├── linux-x64 │ │ │ └── native │ │ │ │ ├── libz.so │ │ │ │ ├── libhpr.so │ │ │ │ ├── libHCCore.so │ │ │ │ ├── libNPQos.so │ │ │ │ ├── libPlayCtrl.so │ │ │ │ ├── libhcnetsdk.so │ │ │ │ ├── libopenal.so.1 │ │ │ │ ├── libssl.so.1.1 │ │ │ │ ├── libAudioRender.so │ │ │ │ ├── libSuperRender.so │ │ │ │ ├── libcrypto.so.1.1 │ │ │ │ ├── HCNetSDKCom │ │ │ │ ├── libiconv2.so │ │ │ │ ├── libHCAlarm.so │ │ │ │ ├── libHCDisplay.so │ │ │ │ ├── libHCPreview.so │ │ │ │ ├── libHCIndustry.so │ │ │ │ ├── libHCPlayBack.so │ │ │ │ ├── libHCVoiceTalk.so │ │ │ │ ├── libanalyzedata.so │ │ │ │ ├── libAudioIntercom.so │ │ │ │ ├── libHCCoreDevCfg.so │ │ │ │ ├── libHCGeneralCfgMgr.so │ │ │ │ ├── libSystemTransform.so │ │ │ │ └── libStreamTransClient.so │ │ │ │ └── HCNetSDK_Log_Switch.xml │ │ └── linux-arm64 │ │ │ └── native │ │ │ ├── libz.so │ │ │ ├── libhpr.so │ │ │ ├── libssl.so │ │ │ ├── libHCCore.so │ │ │ ├── libcrypto.so │ │ │ ├── libPlayCtrl.so │ │ │ ├── libhcnetsdk.so │ │ │ ├── libssl.so.1.1 │ │ │ ├── libAudioRender.so │ │ │ ├── libSuperRender.so │ │ │ ├── libcrypto.so.1.1 │ │ │ ├── HCNetSDKCom │ │ │ ├── libHCAlarm.so │ │ │ ├── libiconv.so.2 │ │ │ ├── libHCDisplay.so │ │ │ ├── libHCPreview.so │ │ │ ├── libHCCoreDevCfg.so │ │ │ ├── libHCIndustry.so │ │ │ ├── libHCPlayBack.so │ │ │ ├── libHCVoiceTalk.so │ │ │ ├── libanalyzedata.so │ │ │ ├── libAudioIntercom.so │ │ │ ├── libHCGeneralCfgMgr.so │ │ │ ├── libStreamTransClient.so │ │ │ └── libSystemTransform.so │ │ │ └── HCNetSDK_Log_Switch.xml │ ├── logo.png │ ├── QuickNV.HikvisionNetSDK.Native.nuspec │ └── build │ │ └── net45 │ │ └── Hikvision.NetSDK.Native.props ├── QuickNV.HikvisionNetSDK.Generator │ ├── CHCNetSDK.cs │ ├── ErrorInfo.cs │ ├── QuickNV.HikvisionNetSDK.Generator.csproj │ └── Program.cs ├── QuickNV.HikvisionNetSDK.Api │ ├── HvLogLevel.cs │ ├── HvStreamType.cs │ ├── HvChannel.cs │ ├── HvRtspPathFormat.cs │ ├── HvIpChannel.cs │ ├── HvDeviceConfig.cs │ ├── HvNetworkConfig.cs │ ├── Utils │ │ └── StringUtils.cs │ ├── HvPTZCommand.cs │ ├── QuickNV.HikvisionNetSDK.Api.csproj │ ├── HvRemoteFile.cs │ ├── Service │ │ ├── PictureService.cs │ │ ├── SdkService.cs │ │ ├── VideoFileService.cs │ │ ├── ConfigService.cs │ │ └── ChannelService.cs │ ├── HvPreset.cs │ ├── README.md │ ├── HvHdConfig.cs │ └── HvSession.cs ├── QuickNV.HikvisionNetSDK.Sample │ ├── QuickNV.HikvisionNetSDK.Sample.csproj │ └── Program.cs ├── QuickNV.HikvisionNetSDK.Api.Sample │ ├── QuickNV.HikvisionNetSDK.Api.Sample.csproj │ └── Program.cs ├── QuickNV.HikvisionNetSDK │ ├── Defines.Preset.cs │ ├── HikvisionExtensions.cs │ ├── HikvisionException.cs │ ├── QuickNV.HikvisionNetSDK.csproj │ ├── README.md │ └── Errors.cs └── QuickNV.HikvisionNetSDK.sln ├── README.md ├── logo.png └── .gitignore /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/lib/netstandard1.0/_._: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QuickNV.HikvisionNetSDK 2 | QuickNV.HikvisionNetSDK -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/LocalSensorAdd.dat: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/logo.png -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/logo.png -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Generator/CHCNetSDK.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Generator/CHCNetSDK.cs -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libz.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libz.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HXVA.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HXVA.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/NPQos.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/NPQos.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/hlog.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/hlog.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/hpr.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/hpr.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/zlib1.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libz.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libz.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libhpr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libhpr.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/GdiPlus.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/GdiPlus.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCCore.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCCore.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HmMerge.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HmMerge.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/libmmd.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/libmmd.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libhpr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libhpr.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libssl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libssl.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libHCCore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libHCCore.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libNPQos.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libNPQos.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDK.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/LocalXml.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/LocalXml.zip -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/MP_Render.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/MP_Render.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/OpenAL32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/OpenAL32.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/PlayCtrl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/PlayCtrl.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/YUVProcess.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/YUVProcess.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libHCCore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libHCCore.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libcrypto.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libPlayCtrl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libPlayCtrl.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libhcnetsdk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libhcnetsdk.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libopenal.so.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libopenal.so.1 -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libssl.so.1.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libssl.so.1.1 -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/AudioRender.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/AudioRender.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/SuperRender.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/SuperRender.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libPlayCtrl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libPlayCtrl.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libhcnetsdk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libhcnetsdk.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libssl.so.1.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libssl.so.1.1 -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libAudioRender.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libAudioRender.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libSuperRender.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libSuperRender.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libcrypto.so.1.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/libcrypto.so.1.1 -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/libssl-1_1-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/libssl-1_1-x64.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libAudioRender.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libAudioRender.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libSuperRender.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libSuperRender.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libcrypto.so.1.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/libcrypto.so.1.1 -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/libcrypto-1_1-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/libcrypto-1_1-x64.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCAlarm.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCAlarm.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/OpenAL32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/OpenAL32.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libiconv2.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libiconv2.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDK_Log_Switch.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDK_Log_Switch.xml -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCDisplay.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCDisplay.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCIndustry.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCIndustry.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCPlayBack.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCPlayBack.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCPreview.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCPreview.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/libiconv2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/libiconv2.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCAlarm.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCAlarm.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libiconv.so.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libiconv.so.2 -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDK_Log_Switch.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDK_Log_Switch.xml -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCAlarm.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCAlarm.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCDisplay.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCDisplay.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCPreview.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCPreview.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/AnalyzeData.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/AnalyzeData.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/AudioIntercom.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/AudioIntercom.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/AudioRender.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/AudioRender.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCCoreDevCfg.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCCoreDevCfg.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCVoiceTalk.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCVoiceTalk.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCDisplay.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCDisplay.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCPreview.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCPreview.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCIndustry.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCIndustry.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCPlayBack.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCPlayBack.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCVoiceTalk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCVoiceTalk.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libanalyzedata.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libanalyzedata.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCGeneralCfgMgr.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/HCGeneralCfgMgr.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/SystemTransform.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/SystemTransform.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCCoreDevCfg.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCCoreDevCfg.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCIndustry.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCIndustry.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCPlayBack.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCPlayBack.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCVoiceTalk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCVoiceTalk.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libanalyzedata.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libanalyzedata.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libAudioIntercom.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libAudioIntercom.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCCoreDevCfg.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCCoreDevCfg.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/StreamTransClient.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/win-x64/native/HCNetSDKCom/StreamTransClient.dll -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libAudioIntercom.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libAudioIntercom.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCGeneralCfgMgr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libHCGeneralCfgMgr.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libSystemTransform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libSystemTransform.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCGeneralCfgMgr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libHCGeneralCfgMgr.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libStreamTransClient.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libStreamTransClient.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libSystemTransform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-arm64/native/HCNetSDKCom/libSystemTransform.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libStreamTransClient.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuickNV/QuickNV.HikvisionNetSDK/HEAD/src/QuickNV.HikvisionNetSDK.Native/runtimes/linux-x64/native/HCNetSDKCom/libStreamTransClient.so -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvLogLevel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickNV.HikvisionNetSDK.Api 6 | { 7 | public enum HvLogLevel 8 | { 9 | Close = 0, 10 | Error = 1, 11 | ErrorAndDebug = 2, 12 | All = 3 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvStreamType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickNV.HikvisionNetSDK.Api 6 | { 7 | public enum HvStreamType 8 | { 9 | Main = 1, 10 | Sub = 2, 11 | StreamType3 = 3, 12 | StreamType4 = 4 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Generator/ErrorInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace CHCNetSDK_Splitter 8 | { 9 | public class ErrorInfo 10 | { 11 | public string Name { get; set; } 12 | public string Value { get; set; } 13 | public string Description { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvChannel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickNV.HikvisionNetSDK.Api 6 | { 7 | public class HvChannel 8 | { 9 | public int Id { get; } 10 | public string Name { get; internal set; } 11 | public virtual int RtspChannelId => Id; 12 | 13 | internal HvChannel(int id) 14 | { 15 | Id = id; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvRtspPathFormat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuickNV.HikvisionNetSDK.Api 4 | { 5 | public enum HvRtspPathFormat 6 | { 7 | /// 8 | /// 2012年以前路径格式。示例:rtsp://192.168.1.65/h264/ch1/sub/av_stream 9 | /// 10 | AvStream, 11 | /// 12 | /// 2012年以后路径格式。rtsp://192.168.1.65/Streaming/Channels/102 13 | /// 14 | Streaming 15 | } 16 | } -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Sample/QuickNV.HikvisionNetSDK.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvIpChannel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickNV.HikvisionNetSDK.Api 6 | { 7 | public class HvIpChannel : HvChannel 8 | { 9 | private int rtspChannelId; 10 | public bool IsOnline { get; } 11 | public override int RtspChannelId => rtspChannelId; 12 | internal HvIpChannel(int id, int rtspChannelId, bool isOnline) : base(id) 13 | { 14 | IsOnline = isOnline; 15 | this.rtspChannelId = rtspChannelId; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api.Sample/QuickNV.HikvisionNetSDK.Api.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK/Defines.Preset.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuickNV.HikvisionNetSDK 4 | { 5 | public partial class Defines 6 | { 7 | public const int NET_DVR_GET_PRESETCFG = 3224; //获取预置点参数 8 | public const int NET_DVR_GET_PRESET_NUM = 3226; //获取预置点个数 9 | 10 | //预置位信息 11 | [StructLayoutAttribute(LayoutKind.Sequential)] 12 | public struct NET_DVR_PRESET_INFO 13 | { 14 | public uint dwSize; //结构体大小 15 | public uint dwPresetNum; //预置点个数 16 | public uint dwGroupNum; //组数 17 | [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 8, ArraySubType = UnmanagedType.I1)] 18 | public byte[] byRes; //保留 19 | } 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvDeviceConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickNV.HikvisionNetSDK.Api 6 | { 7 | public class HvDeviceConfig 8 | { 9 | public int AnalogChannel { get; internal set; } 10 | public int IPChannel { get; internal set; } 11 | public int ZeroChannel { get; internal set; } 12 | public int NetworkPort { get; internal set; } 13 | public int AlarmInPort { get; internal set; } 14 | public int AlarmOutPort { get; internal set; } 15 | public string Serial { get; internal set; } 16 | public string Version { get; internal set; } 17 | public string TypeName { get; internal set; } 18 | public string Name { get; internal set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using static QuickNV.HikvisionNetSDK.Defines; 2 | using static QuickNV.HikvisionNetSDK.Methods; 3 | 4 | var host = "127.0.0.1"; 5 | var port = 8000; 6 | var user = "admin"; 7 | var password = "123456"; 8 | 9 | try 10 | { 11 | NET_DVR_Init(); 12 | Console.WriteLine("初始化成功!"); 13 | //登录 14 | Console.WriteLine("正在登录..."); 15 | NET_DVR_DEVICEINFO_V30 deviceInfo = default; 16 | var userId = Invoke(NET_DVR_Login_V30(host, port, user, password, ref deviceInfo)); 17 | Console.WriteLine("登录成功!"); 18 | //退出登录 19 | NET_DVR_Logout_V30(userId); 20 | Console.WriteLine("退出登录完成"); 21 | //清理 22 | NET_DVR_Cleanup(); 23 | Console.WriteLine("清理完成"); 24 | } 25 | catch (Exception ex) 26 | { 27 | Console.WriteLine(ex.ToString()); 28 | } -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Generator/QuickNV.HikvisionNetSDK.Generator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | PreserveNewest 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/QuickNV.HikvisionNetSDK.Native.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QuickNV.HikvisionNetSDK.Native 5 | 1.0.3 6 | Hikvision 7 | Hikvision 8 | false 9 | logo.png 10 | https://github.com/QuickNV/QuickNV.HikvisionNetSDK 11 | Native Hikvision NetSDK binaries(v6.1.9.48).Include win-x64,linux-x64,linux-arm64. 12 | Public Domain 13 | Hikvision,NetSDK 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK/HikvisionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static QuickNV.HikvisionNetSDK.Defines; 3 | 4 | namespace QuickNV.HikvisionNetSDK 5 | { 6 | public static class HikvisionExtensions 7 | { 8 | public static DateTime ToDateTime(this NET_DVR_TIME time) 9 | { 10 | return new DateTime(time.dwYear, time.dwMonth, time.dwDay, time.dwHour, time.dwMinute, time.dwSecond, DateTimeKind.Local); 11 | } 12 | 13 | public static NET_DVR_TIME ToNET_DVR_TIME(this DateTime time) 14 | { 15 | return new NET_DVR_TIME() 16 | { 17 | dwYear = time.Year, 18 | dwMonth = time.Month, 19 | dwDay = time.Day, 20 | dwHour = time.Hour, 21 | dwMinute = time.Minute, 22 | dwSecond = time.Second 23 | }; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvNetworkConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickNV.HikvisionNetSDK.Api 6 | { 7 | public class HvNetworkConfig 8 | { 9 | public string IPAddress { get; internal set; } 10 | public string GateWay { get; internal set; } 11 | public string SubMask { get; internal set; } 12 | public string Dns { get; internal set; } 13 | public string HostIP { get; internal set; } 14 | public string PPPoEName { get; internal set; } 15 | public string PPPoEPassword { get; internal set; } 16 | public int AlarmHostIpPort { get; internal set; } 17 | public int HttpPort { get; internal set; } 18 | public int DVRPort { get; internal set; } 19 | public bool DHCP { get; internal set; } 20 | public bool PPPoE { get; internal set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/Utils/StringUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickNV.HikvisionNetSDK.Api.Utils 6 | { 7 | public class StringUtils 8 | { 9 | public static string ByteArray2String(byte[] buffer) 10 | { 11 | return ByteArray2String(buffer, Encoding.ASCII); 12 | } 13 | 14 | public static string ByteArray2String(byte[] buffer, Encoding encoding) 15 | { 16 | return encoding.GetString(buffer).Trim(char.MinValue); 17 | } 18 | 19 | public static void String2ByteArray(string str, byte[] buffer) 20 | { 21 | String2ByteArray(str, buffer, Encoding.ASCII); 22 | } 23 | 24 | public static void String2ByteArray(string str, byte[] buffer, Encoding encoding) 25 | { 26 | encoding.GetBytes(str, 0, str.Length, buffer, 0); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK/HikvisionException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Reflection; 4 | 5 | namespace QuickNV.HikvisionNetSDK 6 | { 7 | public class HikvisionException : Exception 8 | { 9 | private string _Message; 10 | public uint ErrorCode { get; } 11 | public override string Message => _Message; 12 | 13 | public HikvisionException(uint errorCode) 14 | { 15 | ErrorCode = errorCode; 16 | _Message = GetEnumDescription((Errors)ErrorCode); 17 | } 18 | 19 | private static string GetEnumDescription(Errors value) 20 | { 21 | string val = value.ToString(); 22 | FieldInfo fi = value.GetType().GetField(val); 23 | val = fi.GetCustomAttribute()?.Description; 24 | if (string.IsNullOrEmpty(val)) 25 | val = value.ToString(); 26 | return val; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvPTZCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuickNV.HikvisionNetSDK.Api 6 | { 7 | public enum HvPTZCommand : uint 8 | { 9 | LIGHT_PWRON = 2, //接通灯光电源 10 | WIPER_PWRON = 3, //接通雨刷开关 11 | FAN_PWRON = 4, // 接通风扇开关 12 | HEATER_PWRON = 5, // 接通加热器开关 13 | AUX_PWRON1 = 6, // 接通辅助设备开关 14 | AUX_PWRON2 = 7, // 接通辅助设备开关 15 | ZOOM_IN = 11, // 焦距变大(倍率变大) 16 | ZOOM_OUT = 12, // 焦距变小(倍率变小) 17 | FOCUS_NEAR = 13, // 焦点前调 18 | FOCUS_FAR = 14, // 焦点后调 19 | IRIS_OPEN = 15, // 光圈扩大 20 | IRIS_CLOSE = 16, // 光圈缩小 21 | TILT_UP = 21, // 云台上仰 22 | TILT_DOWN = 22, // 云台下俯 23 | PAN_LEFT = 23, // 云台左转 24 | PAN_RIGHT = 24, // 云台右转 25 | UP_LEFT = 25, // 云台上仰和左转 26 | UP_RIGHT = 26, // 云台上仰和右转 27 | DOWN_LEFT = 27, // 云台下俯和左转 28 | DOWN_RIGHT = 28, // 云台下俯和右转 29 | PAN_AUTO = 29// 云台左右自动扫描 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK/QuickNV.HikvisionNetSDK.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | aaasoft 6 | https://github.com/QuickNV/QuickNV.HikvisionNetSDK 7 | Hikvision, SDK 8 | https://github.com/QuickNV/QuickNV.HikvisionNetSDK.git 9 | git 10 | Hikvision NetSDK原始API 11 | 2025.4.1212 12 | logo.png 13 | README.md 14 | true 15 | $(NoWarn);1591 16 | 17 | 18 | 19 | 20 | True 21 | \ 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | True 32 | \ 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/QuickNV.HikvisionNetSDK.Api.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | aaasoft 6 | https://github.com/QuickNV/QuickNV.HikvisionNetSDK 7 | Hikvision, SDK 8 | https://github.com/QuickNV/QuickNV.HikvisionNetSDK.git 9 | git 10 | Hikvision NetSDK二次开发API 11 | 2025.4.1212 12 | logo.png 13 | README.md 14 | true 15 | $(NoWarn);1591 16 | 17 | 18 | 19 | 20 | True 21 | \ 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | True 32 | \ 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK/README.md: -------------------------------------------------------------------------------- 1 | # QuickNV.HikvisionNetSDK 2 | * Avaliable as [nuget](https://www.nuget.org/packages/QuickNV.HikvisionNetSDK/) 3 | 4 | * [![NuGet Downloads](https://img.shields.io/nuget/dt/QuickNV.HikvisionNetSDK.svg)](https://www.nuget.org/packages/QuickNV.HikvisionNetSDK/) 5 | 6 | * Hikvision NetSDK. 7 | 8 | 说明 9 | ``` 10 | SDK定义类:QuickNV.HikvisionNetSDK.Defines 11 | SDK方法类:QuickNV.HikvisionNetSDK.Methods 12 | SDK错误枚举:QuickNV.HikvisionNetSDK.Errors 13 | ``` 14 | 15 | 示例 16 | ``` 17 | using static QuickNV.HikvisionNetSDK.Defines; 18 | using static QuickNV.HikvisionNetSDK.Methods; 19 | 20 | var host = "127.0.0.1"; 21 | var port = 8000; 22 | var user = "admin"; 23 | var password = "123456"; 24 | 25 | try 26 | { 27 | NET_DVR_Init(); 28 | Console.WriteLine("初始化成功!"); 29 | //登录 30 | Console.WriteLine("正在登录..."); 31 | NET_DVR_DEVICEINFO_V30 deviceInfo = default; 32 | var userId = Invoke(NET_DVR_Login_V30(host, port, user, password, ref deviceInfo)); 33 | Console.WriteLine("登录成功!"); 34 | //退出登录 35 | NET_DVR_Logout_V30(userId); 36 | Console.WriteLine("退出登录完成"); 37 | //清理 38 | NET_DVR_Cleanup(); 39 | Console.WriteLine("清理完成"); 40 | } 41 | catch (Exception ex) 42 | { 43 | Console.WriteLine(ex.ToString()); 44 | } 45 | ``` -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvRemoteFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using static QuickNV.HikvisionNetSDK.Defines; 5 | 6 | namespace QuickNV.HikvisionNetSDK.Api 7 | { 8 | public class HvRemoteFile 9 | { 10 | public string Name { get; set; } 11 | public DateTime StartTime { get; set; } 12 | public DateTime StopTime { get; set; } 13 | public long Size { get; set; } 14 | 15 | internal HvRemoteFile(NET_DVR_FIND_PICTURE_V50 findData) 16 | { 17 | Name = Encoding.Default.GetString(findData.sFileName); 18 | StartTime = findData.struTime.ToDateTime(); 19 | Size = findData.dwFileSize; 20 | } 21 | 22 | internal HvRemoteFile(NET_DVR_FINDDATA_V30 findData) 23 | { 24 | Name = findData.sFileName; 25 | StartTime = findData.struStartTime.ToDateTime(); 26 | StopTime = findData.struStopTime.ToDateTime(); 27 | Size = findData.dwFileSize; 28 | } 29 | 30 | internal HvRemoteFile(NET_DVR_FINDDATA_V40 findData) 31 | { 32 | Name = findData.sFileName; 33 | StartTime = findData.struStartTime.ToDateTime(); 34 | StopTime = findData.struStopTime.ToDateTime(); 35 | Size = findData.dwFileSize; 36 | } 37 | 38 | public HvRemoteFile() 39 | { 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Native/build/net45/Hikvision.NetSDK.Native.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | x86\%(Filename)%(Extension) 6 | PreserveNewest 7 | False 8 | 9 | 10 | x64\%(Filename)%(Extension) 11 | PreserveNewest 12 | False 13 | 14 | 15 | 16 | 17 | %(Filename)%(Extension) 18 | PreserveNewest 19 | False 20 | 21 | 22 | 23 | 24 | %(Filename)%(Extension) 25 | PreserveNewest 26 | False 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/Service/PictureService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices.ComTypes; 4 | using System.Text; 5 | using static QuickNV.HikvisionNetSDK.Defines; 6 | using static QuickNV.HikvisionNetSDK.Methods; 7 | 8 | namespace QuickNV.HikvisionNetSDK.Api.Service 9 | { 10 | public class PictureService 11 | { 12 | private HvSession session; 13 | internal PictureService(HvSession session) 14 | { 15 | this.session = session; 16 | } 17 | 18 | public void CaptureJPEGPicture(int channelId, string fileName) 19 | { 20 | NET_DVR_JPEGPARA lpJpegPara = new NET_DVR_JPEGPARA(); 21 | lpJpegPara.wPicQuality = 0; //图像质量 Image quality 22 | lpJpegPara.wPicSize = 0xff; //抓图分辨率 Picture size: 0xff-Auto(使用当前码流分辨率) 23 | //抓图分辨率需要设备支持,更多取值请参考SDK文档 24 | Invoke(NET_DVR_CaptureJPEGPicture(session.UserId, channelId, ref lpJpegPara, fileName)); 25 | } 26 | 27 | public byte[] CaptureJPEGPicture_NEW(int channelId) 28 | { 29 | byte[] buffer = new byte[10 * 1024 * 1024]; 30 | NET_DVR_JPEGPARA lpJpegPara = new NET_DVR_JPEGPARA(); 31 | lpJpegPara.wPicQuality = 0; //图像质量 Image quality 32 | lpJpegPara.wPicSize = 0xff; //抓图分辨率 Picture size: 0xff-Auto(使用当前码流分辨率) 33 | uint ret = 0; 34 | Invoke(NET_DVR_CaptureJPEGPicture_NEW(session.UserId, channelId, ref lpJpegPara, buffer, (uint)buffer.Length, ref ret)); 35 | var retBuffer = new byte[ret]; 36 | Buffer.BlockCopy(buffer, 0, retBuffer, 0, (int)ret); 37 | return retBuffer; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvPreset.cs: -------------------------------------------------------------------------------- 1 | namespace QuickNV.HikvisionNetSDK.Api 2 | { 3 | /// 4 | /// 预置点信息 5 | /// 6 | public class HvPreset 7 | { 8 | public HvPreset(int number, string name) 9 | { 10 | Number = number; 11 | Name = name; 12 | } 13 | 14 | /// 15 | /// 预置点编号(从1开始) 16 | /// 17 | public int Number { get; internal set; } 18 | 19 | /// 20 | /// 预置点名称 21 | /// 22 | public string Name { get; internal set; } 23 | 24 | /// 25 | /// 水平参数:角度 26 | /// 27 | public double PanPos { get; set; } 28 | 29 | /// 30 | /// 垂直参数:角度 31 | /// 32 | public double TiltPos { get; set; } 33 | 34 | /// 35 | /// 变倍参数:倍数 36 | /// 37 | public double ZoomPos { get; set; } 38 | 39 | /// 40 | /// 是否被设置 41 | /// 42 | public bool IsSet => PanPos != 0 && TiltPos != 0; 43 | 44 | public override string ToString() 45 | { 46 | return $"[{Number}] {Name} P:{PanPos} T:{TiltPos} Z:{ZoomPos}"; 47 | } 48 | } 49 | 50 | /// 51 | /// PTZ位置信息 52 | /// 53 | public class HvPtzPosition 54 | { 55 | public HvPtzPosition() 56 | { 57 | } 58 | 59 | public HvPtzPosition(double panPos, double tiltPos, double zoomPos) 60 | { 61 | PanPos = panPos; 62 | TiltPos = tiltPos; 63 | ZoomPos = zoomPos; 64 | } 65 | 66 | /// 67 | /// 水平参数:角度 68 | /// 69 | public double PanPos { get; set; } 70 | 71 | /// 72 | /// 垂直参数:角度 73 | /// 74 | public double TiltPos { get; set; } 75 | 76 | /// 77 | /// 变倍参数:倍数 78 | /// 79 | public double ZoomPos { get; set; } 80 | } 81 | } -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/Service/SdkService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | using System.Text; 5 | using static QuickNV.HikvisionNetSDK.Defines; 6 | using static QuickNV.HikvisionNetSDK.Methods; 7 | 8 | namespace QuickNV.HikvisionNetSDK.Api.Service 9 | { 10 | public class SdkService 11 | { 12 | private const int NET_SDK_LOCAL_CFG_TYPE_CHECK_DEV = 10; 13 | public bool SetConnectTime(uint waitTimeMilliseconds, uint tryTimes) 14 | => Invoke(NET_DVR_SetConnectTime(waitTimeMilliseconds, tryTimes)); // 2000 , 1 15 | public bool SetReconnect(uint interval, int enableRecon) 16 | => Invoke(NET_DVR_SetReconnect(interval, enableRecon)); // 10000 , 1 17 | public bool SetupLogs(HvLogLevel logLevel, string logDirectory, bool autoDelete) 18 | => Invoke(NET_DVR_SetLogToFile((int)logLevel, logDirectory, autoDelete)); 19 | 20 | public NET_DVR_LOCAL_CHECK_DEV GetLocalCheckDev() 21 | { 22 | NET_DVR_LOCAL_CHECK_DEV config = default; 23 | var ptrSize = Marshal.SizeOf(config); 24 | IntPtr ptr = Marshal.AllocHGlobal(ptrSize); 25 | try 26 | { 27 | Invoke(NET_DVR_GetSDKLocalCfg(NET_SDK_LOCAL_CFG_TYPE_CHECK_DEV, ptr)); 28 | config = Marshal.PtrToStructure(ptr); 29 | return config; 30 | } 31 | catch 32 | { 33 | throw; 34 | } 35 | finally 36 | { 37 | Marshal.FreeHGlobal(ptr); 38 | } 39 | } 40 | 41 | public void SetLocalCheckDev(NET_DVR_LOCAL_CHECK_DEV config) 42 | { 43 | IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(config)); 44 | try 45 | { 46 | Marshal.StructureToPtr(config, ptr, false); 47 | Invoke(NET_DVR_SetSDKLocalCfg(NET_SDK_LOCAL_CFG_TYPE_CHECK_DEV, ptr)); 48 | } 49 | catch 50 | { 51 | throw; 52 | } 53 | finally 54 | { 55 | Marshal.FreeHGlobal(ptr); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/README.md: -------------------------------------------------------------------------------- 1 | # QuickNV.HikvisionNetSDK.Api 2 | * Avaliable as [nuget](https://www.nuget.org/packages/QuickNV.HikvisionNetSDK.Api/) 3 | 4 | * [![NuGet Downloads](https://img.shields.io/nuget/dt/QuickNV.HikvisionNetSDK.Api.svg)](https://www.nuget.org/packages/QuickNV.HikvisionNetSDK.Api/) 5 | 6 | * Api for Hikvision NetSDK. 7 | 8 | 示例 9 | ``` 10 | using QuickNV.HikvisionNetSDK.Api; 11 | using Newtonsoft.Json; 12 | using System.Text; 13 | 14 | var host = "127.0.0.1"; 15 | var port = 8000; 16 | var user = "admin"; 17 | var password = "123456"; 18 | var encoding = CodePagesEncodingProvider.Instance.GetEncoding("gb2312"); 19 | 20 | try 21 | { 22 | HvSession.Init(); 23 | Console.WriteLine("初始化成功!"); 24 | //登录 25 | Console.WriteLine("正在登录..."); 26 | var session = HvSession.Login(host, port, user, password, encoding); 27 | Console.WriteLine("登录成功!"); 28 | Console.WriteLine("设备时间: " + session.ConfigService.GetTime()); 29 | Console.WriteLine("设备配置: " + JsonConvert.SerializeObject(session.ConfigService.GetDeviceConfig(), Formatting.Indented)); 30 | Console.WriteLine("网络配置: " + JsonConvert.SerializeObject(session.ConfigService.GetNetworkConfig(), Formatting.Indented)); 31 | Console.WriteLine("硬盘配置: " + JsonConvert.SerializeObject(session.ConfigService.GetHdConfig(), Formatting.Indented)); 32 | Console.WriteLine("正在读取通道名称..."); 33 | session.ChannelService.RefreshChannelsName(); 34 | Console.WriteLine("模拟通道:" + string.Join(",", session.ChannelService.AnalogChannels.Select(t => $"通道{t.Id}_{t.Name}"))); 35 | Console.WriteLine("IP通道:" + string.Join(",", session.ChannelService.IpChannels.Select(t => $"通道{t.Id}_{t.Name}"))); 36 | //如果存在IP通道 37 | if (session.ChannelService.IpChannels.Count > 0) 38 | { 39 | Console.WriteLine("开始下载..."); 40 | var channel = session.ChannelService.IpChannels.First(); 41 | var stopTime = DateTime.Now; 42 | var startTime = stopTime.AddMinutes(-1); 43 | var localFileName = $"{channel.Name}_{startTime.ToString("yyyyMMddHHmmss")}_{stopTime.ToString("yyyyMMddHHmmss")}.mp4"; 44 | var fileHandle = session.VideoFileService.StartDownloadFile(channel.Id, startTime, stopTime, localFileName); 45 | while (true) 46 | { 47 | Thread.Sleep(1000); 48 | var progress = session.VideoFileService.GetDownloadPosition(fileHandle); 49 | if (progress < 0 || progress > 100) 50 | throw new Exception("Download error.Progress: " + progress); 51 | Console.CursorLeft = 0; 52 | Console.Write($"进度:{progress}%"); 53 | if (progress == 100) 54 | break; 55 | } 56 | Console.WriteLine(); 57 | session.VideoFileService.StopDownloadFile(fileHandle); 58 | Console.WriteLine("下载完成。文件:" + localFileName); 59 | } 60 | //退出登录 61 | session.Logout(); 62 | Console.WriteLine("退出登录完成"); 63 | 64 | //清理 65 | HvSession.Cleanup(); 66 | Console.WriteLine("清理完成"); 67 | } 68 | catch (Exception ex) 69 | { 70 | Console.WriteLine(ex.ToString()); 71 | } 72 | ``` -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.5.33516.290 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickNV.HikvisionNetSDK", "QuickNV.HikvisionNetSDK\QuickNV.HikvisionNetSDK.csproj", "{314B6538-5FF4-48D4-88D2-497B0C552E99}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickNV.HikvisionNetSDK.Generator", "QuickNV.HikvisionNetSDK.Generator\QuickNV.HikvisionNetSDK.Generator.csproj", "{C0F156BC-ECE2-4030-B620-CD8693F9843C}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickNV.HikvisionNetSDK.Sample", "QuickNV.HikvisionNetSDK.Sample\QuickNV.HikvisionNetSDK.Sample.csproj", "{8C3B597A-4765-489F-A853-E5866DA6EDBB}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickNV.HikvisionNetSDK.Api", "QuickNV.HikvisionNetSDK.Api\QuickNV.HikvisionNetSDK.Api.csproj", "{BE66715C-57D0-46B4-9FC4-E220A09E55BD}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickNV.HikvisionNetSDK.Api.Sample", "QuickNV.HikvisionNetSDK.Api.Sample\QuickNV.HikvisionNetSDK.Api.Sample.csproj", "{7C7AAFC8-0528-4EE4-A681-9695631FB094}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {314B6538-5FF4-48D4-88D2-497B0C552E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {314B6538-5FF4-48D4-88D2-497B0C552E99}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {314B6538-5FF4-48D4-88D2-497B0C552E99}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {314B6538-5FF4-48D4-88D2-497B0C552E99}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {C0F156BC-ECE2-4030-B620-CD8693F9843C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {C0F156BC-ECE2-4030-B620-CD8693F9843C}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {C0F156BC-ECE2-4030-B620-CD8693F9843C}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {C0F156BC-ECE2-4030-B620-CD8693F9843C}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {8C3B597A-4765-489F-A853-E5866DA6EDBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {8C3B597A-4765-489F-A853-E5866DA6EDBB}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {8C3B597A-4765-489F-A853-E5866DA6EDBB}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {8C3B597A-4765-489F-A853-E5866DA6EDBB}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {BE66715C-57D0-46B4-9FC4-E220A09E55BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {BE66715C-57D0-46B4-9FC4-E220A09E55BD}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {BE66715C-57D0-46B4-9FC4-E220A09E55BD}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {BE66715C-57D0-46B4-9FC4-E220A09E55BD}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {7C7AAFC8-0528-4EE4-A681-9695631FB094}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {7C7AAFC8-0528-4EE4-A681-9695631FB094}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {7C7AAFC8-0528-4EE4-A681-9695631FB094}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {7C7AAFC8-0528-4EE4-A681-9695631FB094}.Release|Any CPU.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {577DB075-88EC-4192-94FB-320BA1F35F09} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvHdConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using static QuickNV.HikvisionNetSDK.Defines; 5 | 6 | namespace QuickNV.HikvisionNetSDK.Api 7 | { 8 | public class HvHdConfig 9 | { 10 | public HvHdConfig() { } 11 | internal HvHdConfig(NET_DVR_SINGLE_HD hd) 12 | { 13 | Capacity = hd.dwCapacity; 14 | FreeSpace = hd.dwFreeSpace; 15 | HdStatus = hd.dwHdStatus; 16 | HDAttr = hd.byHDAttr; 17 | HDType = hd.byHDType; 18 | Recycling = hd.byRecycling; 19 | PictureCapacity = hd.dwPictureCapacity; 20 | FreePictureSpace = hd.dwFreePictureSpace; 21 | } 22 | 23 | public bool IsErrorStatus => HdStatus == 2; 24 | 25 | public uint Capacity { get; set; } 26 | public uint FreeSpace { get; set; } 27 | public uint HdStatus { get; set; } 28 | public byte HDAttr { get; set; } 29 | public byte HDType { get; set; } 30 | public byte Recycling { get; set; } 31 | public uint PictureCapacity { get; set; } 32 | public uint FreePictureSpace { get; set; } 33 | 34 | public override string ToString() 35 | { 36 | 37 | StringBuilder sb = new StringBuilder(); 38 | 39 | sb.AppendLine(); 40 | sb.AppendLine(GetRow(nameof(Capacity), ToGB(Capacity))); 41 | sb.AppendLine(GetRow(nameof(FreeSpace), ToGB(FreeSpace))); 42 | sb.AppendLine(GetRow(nameof(PictureCapacity), ToGB(PictureCapacity))); 43 | sb.AppendLine(GetRow(nameof(FreePictureSpace), ToGB(FreePictureSpace))); 44 | sb.AppendLine(GetRow(nameof(HdStatus), HdStatuses.TryGetValue(HdStatus, out var status) ? status : "unknown")); 45 | sb.AppendLine(GetRow(nameof(HDAttr), HdAttributes.TryGetValue(HDAttr, out var atr) ? atr : "unknown")); 46 | sb.AppendLine(GetRow(nameof(HDType), HdTypes.TryGetValue(HDType, out var hdType) ? hdType : "unknown")); 47 | sb.AppendLine(GetRow(nameof(Recycling), Convert.ToString(Recycling))); 48 | 49 | return sb.ToString(); 50 | } 51 | 52 | private static readonly Dictionary HdStatuses = new Dictionary 53 | { 54 | {0, "normal"}, 55 | {1, "unformatted"}, 56 | {2, "error"}, 57 | {3, "S.M.A.R.T state"}, 58 | {4, "not match"}, 59 | {5, "sleeping"}, 60 | {6, "unconnected(network disk)"}, 61 | {7, "virtual disk is normal and supports expansion"}, 62 | {10, "hard disk is being restored"}, 63 | {11, "hard disk is being formatted"}, 64 | {12, "hard disk is waiting formatted"}, 65 | {13, "the hard disk has been uninstalled"}, 66 | {14, "local hard disk does not exist"}, 67 | {15, "it is deleting the network disk"}, 68 | {16, "locked"} 69 | }; 70 | 71 | private static readonly Dictionary HdAttributes = new Dictionary 72 | { 73 | {0, "default"}, 74 | {1, "redundancy (back up important data)"}, 75 | {2, "read only"}, 76 | {3, "Archiving"}, 77 | {4, "Cannot be read/read"} 78 | }; 79 | 80 | private static readonly Dictionary HdTypes = new Dictionary 81 | { 82 | {0, "local disk"}, 83 | {1, "eSATA disk"}, 84 | {2, "NFS disk"}, 85 | {3, "iSCSI disk"}, 86 | {4, "RAID virtual disk"}, 87 | {5, "SD card"}, 88 | {6, "miniSAS"} 89 | }; 90 | 91 | private string ToGB(uint mb) 92 | { 93 | return $"{mb / 1024.0:0.00} GB ({mb} Mb)"; 94 | } 95 | 96 | private string GetRow(string field, string value) 97 | { 98 | return $"{field,-24}: {value}"; 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/Service/VideoFileService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Threading; 5 | using static QuickNV.HikvisionNetSDK.Defines; 6 | using static QuickNV.HikvisionNetSDK.Methods; 7 | 8 | namespace QuickNV.HikvisionNetSDK.Api.Service 9 | { 10 | public class VideoFileService 11 | { 12 | private HvSession session; 13 | internal VideoFileService(HvSession session) 14 | { 15 | this.session = session; 16 | } 17 | 18 | public HvRemoteFile[] FindFile(int channelId, DateTime startTime, DateTime stopTime) 19 | { 20 | NET_DVR_FILECOND_V40 findcond = new NET_DVR_FILECOND_V40() 21 | { 22 | lChannel = channelId, 23 | struStartTime = startTime.ToNET_DVR_TIME(), 24 | struStopTime = stopTime.ToNET_DVR_TIME(), 25 | }; 26 | int iFindHandle = Invoke(NET_DVR_FindFile_V40(session.UserId, ref findcond)); 27 | try 28 | { 29 | var fileList = new List(); 30 | while (true) 31 | { 32 | NET_DVR_FINDDATA_V40 findData = default; 33 | var ret = Invoke(NET_DVR_FindNextFile_V40(iFindHandle, ref findData)); 34 | 35 | //没有更多的文件,查找结束 36 | if (ret == NET_DVR_NOMOREFILE) 37 | break; 38 | //获取文件信息成功 39 | if (ret == NET_DVR_FILE_SUCCESS) 40 | { 41 | fileList.Add(new HvRemoteFile(findData)); 42 | continue; 43 | } 44 | //未查找到文件 45 | if (ret == NET_DVR_FILE_NOFIND) 46 | break; 47 | //正在查找请等待 48 | if (ret == NET_DVR_ISFINDING) 49 | { 50 | Thread.Sleep(1000); 51 | continue; 52 | } 53 | //查找文件时异常 54 | if (ret == NET_DVR_FILE_EXCEPTION) 55 | { 56 | throw new IOException("NET_DVR_FindNextFile_V40 error,reason:" + NET_DVR_GetLastError()); 57 | } 58 | throw new IOException($"NET_DVR_FindNextFile_V40 error,reason: Unknow return code:{ret}"); 59 | } 60 | return fileList.ToArray(); 61 | } 62 | catch 63 | { 64 | throw; 65 | } 66 | finally 67 | { 68 | NET_DVR_FindClose_V30(iFindHandle); 69 | } 70 | } 71 | 72 | public int StartDownloadFile(int channelId, DateTime startTime, DateTime stopTime, string destinationPath) 73 | { 74 | NET_DVR_PLAYCOND playcond = new NET_DVR_PLAYCOND() 75 | { 76 | dwChannel = (uint)channelId, 77 | struStartTime = startTime.ToNET_DVR_TIME(), 78 | struStopTime = stopTime.ToNET_DVR_TIME(), 79 | }; 80 | int iPlayHandle = Invoke(NET_DVR_GetFileByTime_V40(session.UserId, destinationPath, ref playcond)); 81 | uint iOutValue = 0; 82 | Invoke(NET_DVR_PlayBackControl_V40(iPlayHandle, NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue)); 83 | return iPlayHandle; 84 | } 85 | 86 | public virtual int StartDownloadFile(string remoteFile, string destinationPath) 87 | { 88 | int iPlayHandle = Invoke(NET_DVR_GetFileByName(session.UserId, remoteFile, destinationPath)); 89 | uint iOutValue = 0; 90 | Invoke(NET_DVR_PlayBackControl_V40(iPlayHandle, NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue)); 91 | return iPlayHandle; 92 | } 93 | 94 | public int GetDownloadPosition(int fileHandle)=> Invoke(NET_DVR_GetDownloadPos(fileHandle)); 95 | public void StopDownloadFile(int fileHandle)=> Invoke(NET_DVR_StopGetFile(fileHandle)); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/HvSession.cs: -------------------------------------------------------------------------------- 1 | using QuickNV.HikvisionNetSDK.Api.Service; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using static QuickNV.HikvisionNetSDK.Defines; 6 | using static QuickNV.HikvisionNetSDK.Methods; 7 | 8 | namespace QuickNV.HikvisionNetSDK.Api 9 | { 10 | public class HvSession : IDisposable 11 | { 12 | private static SdkService _SdkService; 13 | public static SdkService SdkService 14 | { 15 | get 16 | { 17 | if (_SdkService == null) 18 | { 19 | _SdkService = new SdkService(); 20 | } 21 | return _SdkService; 22 | } 23 | } 24 | 25 | public static void Init() 26 | { 27 | Invoke(NET_DVR_Init()); 28 | } 29 | 30 | public static HvSession Login(string host, int port, string username, string password, Encoding encoding) 31 | { 32 | NET_DVR_DEVICEINFO_V30 deviceInfo = default; 33 | var userId = Invoke(NET_DVR_Login_V30(host, port, username, password, ref deviceInfo)); 34 | var session = new HvSession(userId, encoding, deviceInfo); 35 | session.Host = host; 36 | session.Port = port; 37 | session.UserName = username; 38 | session.Password = password; 39 | return session; 40 | } 41 | public static HvSession Login(string host, int port, string username, string password) 42 | { 43 | return Login(host, port, username, password, Encoding.Default); 44 | } 45 | public static void Cleanup() => Invoke(NET_DVR_Cleanup()); 46 | 47 | public string Host { get; private set; } 48 | public int Port { get; private set; } 49 | public string UserName { get; private set; } 50 | public string Password { get; private set; } 51 | public int UserId { get; private set; } 52 | public bool IsOnline { get; private set; } = true; 53 | public Encoding Encoding { get; } 54 | private NET_DVR_DEVICEINFO_V30 deviceInfo; 55 | 56 | private HvSession(int userId, Encoding encoding, NET_DVR_DEVICEINFO_V30 deviceInfo) 57 | { 58 | UserId = userId; 59 | Encoding = encoding; 60 | this.deviceInfo = deviceInfo; 61 | } 62 | 63 | public void Logout() 64 | { 65 | if (!IsOnline) 66 | return; 67 | IsOnline = false; 68 | Invoke(NET_DVR_Logout_V30(UserId)); 69 | } 70 | 71 | public void Dispose() 72 | { 73 | Logout(); 74 | } 75 | 76 | private ChannelService _ChannelService; 77 | public ChannelService ChannelService 78 | { 79 | get 80 | { 81 | if (_ChannelService == null) 82 | _ChannelService = new ChannelService(this, deviceInfo); 83 | return _ChannelService; 84 | } 85 | } 86 | 87 | private ConfigService _ConfigService; 88 | public ConfigService ConfigService 89 | { 90 | get 91 | { 92 | if (_ConfigService == null) 93 | _ConfigService = new ConfigService(this); 94 | return _ConfigService; 95 | } 96 | } 97 | 98 | private PictureService _PictureService; 99 | public PictureService PictureService 100 | { 101 | get 102 | { 103 | if (_PictureService == null) 104 | _PictureService = new PictureService(this); 105 | return _PictureService; 106 | } 107 | } 108 | 109 | private VideoFileService _VideoFileService; 110 | public VideoFileService VideoFileService 111 | { 112 | get 113 | { 114 | if (_VideoFileService == null) 115 | _VideoFileService = new VideoFileService(this); 116 | return _VideoFileService; 117 | } 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api.Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using QuickNV.HikvisionNetSDK.Api; 2 | using Newtonsoft.Json; 3 | using System.Text; 4 | 5 | var host = "127.0.0.1"; 6 | var port = 8000; 7 | var user = "admin"; 8 | var password = "123456"; 9 | var encoding = CodePagesEncodingProvider.Instance.GetEncoding("gb2312"); 10 | 11 | try 12 | { 13 | HvSession.Init(); 14 | Console.WriteLine("初始化成功!"); 15 | //登录 16 | Console.WriteLine("正在登录..."); 17 | var session = HvSession.Login(host, port, user, password, encoding); 18 | Console.WriteLine("登录成功!"); 19 | Console.WriteLine("设备时间: " + session.ConfigService.GetTime()); 20 | Console.WriteLine("设备配置: " + JsonConvert.SerializeObject(session.ConfigService.GetDeviceConfig(), Formatting.Indented)); 21 | Console.WriteLine("网络配置: " + JsonConvert.SerializeObject(session.ConfigService.GetNetworkConfig(), Formatting.Indented)); 22 | Console.WriteLine("硬盘配置: " + JsonConvert.SerializeObject(session.ConfigService.GetHdConfigs(), Formatting.Indented)); 23 | Console.WriteLine("正在读取通道名称..."); 24 | session.ChannelService.RefreshChannelsName(); 25 | Console.WriteLine("模拟通道:" + string.Join(",", session.ChannelService.AnalogChannels.Select(t => $"通道{t.Id}_{t.Name}"))); 26 | Console.WriteLine("IP通道:" + string.Join(",", session.ChannelService.IpChannels.Select(t => $"通道{t.Id}_{t.Name}"))); 27 | 28 | //获取RTSP地址 29 | var rtsp = session.ChannelService.GetLiveRtspUrl(session.ChannelService.AllChannels.First(), HvStreamType.Main); 30 | //获取PTZ参数 31 | var ptzPosition = session.ChannelService.GetPtzPosition(session.ChannelService.AllChannels.First().Id); 32 | 33 | //设置当前位置为预置位并命名 34 | //session.ChannelService.SetPresetWithName(33, 5, "SDK测试-50"); 35 | //session.ChannelService.SetPresetWithName(1, 6, "SDK测试-6"); 36 | //转动到指定预置位 37 | //session.ChannelService.GotoPreset(33, 5); 38 | //删除预置位 39 | //session.ChannelService.RemovePreset(33, 6); 40 | //直到摄像机停止转动 41 | //await session.ChannelService.WaitUntilStopMovingAsync(33); 42 | 43 | //输出所有有效预置位 44 | foreach (var channel in session.ChannelService.AllChannels) 45 | { 46 | Console.WriteLine($"通道 [{channel.Name}] 预置位信息:"); 47 | var presets = session.ChannelService.GetPresets(channel.Id); 48 | foreach (var preset in presets) 49 | { 50 | Console.WriteLine(preset); 51 | } 52 | } 53 | 54 | //for (int i = 1; i <= 100; i += 2) 55 | //{ 56 | // var path1 = $"images/{i}.jpg"; 57 | // var path2 = $"images/{i + 1}.jpg"; 58 | 59 | // // 抓图方式1: 60 | // session.PictureService.CaptureJPEGPicture(session.ChannelService.AllChannels.First().Id, path1); 61 | 62 | // // 抓图方式2: 63 | // var pictureBytes = session.PictureService.CaptureJPEGPicture_NEW(session.ChannelService.AllChannels.First().Id); 64 | // File.WriteAllBytes(path2, pictureBytes); 65 | //} 66 | 67 | ////如果存在IP通道 68 | //if (session.ChannelService.IpChannels.Count > 0) 69 | //{ 70 | // Console.WriteLine("开始查找录像文件..."); 71 | // var channel = session.ChannelService.IpChannels.First(); 72 | // var stopTime = DateTime.Now; 73 | // var startTime = stopTime.AddDays(-1); 74 | // var files = session.VideoFileService.FindFile(channel.Id, startTime, stopTime); 75 | // Console.WriteLine("录像文件:" + JsonConvert.SerializeObject(files, Formatting.Indented)); 76 | // Console.WriteLine("查找录像文件完成."); 77 | 78 | 79 | // Console.WriteLine("开始下载..."); 80 | // //var channel = session.ChannelService.IpChannels.First(); 81 | // //var stopTime = DateTime.Now; 82 | // //var startTime = stopTime.AddMinutes(-1); 83 | // var localFileName = $"{channel.Name}_{startTime.ToString("yyyyMMddHHmmss")}_{stopTime.ToString("yyyyMMddHHmmss")}.mp4"; 84 | // var fileHandle = session.VideoFileService.StartDownloadFile(channel.Id, startTime, stopTime, localFileName); 85 | // while (true) 86 | // { 87 | // Thread.Sleep(1000); 88 | // var progress = session.VideoFileService.GetDownloadPosition(fileHandle); 89 | // if (progress < 0 || progress > 100) 90 | // throw new Exception("Download error.Progress: " + progress); 91 | // Console.CursorLeft = 0; 92 | // Console.Write($"进度:{progress}%"); 93 | // if (progress == 100) 94 | // break; 95 | // } 96 | // Console.WriteLine(); 97 | // session.VideoFileService.StopDownloadFile(fileHandle); 98 | // Console.WriteLine("下载完成。文件:" + localFileName); 99 | 100 | //} 101 | //退出登录 102 | session.Logout(); 103 | Console.WriteLine("退出登录完成"); 104 | 105 | //清理 106 | HvSession.Cleanup(); 107 | Console.WriteLine("清理完成"); 108 | 109 | Console.ReadLine(); 110 | } 111 | catch (Exception ex) 112 | { 113 | Console.WriteLine(ex.ToString()); 114 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/Service/ConfigService.cs: -------------------------------------------------------------------------------- 1 | using QuickNV.HikvisionNetSDK.Api.Utils; 2 | using System; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using static QuickNV.HikvisionNetSDK.Defines; 6 | using static QuickNV.HikvisionNetSDK.Methods; 7 | 8 | namespace QuickNV.HikvisionNetSDK.Api.Service 9 | { 10 | public class ConfigService 11 | { 12 | private HvSession session; 13 | internal ConfigService(HvSession session) 14 | { 15 | this.session = session; 16 | } 17 | 18 | public DateTime GetTime() 19 | { 20 | NET_DVR_TIME m_struTimeCfg = default; 21 | uint dwReturn = 0; 22 | int nSize = Marshal.SizeOf(m_struTimeCfg); 23 | IntPtr ptrTimeCfg = Marshal.AllocHGlobal(nSize); 24 | try 25 | { 26 | Marshal.StructureToPtr(m_struTimeCfg, ptrTimeCfg, false); 27 | Invoke(NET_DVR_GetDVRConfig(session.UserId, NET_DVR_GET_TIMECFG, 1, ptrTimeCfg, (uint)nSize, ref dwReturn)); 28 | m_struTimeCfg = Marshal.PtrToStructure(ptrTimeCfg); 29 | return m_struTimeCfg.ToDateTime(); 30 | } 31 | catch 32 | { 33 | throw; 34 | } 35 | finally 36 | { 37 | Marshal.FreeHGlobal(ptrTimeCfg); 38 | } 39 | } 40 | 41 | public void SetTime(DateTime dateTime) 42 | { 43 | NET_DVR_TIME m_struTimeCfg = dateTime.ToNET_DVR_TIME(); 44 | int nSize = Marshal.SizeOf(m_struTimeCfg); 45 | IntPtr ptrTimeCfg = Marshal.AllocHGlobal(nSize); 46 | try 47 | { 48 | Marshal.StructureToPtr(m_struTimeCfg, ptrTimeCfg, false); 49 | Invoke(NET_DVR_SetDVRConfig(session.UserId, NET_DVR_SET_TIMECFG, -1, ptrTimeCfg, (uint)nSize)); 50 | } 51 | catch 52 | { 53 | throw; 54 | } 55 | finally 56 | { 57 | Marshal.FreeHGlobal(ptrTimeCfg); 58 | } 59 | } 60 | 61 | public HvNetworkConfig GetNetworkConfig() 62 | { 63 | NET_DVR_NETCFG_V30 m_struNetCfg = default; 64 | uint dwReturn = 0; 65 | int nSize = Marshal.SizeOf(m_struNetCfg); 66 | IntPtr ptrNetCfg = Marshal.AllocHGlobal(nSize); 67 | try 68 | { 69 | Marshal.StructureToPtr(m_struNetCfg, ptrNetCfg, false); 70 | 71 | Invoke(NET_DVR_GetDVRConfig(session.UserId, NET_DVR_GET_NETCFG_V30, -1, ptrNetCfg, (uint)nSize, ref dwReturn)); 72 | m_struNetCfg = Marshal.PtrToStructure(ptrNetCfg); 73 | 74 | HvNetworkConfig networkConfig = new HvNetworkConfig 75 | { 76 | IPAddress = StringUtils.ByteArray2String(m_struNetCfg.struEtherNet[0].struDVRIP.sIpV4, session.Encoding), 77 | GateWay = StringUtils.ByteArray2String(m_struNetCfg.struGatewayIpAddr.sIpV4, session.Encoding), 78 | SubMask = StringUtils.ByteArray2String(m_struNetCfg.struEtherNet[0].struDVRIPMask.sIpV4, session.Encoding), 79 | Dns = StringUtils.ByteArray2String(m_struNetCfg.struDnsServer1IpAddr.sIpV4, session.Encoding), 80 | HostIP = StringUtils.ByteArray2String(m_struNetCfg.struAlarmHostIpAddr.sIpV4, session.Encoding), 81 | AlarmHostIpPort = Convert.ToInt32(m_struNetCfg.wAlarmHostIpPort), 82 | HttpPort = Convert.ToInt32(m_struNetCfg.wHttpPortNo), 83 | DVRPort = Convert.ToInt32(m_struNetCfg.struEtherNet[0].wDVRPort), 84 | DHCP = m_struNetCfg.byUseDhcp == 1, 85 | PPPoE = m_struNetCfg.struPPPoE.dwPPPOE == 1, 86 | PPPoEName = StringUtils.ByteArray2String(m_struNetCfg.struPPPoE.sPPPoEUser, session.Encoding), 87 | PPPoEPassword = m_struNetCfg.struPPPoE.sPPPoEPassword 88 | }; 89 | return networkConfig; 90 | } 91 | catch 92 | { 93 | throw; 94 | } 95 | finally 96 | { 97 | Marshal.FreeHGlobal(ptrNetCfg); 98 | } 99 | } 100 | 101 | 102 | public HvDeviceConfig GetDeviceConfig() 103 | { 104 | NET_DVR_DEVICECFG_V40 m_struDeviceCfg = default; 105 | 106 | uint dwReturn = 0; 107 | int nSize = Marshal.SizeOf(m_struDeviceCfg); 108 | IntPtr ptrDeviceCfg = Marshal.AllocHGlobal(nSize); 109 | try 110 | { 111 | Marshal.StructureToPtr(m_struDeviceCfg, ptrDeviceCfg, false); 112 | 113 | Invoke(NET_DVR_GetDVRConfig(session.UserId, NET_DVR_GET_DEVICECFG_V40, -1, ptrDeviceCfg, (uint)nSize, ref dwReturn)); 114 | 115 | m_struDeviceCfg = Marshal.PtrToStructure(ptrDeviceCfg); 116 | 117 | uint iVer1 = (m_struDeviceCfg.dwSoftwareVersion >> 24) & 0xFF; 118 | uint iVer2 = (m_struDeviceCfg.dwSoftwareVersion >> 16) & 0xFF; 119 | uint iVer3 = m_struDeviceCfg.dwSoftwareVersion & 0xFFFF; 120 | uint iVer4 = (m_struDeviceCfg.dwSoftwareBuildDate >> 16) & 0xFFFF; 121 | uint iVer5 = (m_struDeviceCfg.dwSoftwareBuildDate >> 8) & 0xFF; 122 | uint iVer6 = m_struDeviceCfg.dwSoftwareBuildDate & 0xFF; 123 | 124 | var deviceConfig = new HvDeviceConfig 125 | { 126 | Name = StringUtils.ByteArray2String(m_struDeviceCfg.sDVRName, session.Encoding), 127 | TypeName = StringUtils.ByteArray2String(m_struDeviceCfg.byDevTypeName, session.Encoding), 128 | AnalogChannel = Convert.ToInt32(m_struDeviceCfg.byChanNum), 129 | IPChannel = Convert.ToInt32(m_struDeviceCfg.byIPChanNum + 256 * m_struDeviceCfg.byHighIPChanNum), 130 | ZeroChannel = Convert.ToInt32(m_struDeviceCfg.byZeroChanNum), 131 | NetworkPort = Convert.ToInt32(m_struDeviceCfg.byNetworkPortNum), 132 | AlarmInPort = Convert.ToInt32(m_struDeviceCfg.byAlarmInPortNum), 133 | AlarmOutPort = Convert.ToInt32(m_struDeviceCfg.byAlarmOutPortNum), 134 | Serial = StringUtils.ByteArray2String(m_struDeviceCfg.sSerialNumber, session.Encoding), 135 | Version = $"V{iVer1}.{iVer2}.{iVer3} Build {iVer4,0:D2}{iVer5,0:D2}{iVer6,0:D2}" 136 | }; 137 | return deviceConfig; 138 | } 139 | catch 140 | { 141 | throw; 142 | } 143 | finally 144 | { 145 | Marshal.FreeHGlobal(ptrDeviceCfg); 146 | } 147 | } 148 | 149 | /// 150 | /// 获取第一块硬盘信息 151 | /// 152 | /// 153 | public HvHdConfig GetHdConfig() 154 | { 155 | return GetHdConfigs().FirstOrDefault(); 156 | } 157 | 158 | /// 159 | /// 获取全部硬盘信息 160 | /// 161 | /// 162 | public HvHdConfig[] GetHdConfigs() 163 | { 164 | NET_DVR_HDCFG hdConfig = default; 165 | uint returned = 0; 166 | int sizeOfConfig = Marshal.SizeOf(hdConfig); 167 | IntPtr ptrDeviceCfg = Marshal.AllocHGlobal(sizeOfConfig); 168 | try 169 | { 170 | Marshal.StructureToPtr(hdConfig, ptrDeviceCfg, false); 171 | Invoke(NET_DVR_GetDVRConfig( 172 | session.UserId, 173 | NET_DVR_GET_HDCFG, 174 | -1, 175 | ptrDeviceCfg, 176 | (uint)sizeOfConfig, 177 | ref returned)); 178 | 179 | hdConfig = Marshal.PtrToStructure(ptrDeviceCfg); 180 | var disks = hdConfig.struHDInfo 181 | .Take((int)hdConfig.dwHDCount) 182 | .Select(x => new HvHdConfig(x)) 183 | .ToArray(); 184 | return disks; 185 | } 186 | catch 187 | { 188 | throw; 189 | } 190 | finally 191 | { 192 | Marshal.FreeHGlobal(ptrDeviceCfg); 193 | } 194 | } 195 | 196 | /// 197 | /// 获取RTSP端口 198 | /// 199 | /// 200 | public int GetRtspPort() 201 | { 202 | NET_DVR_RTSPCFG rtspConfig = default; 203 | var ptrSize = Marshal.SizeOf(rtspConfig); 204 | NET_DVR_GetRtspConfig(session.UserId, 0, ref rtspConfig, (uint)ptrSize); 205 | return rtspConfig.wPort; 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK/Errors.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace QuickNV.HikvisionNetSDK 4 | { 5 | /// 6 | /// 海康SDK错误代码枚举 7 | /// 8 | public enum Errors 9 | { 10 | /// 11 | /// 没有错误 12 | /// 13 | [Description("没有错误")] 14 | NET_DVR_NOERROR = 0, 15 | /// 16 | /// 用户名密码错误 17 | /// 18 | [Description("用户名密码错误")] 19 | NET_DVR_PASSWORD_ERROR = 1, 20 | /// 21 | /// 权限不足 22 | /// 23 | [Description("权限不足")] 24 | NET_DVR_NOENOUGHPRI = 2, 25 | /// 26 | /// 没有初始化 27 | /// 28 | [Description("没有初始化")] 29 | NET_DVR_NOINIT = 3, 30 | /// 31 | /// 通道号错误 32 | /// 33 | [Description("通道号错误")] 34 | NET_DVR_CHANNEL_ERROR = 4, 35 | /// 36 | /// 连接到DVR的客户端个数超过最大 37 | /// 38 | [Description("连接到DVR的客户端个数超过最大")] 39 | NET_DVR_OVER_MAXLINK = 5, 40 | /// 41 | /// 版本不匹配 42 | /// 43 | [Description("版本不匹配")] 44 | NET_DVR_VERSIONNOMATCH = 6, 45 | /// 46 | /// 连接服务器失败 47 | /// 48 | [Description("连接服务器失败")] 49 | NET_DVR_NETWORK_FAIL_CONNECT = 7, 50 | /// 51 | /// 向服务器发送失败 52 | /// 53 | [Description("向服务器发送失败")] 54 | NET_DVR_NETWORK_SEND_ERROR = 8, 55 | /// 56 | /// 从服务器接收数据失败 57 | /// 58 | [Description("从服务器接收数据失败")] 59 | NET_DVR_NETWORK_RECV_ERROR = 9, 60 | /// 61 | /// 从服务器接收数据超时 62 | /// 63 | [Description("从服务器接收数据超时")] 64 | NET_DVR_NETWORK_RECV_TIMEOUT = 10, 65 | /// 66 | /// 传送的数据有误 67 | /// 68 | [Description("传送的数据有误")] 69 | NET_DVR_NETWORK_ERRORDATA = 11, 70 | /// 71 | /// 调用次序错误 72 | /// 73 | [Description("调用次序错误")] 74 | NET_DVR_ORDER_ERROR = 12, 75 | /// 76 | /// 无此权限 77 | /// 78 | [Description("无此权限")] 79 | NET_DVR_OPERNOPERMIT = 13, 80 | /// 81 | /// DVR命令执行超时 82 | /// 83 | [Description("DVR命令执行超时")] 84 | NET_DVR_COMMANDTIMEOUT = 14, 85 | /// 86 | /// 串口号错误 87 | /// 88 | [Description("串口号错误")] 89 | NET_DVR_ERRORSERIALPORT = 15, 90 | /// 91 | /// 报警端口错误 92 | /// 93 | [Description("报警端口错误")] 94 | NET_DVR_ERRORALARMPORT = 16, 95 | /// 96 | /// 参数错误 97 | /// 98 | [Description("参数错误")] 99 | NET_DVR_PARAMETER_ERROR = 17, 100 | /// 101 | /// 服务器通道处于错误状态 102 | /// 103 | [Description("服务器通道处于错误状态")] 104 | NET_DVR_CHAN_EXCEPTION = 18, 105 | /// 106 | /// 没有硬盘 107 | /// 108 | [Description("没有硬盘")] 109 | NET_DVR_NODISK = 19, 110 | /// 111 | /// 硬盘号错误 112 | /// 113 | [Description("硬盘号错误")] 114 | NET_DVR_ERRORDISKNUM = 20, 115 | /// 116 | /// 服务器硬盘满 117 | /// 118 | [Description("服务器硬盘满")] 119 | NET_DVR_DISK_FULL = 21, 120 | /// 121 | /// 服务器硬盘出错 122 | /// 123 | [Description("服务器硬盘出错")] 124 | NET_DVR_DISK_ERROR = 22, 125 | /// 126 | /// 服务器不支持 127 | /// 128 | [Description("服务器不支持")] 129 | NET_DVR_NOSUPPORT = 23, 130 | /// 131 | /// 服务器忙 132 | /// 133 | [Description("服务器忙")] 134 | NET_DVR_BUSY = 24, 135 | /// 136 | /// 服务器修改不成功 137 | /// 138 | [Description("服务器修改不成功")] 139 | NET_DVR_MODIFY_FAIL = 25, 140 | /// 141 | /// 密码输入格式不正确 142 | /// 143 | [Description("密码输入格式不正确")] 144 | NET_DVR_PASSWORD_FORMAT_ERROR = 26, 145 | /// 146 | /// 硬盘正在格式化,不能启动操作 147 | /// 148 | [Description("硬盘正在格式化,不能启动操作")] 149 | NET_DVR_DISK_FORMATING = 27, 150 | /// 151 | /// DVR资源不足 152 | /// 153 | [Description("DVR资源不足")] 154 | NET_DVR_DVRNORESOURCE = 28, 155 | /// 156 | /// DVR操作失败 157 | /// 158 | [Description("DVR操作失败")] 159 | NET_DVR_DVROPRATEFAILED = 29, 160 | /// 161 | /// 打开PC声音失败 162 | /// 163 | [Description("打开PC声音失败")] 164 | NET_DVR_OPENHOSTSOUND_FAIL = 30, 165 | /// 166 | /// 服务器语音对讲被占用 167 | /// 168 | [Description("服务器语音对讲被占用")] 169 | NET_DVR_DVRVOICEOPENED = 31, 170 | /// 171 | /// 时间输入不正确 172 | /// 173 | [Description("时间输入不正确")] 174 | NET_DVR_TIMEINPUTERROR = 32, 175 | /// 176 | /// 回放时服务器没有指定的文件 177 | /// 178 | [Description("回放时服务器没有指定的文件")] 179 | NET_DVR_NOSPECFILE = 33, 180 | /// 181 | /// 创建文件出错 182 | /// 183 | [Description("创建文件出错")] 184 | NET_DVR_CREATEFILE_ERROR = 34, 185 | /// 186 | /// 打开文件出错 187 | /// 188 | [Description("打开文件出错")] 189 | NET_DVR_FILEOPENFAIL = 35, 190 | /// 191 | /// 上次的操作还没有完成 192 | /// 193 | [Description("上次的操作还没有完成")] 194 | NET_DVR_OPERNOTFINISH = 36, 195 | /// 196 | /// 获取当前播放的时间出错 197 | /// 198 | [Description("获取当前播放的时间出错")] 199 | NET_DVR_GETPLAYTIMEFAIL = 37, 200 | /// 201 | /// 播放出错 202 | /// 203 | [Description("播放出错")] 204 | NET_DVR_PLAYFAIL = 38, 205 | /// 206 | /// 文件格式不正确 207 | /// 208 | [Description("文件格式不正确")] 209 | NET_DVR_FILEFORMAT_ERROR = 39, 210 | /// 211 | /// 路径错误 212 | /// 213 | [Description("路径错误")] 214 | NET_DVR_DIR_ERROR = 40, 215 | /// 216 | /// 资源分配错误 217 | /// 218 | [Description("资源分配错误")] 219 | NET_DVR_ALLOC_RESOURCE_ERROR = 41, 220 | /// 221 | /// 声卡模式错误 222 | /// 223 | [Description("声卡模式错误")] 224 | NET_DVR_AUDIO_MODE_ERROR = 42, 225 | /// 226 | /// 缓冲区太小 227 | /// 228 | [Description("缓冲区太小")] 229 | NET_DVR_NOENOUGH_BUF = 43, 230 | /// 231 | /// 创建SOCKET出错 232 | /// 233 | [Description("创建SOCKET出错")] 234 | NET_DVR_CREATESOCKET_ERROR = 44, 235 | /// 236 | /// 设置SOCKET出错 237 | /// 238 | [Description("设置SOCKET出错")] 239 | NET_DVR_SETSOCKET_ERROR = 45, 240 | /// 241 | /// 个数达到最大 242 | /// 243 | [Description("个数达到最大")] 244 | NET_DVR_MAX_NUM = 46, 245 | /// 246 | /// 用户不存在 247 | /// 248 | [Description("用户不存在")] 249 | NET_DVR_USERNOTEXIST = 47, 250 | /// 251 | /// 写FLASH出错 252 | /// 253 | [Description("写FLASH出错")] 254 | NET_DVR_WRITEFLASHERROR = 48, 255 | /// 256 | /// DVR升级失败 257 | /// 258 | [Description("DVR升级失败")] 259 | NET_DVR_UPGRADEFAIL = 49, 260 | /// 261 | /// 解码卡已经初始化过 262 | /// 263 | [Description("解码卡已经初始化过")] 264 | NET_DVR_CARDHAVEINIT = 50, 265 | /// 266 | /// 调用播放库中某个函数失败 267 | /// 268 | [Description("调用播放库中某个函数失败")] 269 | NET_DVR_PLAYERFAILED = 51, 270 | /// 271 | /// 设备端用户数达到最大 272 | /// 273 | [Description("设备端用户数达到最大")] 274 | NET_DVR_MAX_USERNUM = 52, 275 | /// 276 | /// 获得客户端的IP地址或物理地址失败 277 | /// 278 | [Description("获得客户端的IP地址或物理地址失败")] 279 | NET_DVR_GETLOCALIPANDMACFAIL = 53, 280 | /// 281 | /// 该通道没有编码 282 | /// 283 | [Description("该通道没有编码")] 284 | NET_DVR_NOENCODEING = 54, 285 | /// 286 | /// IP地址不匹配 287 | /// 288 | [Description("IP地址不匹配")] 289 | NET_DVR_IPMISMATCH = 55, 290 | /// 291 | /// MAC地址不匹配 292 | /// 293 | [Description("MAC地址不匹配")] 294 | NET_DVR_MACMISMATCH = 56, 295 | /// 296 | /// 升级文件语言不匹配 297 | /// 298 | [Description("升级文件语言不匹配")] 299 | NET_DVR_UPGRADELANGMISMATCH = 57, 300 | /// 301 | /// 播放器路数达到最大 302 | /// 303 | [Description("播放器路数达到最大")] 304 | NET_DVR_MAX_PLAYERPORT = 58, 305 | /// 306 | /// 备份设备中没有足够空间进行备份 307 | /// 308 | [Description("备份设备中没有足够空间进行备份")] 309 | NET_DVR_NOSPACEBACKUP = 59, 310 | /// 311 | /// 没有找到指定的备份设备 312 | /// 313 | [Description("没有找到指定的备份设备")] 314 | NET_DVR_NODEVICEBACKUP = 60, 315 | /// 316 | /// 图像素位数不符,限24色 317 | /// 318 | [Description("图像素位数不符,限24色")] 319 | NET_DVR_PICTURE_BITS_ERROR = 61, 320 | /// 321 | /// 图片高*宽超限, 限128*256 322 | /// 323 | [Description("图片高*宽超限, 限128*256")] 324 | NET_DVR_PICTURE_DIMENSION_ERROR = 62, 325 | /// 326 | /// 图片大小超限,限100K 327 | /// 328 | [Description("图片大小超限,限100K")] 329 | NET_DVR_PICTURE_SIZ_ERROR = 63, 330 | /// 331 | /// 载入当前目录下Player Sdk出错 332 | /// 333 | [Description("载入当前目录下Player Sdk出错")] 334 | NET_DVR_LOADPLAYERSDKFAILED = 64, 335 | /// 336 | /// 找不到Player Sdk中某个函数入口 337 | /// 338 | [Description("找不到Player Sdk中某个函数入口")] 339 | NET_DVR_LOADPLAYERSDKPROC_ERROR = 65, 340 | /// 341 | /// 载入当前目录下DSsdk出错 342 | /// 343 | [Description("载入当前目录下DSsdk出错")] 344 | NET_DVR_LOADDSSDKFAILED = 66, 345 | /// 346 | /// 找不到DsSdk中某个函数入口 347 | /// 348 | [Description("找不到DsSdk中某个函数入口")] 349 | NET_DVR_LOADDSSDKPROC_ERROR = 67, 350 | /// 351 | /// 调用硬解码库DsSdk中某个函数失败 352 | /// 353 | [Description("调用硬解码库DsSdk中某个函数失败")] 354 | NET_DVR_DSSDK_ERROR = 68, 355 | /// 356 | /// 声卡被独占 357 | /// 358 | [Description("声卡被独占")] 359 | NET_DVR_VOICEMONOPOLIZE = 69, 360 | /// 361 | /// 加入多播组失败 362 | /// 363 | [Description("加入多播组失败")] 364 | NET_DVR_JOINMULTICASTFAILED = 70, 365 | /// 366 | /// 建立日志文件目录失败 367 | /// 368 | [Description("建立日志文件目录失败")] 369 | NET_DVR_CREATEDIR_ERROR = 71, 370 | /// 371 | /// 绑定套接字失败 372 | /// 373 | [Description("绑定套接字失败")] 374 | NET_DVR_BINDSOCKET_ERROR = 72, 375 | /// 376 | /// socket连接中断,此错误通常是由于连接中断或目的地不可达 377 | /// 378 | [Description("socket连接中断,此错误通常是由于连接中断或目的地不可达")] 379 | NET_DVR_SOCKETCLOSE_ERROR = 73, 380 | /// 381 | /// 注销时用户ID正在进行某操作 382 | /// 383 | [Description("注销时用户ID正在进行某操作")] 384 | NET_DVR_USERID_ISUSING = 74, 385 | /// 386 | /// 监听失败 387 | /// 388 | [Description("监听失败")] 389 | NET_DVR_SOCKETLISTEN_ERROR = 75, 390 | /// 391 | /// 程序异常 392 | /// 393 | [Description("程序异常")] 394 | NET_DVR_PROGRAM_EXCEPTION = 76, 395 | /// 396 | /// 写文件失败 397 | /// 398 | [Description("写文件失败")] 399 | NET_DVR_WRITEFILE_FAILED = 77, 400 | /// 401 | /// 禁止格式化只读硬盘 402 | /// 403 | [Description("禁止格式化只读硬盘")] 404 | NET_DVR_FORMAT_READONLY = 78, 405 | /// 406 | /// 用户配置结构中存在相同的用户名 407 | /// 408 | [Description("用户配置结构中存在相同的用户名")] 409 | NET_DVR_WITHSAMEUSERNAME = 79, 410 | /// 411 | /// 导入参数时设备型号不匹配 412 | /// 413 | [Description("导入参数时设备型号不匹配")] 414 | NET_DVR_DEVICETYPE_ERROR = 80, 415 | /// 416 | /// 导入参数时语言不匹配 417 | /// 418 | [Description("导入参数时语言不匹配")] 419 | NET_DVR_LANGUAGE_ERROR = 81, 420 | /// 421 | /// 导入参数时软件版本不匹配 422 | /// 423 | [Description("导入参数时软件版本不匹配")] 424 | NET_DVR_PARAVERSION_ERROR = 82, 425 | /// 426 | /// 预览时外接IP通道不在线 427 | /// 428 | [Description("预览时外接IP通道不在线")] 429 | NET_DVR_IPCHAN_NOTALIVE = 83, 430 | /// 431 | /// 加载高清IPC通讯库StreamTransClient.dll失败 432 | /// 433 | [Description("加载高清IPC通讯库StreamTransClient.dll失败")] 434 | NET_DVR_RTSP_SDK_ERROR = 84, 435 | /// 436 | /// 加载转码库失败 437 | /// 438 | [Description("加载转码库失败")] 439 | NET_DVR_CONVERT_SDK_ERROR = 85, 440 | /// 441 | /// 超出最大的ip接入通道数 442 | /// 443 | [Description("超出最大的ip接入通道数")] 444 | NET_DVR_IPC_COUNT_OVERFLOW = 86, 445 | [Description("")] 446 | NET_DVR_USER_LOCKED = 153, 447 | /// 448 | /// no error 449 | /// 450 | [Description("no error")] 451 | NET_PLAYM4_NOERROR = 500, 452 | /// 453 | /// input parameter is invalid 454 | /// 455 | [Description("input parameter is invalid")] 456 | NET_PLAYM4_PARA_OVER = 501, 457 | /// 458 | /// The order of the function to be called is error 459 | /// 460 | [Description("The order of the function to be called is error")] 461 | NET_PLAYM4_ORDER_ERROR = 502, 462 | /// 463 | /// Create multimedia clock failed 464 | /// 465 | [Description("Create multimedia clock failed")] 466 | NET_PLAYM4_TIMER_ERROR = 503, 467 | /// 468 | /// Decode video data failed 469 | /// 470 | [Description("Decode video data failed")] 471 | NET_PLAYM4_DEC_VIDEO_ERROR = 504, 472 | /// 473 | /// Decode audio data failed 474 | /// 475 | [Description("Decode audio data failed")] 476 | NET_PLAYM4_DEC_AUDIO_ERROR = 505, 477 | /// 478 | /// Allocate memory failed 479 | /// 480 | [Description("Allocate memory failed")] 481 | NET_PLAYM4_ALLOC_MEMORY_ERROR = 506, 482 | /// 483 | /// Open the file failed 484 | /// 485 | [Description("Open the file failed")] 486 | NET_PLAYM4_OPEN_FILE_ERROR = 507, 487 | /// 488 | /// Create thread or event failed 489 | /// 490 | [Description("Create thread or event failed")] 491 | NET_PLAYM4_CREATE_OBJ_ERROR = 508, 492 | /// 493 | /// Create DirectDraw object failed 494 | /// 495 | [Description("Create DirectDraw object failed")] 496 | NET_PLAYM4_CREATE_DDRAW_ERROR = 509, 497 | /// 498 | /// failed when creating off-screen surface 499 | /// 500 | [Description("failed when creating off-screen surface")] 501 | NET_PLAYM4_CREATE_OFFSCREEN_ERROR = 510, 502 | /// 503 | /// buffer is overflow 504 | /// 505 | [Description("buffer is overflow")] 506 | NET_PLAYM4_BUF_OVER = 511, 507 | /// 508 | /// failed when creating audio device 509 | /// 510 | [Description("failed when creating audio device")] 511 | NET_PLAYM4_CREATE_SOUND_ERROR = 512, 512 | /// 513 | /// Set volume failed 514 | /// 515 | [Description("Set volume failed")] 516 | NET_PLAYM4_SET_VOLUME_ERROR = 513, 517 | /// 518 | /// The function only support play file 519 | /// 520 | [Description("The function only support play file")] 521 | NET_PLAYM4_SUPPORT_FILE_ONLY = 514, 522 | /// 523 | /// The function only support play stream 524 | /// 525 | [Description("The function only support play stream")] 526 | NET_PLAYM4_SUPPORT_STREAM_ONLY = 515, 527 | /// 528 | /// System not support 529 | /// 530 | [Description("System not support")] 531 | NET_PLAYM4_SYS_NOT_SUPPORT = 516, 532 | /// 533 | /// No file header 534 | /// 535 | [Description("No file header")] 536 | NET_PLAYM4_FILEHEADER_UNKNOWN = 517, 537 | /// 538 | /// The version of decoder and encoder is not adapted 539 | /// 540 | [Description("The version of decoder and encoder is not adapted")] 541 | NET_PLAYM4_VERSION_INCORRECT = 518, 542 | /// 543 | /// Initialize decoder failed 544 | /// 545 | [Description("Initialize decoder failed")] 546 | NET_PALYM4_INIT_DECODER_ERROR = 519, 547 | /// 548 | /// The file data is unknown 549 | /// 550 | [Description("The file data is unknown")] 551 | NET_PLAYM4_CHECK_FILE_ERROR = 520, 552 | /// 553 | /// Initialize multimedia clock failed 554 | /// 555 | [Description("Initialize multimedia clock failed")] 556 | NET_PLAYM4_INIT_TIMER_ERROR = 521, 557 | /// 558 | /// Blt failed 559 | /// 560 | [Description("Blt failed")] 561 | NET_PLAYM4_BLT_ERROR = 522, 562 | /// 563 | /// Update failed 564 | /// 565 | [Description("Update failed")] 566 | NET_PLAYM4_UPDATE_ERROR = 523, 567 | /// 568 | /// openfile error, streamtype is multi 569 | /// 570 | [Description("openfile error, streamtype is multi")] 571 | NET_PLAYM4_OPEN_FILE_ERROR_MULTI = 524, 572 | /// 573 | /// openfile error, streamtype is video 574 | /// 575 | [Description("openfile error, streamtype is video")] 576 | NET_PLAYM4_OPEN_FILE_ERROR_VIDEO = 525, 577 | /// 578 | /// JPEG compress error 579 | /// 580 | [Description("JPEG compress error")] 581 | NET_PLAYM4_JPEG_COMPRESS_ERROR = 526, 582 | /// 583 | /// Don't support the version of this file 584 | /// 585 | [Description("Don't support the version of this file")] 586 | NET_PLAYM4_EXTRACT_NOT_SUPPORT = 527, 587 | /// 588 | /// extract video data failed 589 | /// 590 | [Description("extract video data failed")] 591 | NET_PLAYM4_EXTRACT_DATA_ERROR = 528 592 | } 593 | } 594 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Api/Service/ChannelService.cs: -------------------------------------------------------------------------------- 1 | using QuickNV.HikvisionNetSDK.Api.Utils; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Threading.Tasks; 7 | using static QuickNV.HikvisionNetSDK.Defines; 8 | using static QuickNV.HikvisionNetSDK.Methods; 9 | 10 | namespace QuickNV.HikvisionNetSDK.Api.Service 11 | { 12 | public class ChannelService 13 | { 14 | private HvSession session; 15 | private int rtspPort; 16 | public IReadOnlyCollection AnalogChannels { get; private set; } 17 | public IReadOnlyCollection IpChannels { get; private set; } 18 | public IReadOnlyCollection AllChannels { get; private set; } 19 | 20 | internal ChannelService(HvSession session, NET_DVR_DEVICEINFO_V30 deviceInfo) 21 | { 22 | this.session = session; 23 | RefreshChannelsInfo(deviceInfo); 24 | rtspPort = session.ConfigService.GetRtspPort(); 25 | } 26 | 27 | private void RefreshChannelsInfo(NET_DVR_DEVICEINFO_V30 deviceInfo) 28 | { 29 | var allChannels = new List(); 30 | 31 | var dwAnalogChannelTotalNumber = deviceInfo.byChanNum; 32 | var analogChannels = new List(); 33 | for (var i = 0; i < dwAnalogChannelTotalNumber; i++) 34 | { 35 | var id = i + deviceInfo.byStartChan; 36 | var channel = new HvChannel(id); 37 | analogChannels.Add(channel); 38 | allChannels.Add(channel); 39 | } 40 | AnalogChannels = analogChannels; 41 | 42 | var ipChannels = new List(); 43 | uint dwDigitalChannelTotalNumber = deviceInfo.byIPChanNum + 256 * (uint)deviceInfo.byHighDChanNum; 44 | if (dwDigitalChannelTotalNumber > 0) 45 | { 46 | NET_DVR_IPPARACFG_V40 struIpParaCfgV40 = default; 47 | 48 | int dwSize = Marshal.SizeOf(struIpParaCfgV40); 49 | 50 | IntPtr ptrIpParaCfgV40 = Marshal.AllocHGlobal(dwSize); 51 | Marshal.StructureToPtr(struIpParaCfgV40, ptrIpParaCfgV40, false); 52 | 53 | uint dwReturn = 0; 54 | int iGroupNo = 0; 55 | 56 | var ipChannelsConfig = Invoke(NET_DVR_GetDVRConfig( 57 | session.UserId, 58 | NET_DVR_GET_IPPARACFG_V40, 59 | iGroupNo, 60 | ptrIpParaCfgV40, 61 | (uint)dwSize, 62 | ref dwReturn)); 63 | if (ipChannelsConfig) 64 | { 65 | // succ 66 | struIpParaCfgV40 = Marshal.PtrToStructure(ptrIpParaCfgV40); 67 | 68 | byte byStreamType; 69 | uint iDChanNum = 64; 70 | 71 | if (dwDigitalChannelTotalNumber < 64) 72 | { 73 | //If the ip channels of device is less than 64,will get the real channel of device 74 | iDChanNum = dwDigitalChannelTotalNumber; 75 | } 76 | 77 | for (int i = 0; i < iDChanNum; i++) 78 | { 79 | byStreamType = struIpParaCfgV40.struStreamMode[i].byGetStreamType; 80 | var unionGetStream = struIpParaCfgV40.struStreamMode[i].uGetStream; 81 | 82 | switch (byStreamType) 83 | { 84 | //At present NVR just support case 0-one way to get stream from device 85 | case 0: 86 | dwSize = Marshal.SizeOf(unionGetStream); 87 | IntPtr ptrChanInfo = Marshal.AllocHGlobal(dwSize); 88 | Marshal.StructureToPtr(unionGetStream, ptrChanInfo, false); 89 | var struChanInfo = Marshal.PtrToStructure(ptrChanInfo); 90 | //List ip channels 91 | if (struChanInfo.byIPID == 0) 92 | continue; 93 | var channelId = i + (int)struIpParaCfgV40.dwStartDChan; 94 | var channel = new HvIpChannel( 95 | channelId, 96 | i + 1, 97 | struChanInfo.byEnable != 0); 98 | ipChannels.Add(channel); 99 | allChannels.Add(channel); 100 | Marshal.FreeHGlobal(ptrChanInfo); 101 | break; 102 | 103 | default: 104 | break; 105 | } 106 | } 107 | } 108 | Marshal.FreeHGlobal(ptrIpParaCfgV40); 109 | } 110 | IpChannels = ipChannels; 111 | AllChannels = allChannels; 112 | } 113 | 114 | public void RefreshChannelName(HvChannel channel) 115 | { 116 | NET_DVR_PICCFG_V30 config = default; 117 | var ptrSize = Marshal.SizeOf(config); 118 | IntPtr ptr = Marshal.AllocHGlobal(ptrSize); 119 | try 120 | { 121 | uint ret = 0; 122 | Invoke(NET_DVR_GetDVRConfig(session.UserId, NET_DVR_GET_PICCFG_V30, channel.Id, ptr, (uint)ptrSize, ref ret)); 123 | config = Marshal.PtrToStructure(ptr); 124 | channel.Name = StringUtils.ByteArray2String(config.sChanName, session.Encoding); 125 | } 126 | catch 127 | { 128 | throw; 129 | } 130 | finally 131 | { 132 | Marshal.FreeHGlobal(ptr); 133 | } 134 | } 135 | 136 | public void RefreshChannelsName() 137 | { 138 | foreach (var channel in AllChannels) 139 | RefreshChannelName(channel); 140 | } 141 | 142 | /// 143 | /// 云台控制 144 | /// 145 | /// 通道号 146 | /// 云台控制命令 147 | /// 云台停止动作或开始动作 148 | /// 云台控制的速度,用户按不同解码器的速度控制值设置。取值范围[1,160] 149 | public void PTZControl(int channelId, HvPTZCommand ptzCommand, bool isStop, uint speed) 150 | { 151 | uint dwStop = 0; 152 | if (isStop) 153 | dwStop = 1; 154 | Invoke(NET_DVR_PTZControlWithSpeed_Other(session.UserId, channelId, (uint)ptzCommand, dwStop, speed)); 155 | } 156 | 157 | /// 158 | /// 获取通道实时视频流的RTSP地址 159 | /// 160 | /// 通道 161 | /// 视频流类型 162 | /// 163 | public string GetLiveRtspUrl(HvChannel channel, HvStreamType streamType) 164 | { 165 | return GetLiveRtspUrl(channel,streamType, HvRtspPathFormat.Streaming); 166 | } 167 | 168 | /// 169 | /// 获取通道实时视频流的RTSP地址 170 | /// 171 | /// 通道 172 | /// 视频流类型 173 | /// 路径格式 174 | /// 175 | public string GetLiveRtspUrl(HvChannel channel, HvStreamType streamType, HvRtspPathFormat pathFormat) 176 | { 177 | UriBuilder uriBuilder = new UriBuilder(); 178 | uriBuilder.Scheme = "rtsp"; 179 | uriBuilder.Host = session.Host; 180 | uriBuilder.Port = rtspPort; 181 | uriBuilder.UserName = session.UserName; 182 | uriBuilder.Password = session.Password; 183 | switch (pathFormat) 184 | { 185 | case HvRtspPathFormat.AvStream: 186 | uriBuilder.Path = $"/h264/ch{channel.RtspChannelId}/{streamType.ToString().ToLower()}/av_stream"; 187 | break; 188 | case HvRtspPathFormat.Streaming: 189 | uriBuilder.Path = $"/Streaming/Channels/{channel.RtspChannelId}0{(int)streamType}"; 190 | break; 191 | } 192 | return uriBuilder.ToString(); 193 | } 194 | 195 | private string dateTime2Str(DateTime dateTime) 196 | { 197 | return $"{dateTime.ToString("yyyyMMdd")}t{dateTime.ToString("HHmmss")}z"; 198 | } 199 | 200 | /// 201 | /// 获取通道回放视频流的RTSP地址 202 | /// 203 | /// 通道 204 | /// 视频流类型 205 | /// 开始时间 206 | /// 结束时间 207 | /// 208 | public string GetPlaybackRtspUrl(HvChannel channel, HvStreamType streamType, DateTime startTime, DateTime endTime) 209 | { 210 | UriBuilder uriBuilder = new UriBuilder(); 211 | uriBuilder.Scheme = "rtsp"; 212 | uriBuilder.Host = session.Host; 213 | uriBuilder.Port = rtspPort; 214 | uriBuilder.UserName = session.UserName; 215 | uriBuilder.Password = session.Password; 216 | uriBuilder.Path = $"/Streaming/tracks/{channel.RtspChannelId}0{(int)streamType}"; 217 | uriBuilder.Query = $"starttime={dateTime2Str(startTime)}&endtime={dateTime2Str(endTime)}"; 218 | return uriBuilder.ToString(); 219 | } 220 | 221 | /// 222 | /// 获取预置位数量 223 | /// 224 | /// 通道号 225 | /// 226 | public int GetPresetCount(int channelId) 227 | { 228 | uint bytesReturned = 0; 229 | 230 | NET_DVR_PRESET_INFO presetInfo = new NET_DVR_PRESET_INFO(); 231 | int size = Marshal.SizeOf(typeof(NET_DVR_PRESET_INFO)); 232 | IntPtr presetInfoPtr = Marshal.AllocHGlobal(size); 233 | Marshal.StructureToPtr(presetInfo, presetInfoPtr, false); 234 | 235 | Invoke(NET_DVR_GetDVRConfig(session.UserId, NET_DVR_GET_PRESETCFG, channelId, presetInfoPtr, (uint)size, ref bytesReturned)); 236 | presetInfo = Marshal.PtrToStructure(presetInfoPtr); 237 | Console.WriteLine(presetInfo.dwPresetNum); 238 | return Convert.ToInt32(presetInfo.dwPresetNum); 239 | } 240 | 241 | /// 242 | /// 设置当前位置为特定预置位 243 | /// 244 | /// 通道号 245 | /// 预置位编码 246 | /// 247 | public void SetPreset(int channelId, ushort presetNumber) 248 | { 249 | Invoke(NET_DVR_PTZPreset_Other(session.UserId, channelId, SET_PRESET, presetNumber)); 250 | } 251 | 252 | /// 253 | /// 修改特定预置位的名称 254 | /// 255 | /// 通道号 256 | /// 预置位编码 257 | /// 预置位名称 258 | public void ModifyPresetName(int channelId, ushort presetNumber, string presetName) 259 | { 260 | if (string.IsNullOrWhiteSpace(presetName)) 261 | { 262 | presetName = $"预置点 {presetNumber}"; 263 | } 264 | 265 | NET_DVR_PRESET_NAME structure = new NET_DVR_PRESET_NAME(); 266 | int nSize = Marshal.SizeOf(structure); 267 | var bytes = new byte[32]; 268 | var src = session.Encoding.GetBytes(presetName); 269 | var length = bytes.Length <= 32 ? src.Length : 32; 270 | Array.Copy(src, bytes, length); 271 | structure.dwSize = (uint)nSize; 272 | structure.wPresetNum = presetNumber; 273 | structure.byName = bytes; 274 | 275 | IntPtr ptr = Marshal.AllocHGlobal(nSize); 276 | Marshal.StructureToPtr(structure, ptr, false); 277 | try 278 | { 279 | Invoke(NET_DVR_SetDVRConfig(session.UserId, NET_DVR_SET_PRESET_NAME, channelId, ptr, (uint)nSize)); 280 | } 281 | catch 282 | { 283 | throw; 284 | } 285 | finally 286 | { 287 | Marshal.FreeHGlobal(ptr); 288 | } 289 | } 290 | 291 | /// 292 | /// 设置当前位置为特定预置位编号及指定名称 293 | /// 294 | /// 通道号 295 | /// 预置位编码 296 | /// 预置位名称 297 | /// 298 | public void SetPresetWithName(int channelId, ushort presetNumber, string presetName) 299 | { 300 | SetPreset(channelId, presetNumber); 301 | ModifyPresetName(channelId, presetNumber, presetName); 302 | } 303 | 304 | /// 305 | /// 转动到指定预置位 306 | /// 307 | /// 通道号 308 | /// 预置位编码 309 | public void GotoPreset(int channelId, ushort presetNumber) 310 | { 311 | Invoke(NET_DVR_PTZPreset_Other(session.UserId, channelId, GOTO_PRESET, presetNumber)); 312 | } 313 | 314 | /// 315 | /// 清除指定预置位 316 | /// 317 | /// 通道号 318 | /// 预置位编码 319 | public void RemovePreset(int channelId, ushort presetNumber) 320 | { 321 | Invoke(NET_DVR_PTZPreset_Other(session.UserId, channelId, CLE_PRESET, presetNumber)); 322 | } 323 | 324 | /// 325 | /// 获取NVR通道的预置位信息 326 | /// 327 | /// 通道号 328 | /// 预置位数量,默认为255 329 | /// 是否仅反馈有效的预置位,默认是 true 330 | /// 331 | public HvPreset[] GetPresets(int channelId, int presetCount = 255, bool containOnlyValidPreset = true) 332 | { 333 | if (presetCount <= 0) 334 | { 335 | return Array.Empty(); 336 | } 337 | 338 | uint bytesReturned = 0; 339 | var presets = new HvPreset[presetCount]; 340 | var presetCfg = new NET_DVR_PRESET_NAME[presetCount]; 341 | int nSize = Marshal.SizeOf(typeof(NET_DVR_PRESET_NAME)); 342 | int nOutBufSize = nSize * presetCount; 343 | IntPtr ptrPreSetCfg = Marshal.AllocHGlobal(nOutBufSize); 344 | 345 | try 346 | { 347 | int i; 348 | for (i = 0; i < presetCount; i++) 349 | { 350 | Marshal.StructureToPtr(presetCfg[i], ptrPreSetCfg, false); 351 | } 352 | 353 | //获取参数成功 354 | 355 | if (Invoke(NET_DVR_GetDVRConfig( 356 | session.UserId, 357 | NET_DVR_GET_PRESET_NAME, 358 | channelId, ptrPreSetCfg, 359 | (uint)nOutBufSize, 360 | ref bytesReturned))) 361 | { 362 | for (i = 0; i < presetCount; i++) 363 | { 364 | // 在每次循环中,通过计算当前结构体的指针位置,将 ptrPreSetCfg 移动到正确的位置。然后使用 Marshal.PtrToStructure 方法将指针转换为结构体 365 | var ptrCurrent = IntPtr.Add(ptrPreSetCfg, i * nSize); 366 | presetCfg[i] = Marshal.PtrToStructure(ptrCurrent); 367 | if (presetCfg[i].byName != null) 368 | { 369 | var presetName = StringUtils.ByteArray2String(presetCfg[i].byName, session.Encoding); 370 | var preset = new HvPreset(presetCfg[i].wPresetNum, presetName); 371 | preset.PanPos = ConvertPtzPos(presetCfg[i].wPanPos); 372 | preset.TiltPos = ConvertPtzPos(presetCfg[i].wTiltPos); 373 | preset.ZoomPos = ConvertPtzPos(presetCfg[i].wZoomPos); 374 | 375 | presets[i] = preset; 376 | } 377 | } 378 | } 379 | } 380 | catch 381 | { 382 | throw; 383 | } 384 | finally 385 | { 386 | Marshal.FreeHGlobal(ptrPreSetCfg); 387 | } 388 | return containOnlyValidPreset ? presets.Where(x => x.IsSet).ToArray() : presets; 389 | } 390 | 391 | /// 392 | /// 获取球机Ptz参数 393 | /// 394 | /// 通道号 395 | /// 396 | public HvPtzPosition GetPtzPosition(int channelId) 397 | { 398 | uint bytesReturned = 0; 399 | NET_DVR_PTZPOS ptzPos = default; 400 | int nSize = Marshal.SizeOf(ptzPos); 401 | IntPtr ptrPicCfg = Marshal.AllocHGlobal(nSize); 402 | Marshal.StructureToPtr(ptzPos, ptrPicCfg, false); 403 | try 404 | { 405 | Invoke(NET_DVR_GetDVRConfig(session.UserId, NET_DVR_GET_PTZPOS, channelId, ptrPicCfg, (uint)nSize, ref bytesReturned)); 406 | ptzPos = (NET_DVR_PTZPOS)Marshal.PtrToStructure(ptrPicCfg, typeof(NET_DVR_PTZPOS)); 407 | 408 | var panPos = ConvertPtzPos(ptzPos.wPanPos); 409 | var tiltPos = ConvertPtzPos(ptzPos.wTiltPos); 410 | var zoomPos = ConvertPtzPos(ptzPos.wZoomPos); 411 | 412 | return new HvPtzPosition(panPos, tiltPos, zoomPos); 413 | } 414 | catch 415 | { 416 | throw; 417 | } 418 | finally 419 | { 420 | Marshal.FreeHGlobal(ptrPicCfg); 421 | } 422 | } 423 | 424 | /// 425 | /// 等待摄像机停止转动 426 | /// 427 | /// 通道号 428 | /// 429 | public async Task WaitUntilStopMovingAsync(int channelId) 430 | { 431 | uint bytesReturned = 0; 432 | NET_DVR_PTZPOS structure = new NET_DVR_PTZPOS(); 433 | int nSize = Marshal.SizeOf(structure); 434 | IntPtr ptrPicCfg = Marshal.AllocHGlobal(nSize); 435 | Marshal.StructureToPtr(structure, ptrPicCfg, false); 436 | 437 | try 438 | { 439 | bool result = NET_DVR_GetDVRConfig(session.UserId, NET_DVR_GET_PTZPOS, channelId, ptrPicCfg, (uint)nSize, ref bytesReturned); 440 | structure = (NET_DVR_PTZPOS)Marshal.PtrToStructure(ptrPicCfg, typeof(NET_DVR_PTZPOS)); 441 | var panPos = structure.wPanPos; 442 | var tiltPos = structure.wTiltPos; 443 | var zoomPos = structure.wZoomPos; 444 | 445 | bool isMoving = true; 446 | while (isMoving) 447 | { 448 | await Task.Delay(100); 449 | 450 | result = NET_DVR_GetDVRConfig(session.UserId, NET_DVR_GET_PTZPOS, channelId, ptrPicCfg, (uint)nSize, ref bytesReturned); 451 | if (result) 452 | { 453 | structure = (NET_DVR_PTZPOS)Marshal.PtrToStructure(ptrPicCfg, typeof(NET_DVR_PTZPOS)); 454 | //只要坐标没变就代表没动 455 | if (structure.wPanPos == panPos && structure.wTiltPos == tiltPos && structure.wZoomPos == zoomPos) 456 | { 457 | isMoving = false; 458 | } 459 | else 460 | { 461 | //设置当前位置为最新位置 462 | panPos = structure.wPanPos; 463 | tiltPos = structure.wTiltPos; 464 | zoomPos = structure.wZoomPos; 465 | } 466 | } 467 | } 468 | } 469 | catch 470 | { 471 | throw; 472 | } 473 | finally 474 | { 475 | Marshal.FreeHGlobal(ptrPicCfg); 476 | } 477 | } 478 | 479 | /// 480 | /// 将PTZPOS参数转化为实际值 481 | /// 482 | /// 参数 483 | /// 484 | private double ConvertPtzPos(ushort ptzPos) 485 | { 486 | var temp = (ptzPos / 4096) * 1000 + ((ptzPos % 4096) / 256) * 100 + ((ptzPos % 256) / 16) * 10 + (ptzPos % 16); 487 | var result = temp / 10d % 360; 488 | return result; 489 | } 490 | } 491 | } 492 | -------------------------------------------------------------------------------- /src/QuickNV.HikvisionNetSDK.Generator/Program.cs: -------------------------------------------------------------------------------- 1 | using CHCNetSDK_Splitter; 2 | using Microsoft.CodeAnalysis; 3 | using Microsoft.CodeAnalysis.CSharp; 4 | using Microsoft.CodeAnalysis.CSharp.Syntax; 5 | using System.Text; 6 | 7 | namespace HikvisionNetSDK.Generator 8 | { 9 | internal class Program 10 | { 11 | private static void Main(string[] args) 12 | { 13 | // 注册编码提供程序,以支持GBK编码 14 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 15 | 16 | // 读取源文件 17 | string sourceFile = "CHCNetSDK.cs"; 18 | string code = File.ReadAllText(sourceFile, Encoding.GetEncoding("gb2312")) 19 | .Replace("CHCNetSDK.", ""); 20 | 21 | // 初始化生成器 22 | CodeGenerator generator = new CodeGenerator(); 23 | 24 | // 提取错误代码 25 | string errorCodesSection = ExtractErrorCodes(code, generator); 26 | 27 | // 删除错误代码部分 28 | string codeWithoutErrors = RemoveErrorCodes(code); 29 | 30 | // 解析剩余代码 31 | SyntaxTree tree = CSharpSyntaxTree.ParseText(codeWithoutErrors); 32 | CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); 33 | var outFolder = "../../../../QuickNV.HikvisionNetSDK"; 34 | Environment.CurrentDirectory = outFolder; 35 | // 生成代码 36 | generator.Generate(root); 37 | 38 | // 生成文件 39 | generator.WriteFiles("."); 40 | 41 | Console.WriteLine("Done"); 42 | } 43 | 44 | /// 45 | /// 从代码中提取错误代码部分 46 | /// 47 | private static string ExtractErrorCodes(string code, CodeGenerator generator) 48 | { 49 | // 错误代码开始和结束标记 50 | string errorStartMarker = "/*******************全局错误码 begin**********************/"; 51 | string errorEndMarker = "/*******************全局错误码 end**********************/"; 52 | 53 | int startIndex = code.IndexOf(errorStartMarker); 54 | int endIndex = code.IndexOf(errorEndMarker); 55 | 56 | if (startIndex != -1 && endIndex != -1 && endIndex > startIndex) 57 | { 58 | endIndex += errorEndMarker.Length; 59 | string errorSection = code.Substring(startIndex, endIndex - startIndex); 60 | 61 | // 将错误代码部分转换为临时文件内容,以便使用Roslyn解析 62 | string tempCode = $@"using System; 63 | namespace Temp 64 | {{ 65 | public class TempClass 66 | {{ 67 | {errorSection} 68 | }} 69 | }}"; 70 | 71 | // 解析错误代码 72 | SyntaxTree tempTree = CSharpSyntaxTree.ParseText(tempCode); 73 | CompilationUnitSyntax tempRoot = tempTree.GetCompilationUnitRoot(); 74 | 75 | // 处理错误代码 76 | ProcessErrorCodes(tempRoot, generator); 77 | 78 | return errorSection; 79 | } 80 | 81 | return string.Empty; 82 | } 83 | 84 | /// 85 | /// 处理提取出的错误代码 86 | /// 87 | private static void ProcessErrorCodes(CompilationUnitSyntax root, CodeGenerator generator) 88 | { 89 | // 遍历命名空间 90 | foreach (var member in root.Members) 91 | { 92 | if (member is NamespaceDeclarationSyntax namespaceDecl) 93 | { 94 | // 遍历命名空间中的类 95 | foreach (var namespaceMember in namespaceDecl.Members) 96 | { 97 | if (namespaceMember is ClassDeclarationSyntax classDecl) 98 | { 99 | // 遍历类中的成员,只处理常量字段 100 | foreach (var classMember in classDecl.Members) 101 | { 102 | if (classMember is FieldDeclarationSyntax fieldDecl) 103 | { 104 | // 检查是否是常量字段 105 | if (fieldDecl.Modifiers.Any(SyntaxKind.ConstKeyword)) 106 | { 107 | // 获取字段注释 108 | string fieldComment = generator.GetComment(fieldDecl); 109 | 110 | // 生成字段声明 111 | string modifiers = string.Join(" ", fieldDecl.Modifiers); 112 | string fieldType = fieldDecl.Declaration.Type.ToString(); 113 | 114 | foreach (var variable in fieldDecl.Declaration.Variables) 115 | { 116 | string fieldName = variable.Identifier.Text; 117 | string fieldValue = variable.Initializer?.Value.ToString() ?? ""; 118 | 119 | // 清理字段值,移除无效字符 120 | fieldValue = fieldValue.Replace(";", "") 121 | .Replace(";", "") 122 | .Replace(",", ",") 123 | .Replace("。", "") 124 | .Replace("(", "(") 125 | .Replace(")", ")") 126 | .Trim(); 127 | 128 | // 清理注释,移除注释标记和无关文本 129 | string cleanComment = fieldComment.Replace("//", "").Trim(); 130 | 131 | // 添加到错误列表 132 | generator.AddErrorInfo(new ErrorInfo 133 | { 134 | Name = fieldName, 135 | Value = fieldValue, 136 | Description = cleanComment 137 | }); 138 | } 139 | } 140 | } 141 | } 142 | } 143 | } 144 | } 145 | } 146 | } 147 | 148 | /// 149 | /// 从代码中删除错误代码部分 150 | /// 151 | private static string RemoveErrorCodes(string code) 152 | { 153 | string errorStartMarker = "全局错误码 begin"; 154 | string errorEndMarker = "全局错误码 end"; 155 | 156 | int startIndex = code.IndexOf(errorStartMarker); 157 | int endIndex = code.IndexOf(errorEndMarker); 158 | 159 | if (startIndex != -1 && endIndex != -1 && endIndex > startIndex) 160 | { 161 | endIndex += errorEndMarker.Length; 162 | return code.Substring(0, startIndex) + code.Substring(endIndex); 163 | } 164 | 165 | return code; 166 | } 167 | } 168 | 169 | internal class CodeGenerator 170 | { 171 | private StringBuilder definesBuilder = new StringBuilder(); 172 | private StringBuilder methodsBuilder = new StringBuilder(); 173 | private StringBuilder errorsBuilder = new StringBuilder(); 174 | private List errorList = new List(); 175 | private List methodList = new List(); 176 | private static char[] SplitChars = new[] { '\r', '\n' }; 177 | 178 | private class MethodInfo 179 | { 180 | public MethodDeclarationSyntax MethodDecl { get; set; } 181 | public string Comment { get; set; } 182 | } 183 | 184 | /// 185 | /// 添加错误信息 186 | /// 187 | public void AddErrorInfo(ErrorInfo errorInfo) 188 | { 189 | errorList.Add(errorInfo); 190 | } 191 | 192 | /// 193 | /// 移除 #region 和 #endregion 指令 194 | /// 195 | public class RegionRemover : CSharpSyntaxRewriter 196 | { 197 | public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia) 198 | { 199 | // 移除 #region 和 #endregion 指令 200 | if (trivia.IsKind(SyntaxKind.RegionDirectiveTrivia) || 201 | trivia.IsKind(SyntaxKind.EndRegionDirectiveTrivia)) 202 | { 203 | return default; // 返回默认值会移除该 trivia 204 | } 205 | 206 | return base.VisitTrivia(trivia); 207 | } 208 | } 209 | 210 | public void Generate(CompilationUnitSyntax root) 211 | { 212 | //移除 #region 和 #endregion 指令 213 | var remover = new RegionRemover(); 214 | root = (CompilationUnitSyntax)remover.Visit(root); 215 | 216 | // 构建Defines.cs文件头 217 | definesBuilder.AppendLine("using System;"); 218 | definesBuilder.AppendLine("using System.Runtime.InteropServices;"); 219 | definesBuilder.AppendLine(); 220 | definesBuilder.AppendLine("namespace QuickNV.HikvisionNetSDK"); 221 | definesBuilder.AppendLine("{"); 222 | definesBuilder.AppendLine(" /// "); 223 | definesBuilder.AppendLine(" /// CHCNetSDK 的摘要说明。"); 224 | definesBuilder.AppendLine(" /// "); 225 | definesBuilder.AppendLine(" public partial class Defines"); 226 | definesBuilder.AppendLine(" {"); 227 | definesBuilder.AppendLine(" public Defines()"); 228 | definesBuilder.AppendLine(" {"); 229 | definesBuilder.AppendLine(" //"); 230 | definesBuilder.AppendLine(" // TODO: 在此处添加构造函数逻辑"); 231 | definesBuilder.AppendLine(" //"); 232 | definesBuilder.AppendLine(" "); 233 | definesBuilder.AppendLine(" }"); 234 | definesBuilder.AppendLine(); 235 | 236 | // 遍历命名空间 237 | foreach (var member in root.Members) 238 | { 239 | if (member is NamespaceDeclarationSyntax namespaceDecl) 240 | { 241 | // 遍历命名空间中的类 242 | foreach (var namespaceMember in namespaceDecl.Members) 243 | { 244 | if (namespaceMember is ClassDeclarationSyntax classDecl) 245 | { 246 | // 遍历类中的成员 247 | foreach (var classMember in classDecl.Members) 248 | { 249 | // 处理字段 250 | if (classMember is FieldDeclarationSyntax fieldDecl) 251 | { 252 | ProcessField(fieldDecl); 253 | } 254 | // 处理结构体 255 | else if (classMember is StructDeclarationSyntax structDecl) 256 | { 257 | ProcessStruct(structDecl); 258 | } 259 | // 处理方法 260 | else if (classMember is MethodDeclarationSyntax methodDecl) 261 | { 262 | ProcessMethod(methodDecl); 263 | } 264 | // 处理枚举 265 | else if (classMember is EnumDeclarationSyntax enumDecl) 266 | { 267 | ProcessEnum(enumDecl); 268 | } 269 | // 处理委托 270 | else if (classMember is DelegateDeclarationSyntax delegateDecl) 271 | { 272 | ProcessDelegate(delegateDecl); 273 | } 274 | else 275 | { 276 | Console.WriteLine("Warning: Untranslated type."); 277 | } 278 | } 279 | } 280 | } 281 | } 282 | } 283 | 284 | // 结束Defines.cs文件 285 | definesBuilder.AppendLine(" "); 286 | definesBuilder.AppendLine(" }"); 287 | definesBuilder.AppendLine("}"); 288 | 289 | // 生成Errors.cs 290 | GenerateErrors(); 291 | 292 | // 生成Methods.cs 293 | GenerateMethods(); 294 | } 295 | 296 | private void ProcessField(FieldDeclarationSyntax fieldDecl) 297 | { 298 | // 检查是否是常量字段 299 | if (fieldDecl.Modifiers.Any(SyntaxKind.ConstKeyword)) 300 | { 301 | // 获取字段注释 302 | string fieldComment = GetComment(fieldDecl); 303 | 304 | // 转换为标准文档注释 305 | string docComment = ConvertToDocComment(fieldComment); 306 | 307 | // 生成字段声明 308 | string modifiers = string.Join(" ", fieldDecl.Modifiers); 309 | string fieldType = fieldDecl.Declaration.Type.ToString(); 310 | 311 | foreach (var variable in fieldDecl.Declaration.Variables) 312 | { 313 | string fieldName = variable.Identifier.Text; 314 | string fieldValue = variable.Initializer?.Value.ToString() ?? ""; 315 | 316 | // 清理字段值,移除无效字符 317 | fieldValue = fieldValue.Replace(";", "") 318 | .Replace(";", "") 319 | .Replace(",", ",") 320 | .Replace("。", "") 321 | .Replace("(", "(") 322 | .Replace(")", ")") 323 | .Trim(); 324 | 325 | // 写入Defines.cs,确保所有行都有8个空格缩进 326 | if (!string.IsNullOrEmpty(docComment)) 327 | { 328 | // 先移除多余的空行,然后添加缩进 329 | string[] commentLines = docComment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 330 | foreach (string line in commentLines) 331 | { 332 | definesBuilder.AppendLine($" {line}"); 333 | } 334 | } 335 | definesBuilder.AppendLine($" {modifiers} {fieldType} {fieldName} = {fieldValue};"); 336 | } 337 | } 338 | } 339 | 340 | private void ProcessStruct(StructDeclarationSyntax structDecl) 341 | { 342 | // 获取注释并转换为标准文档注释 343 | string comment = GetComment(structDecl); 344 | string docComment = ConvertToDocComment(comment); 345 | 346 | // 写入Defines.cs 347 | definesBuilder.AppendLine(); 348 | if (!string.IsNullOrEmpty(docComment)) 349 | { 350 | string[] commentLines = docComment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 351 | foreach (string line in commentLines) 352 | { 353 | definesBuilder.AppendLine($" {line}"); 354 | } 355 | } 356 | 357 | // 添加StructLayout属性 358 | // 从原始结构体中提取StructLayout属性 359 | foreach (var attributeList in structDecl.AttributeLists) 360 | { 361 | definesBuilder.AppendLine($" {attributeList.ToFullString().Trim()}"); 362 | } 363 | definesBuilder.AppendLine($" {structDecl.Modifiers} struct {structDecl.Identifier}"); 364 | definesBuilder.AppendLine(" {"); 365 | 366 | // 遍历结构体成员 367 | foreach (var structMember in structDecl.Members) 368 | { 369 | // 只处理字段成员 370 | if (structMember is FieldDeclarationSyntax fieldDecl) 371 | { 372 | // 获取成员注释并转换为标准文档注释 373 | string memberComment = GetComment(fieldDecl); 374 | if (memberComment != null) 375 | memberComment = memberComment 376 | .Replace("<","<") 377 | .Replace(">",">") 378 | .Replace("&","&"); 379 | 380 | string memberDocComment = ConvertToDocComment(memberComment); 381 | if (!string.IsNullOrEmpty(memberDocComment)) 382 | { 383 | // 结构体成员注释:添加12个空格缩进 384 | string[] commentLines = memberDocComment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 385 | foreach (string line in commentLines) 386 | { 387 | definesBuilder.AppendLine($" {line}"); 388 | } 389 | } 390 | 391 | // 生成字段属性 392 | foreach (var attributeList in fieldDecl.AttributeLists) 393 | { 394 | definesBuilder.AppendLine(" " + attributeList.ToString().Trim()); 395 | } 396 | 397 | string fieldType = fieldDecl.Declaration.Type.ToString(); 398 | string fieldModifiers = string.Join(" ", fieldDecl.Modifiers); 399 | 400 | // 处理多个变量声明 401 | foreach (var variable in fieldDecl.Declaration.Variables) 402 | { 403 | string fieldName = variable.Identifier.Text; 404 | if (!string.IsNullOrEmpty(fieldModifiers)) 405 | { 406 | definesBuilder.AppendLine($" {fieldModifiers} {fieldType} {fieldName};"); 407 | } 408 | else 409 | { 410 | definesBuilder.AppendLine($" {fieldType} {fieldName};"); 411 | } 412 | } 413 | } 414 | else if (structMember is MethodDeclarationSyntax methodDecl) 415 | { 416 | definesBuilder.AppendLine(methodDecl.ToFullString()); 417 | } 418 | else if (structMember is StructDeclarationSyntax subStructDecl) 419 | { 420 | //ProcessStruct(subStructDecl); 421 | definesBuilder.AppendLine(subStructDecl.ToFullString()); 422 | } 423 | else 424 | { 425 | definesBuilder.AppendLine(structMember.ToFullString()); 426 | Console.WriteLine("Warning: Untranslated type."); 427 | } 428 | } 429 | 430 | definesBuilder.AppendLine(" }"); 431 | } 432 | 433 | private void ProcessMethod(MethodDeclarationSyntax methodDecl) 434 | { 435 | // 检查是否是DllImport方法 436 | bool isDllImport = false; 437 | foreach (var attributeList in methodDecl.AttributeLists) 438 | { 439 | foreach (var attribute in attributeList.Attributes) 440 | { 441 | // 检查是否是DllImport属性,包括DllImport和DllImportAttribute两种形式 442 | string attributeName = attribute.Name.ToString(); 443 | if (attributeName == "DllImport" || 444 | attributeName == "DllImportAttribute" || 445 | attributeName == "System.Runtime.InteropServices.DllImport" || 446 | attributeName == "System.Runtime.InteropServices.DllImportAttribute") 447 | { 448 | isDllImport = true; 449 | break; 450 | } 451 | } 452 | if (isDllImport) 453 | { 454 | break; 455 | } 456 | } 457 | 458 | if (isDllImport) 459 | { 460 | // 获取方法注释 461 | string comment = GetComment(methodDecl); 462 | 463 | // 存储方法声明和注释 464 | MethodInfo methodInfo = new MethodInfo 465 | { 466 | MethodDecl = methodDecl, 467 | Comment = comment 468 | }; 469 | methodList.Add(methodInfo); 470 | 471 | // 调试信息 472 | Console.WriteLine($"Found method: {methodDecl.Identifier.Text}"); 473 | Console.WriteLine($" Comment: {comment}"); 474 | } 475 | } 476 | 477 | private void ProcessDelegate(DelegateDeclarationSyntax delegateDecl) 478 | { 479 | // 获取注释并转换为标准文档注释 480 | string comment = GetComment(delegateDecl); 481 | string docComment = ConvertToDocComment(comment); 482 | 483 | // 生成委托声明 484 | string returnType = delegateDecl.ReturnType.ToString(); 485 | string delegateName = delegateDecl.Identifier.Text; 486 | string modifiers = string.Join(" ", delegateDecl.Modifiers); 487 | 488 | // 处理参数列表 489 | string parameters = string.Join(", ", delegateDecl.ParameterList.Parameters.Select(p => p.ToFullString().Trim())); 490 | 491 | // 写入Defines.cs 492 | definesBuilder.AppendLine(); 493 | if (!string.IsNullOrEmpty(docComment)) 494 | { 495 | string[] commentLines = docComment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 496 | foreach (string line in commentLines) 497 | { 498 | definesBuilder.AppendLine($" {line}"); 499 | } 500 | } 501 | definesBuilder.AppendLine($" {modifiers} delegate {returnType} {delegateName}({parameters});"); 502 | } 503 | 504 | private void ProcessEnum(EnumDeclarationSyntax enumDecl) 505 | { 506 | // 获取注释并转换为标准文档注释 507 | string comment = GetComment(enumDecl); 508 | string docComment = ConvertToDocComment(comment); 509 | 510 | // 写入Defines.cs 511 | definesBuilder.AppendLine(); 512 | if (!string.IsNullOrEmpty(docComment)) 513 | { 514 | string[] commentLines = docComment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 515 | foreach (string line in commentLines) 516 | { 517 | definesBuilder.AppendLine($" {line}"); 518 | } 519 | } 520 | string enumDefinition; 521 | if (enumDecl.BaseList != null && enumDecl.BaseList.Types.Count > 0) 522 | { 523 | // 枚举有基类型,如 : uint 524 | enumDefinition = $" {enumDecl.Modifiers} enum {enumDecl.Identifier} {enumDecl.BaseList.ToString()}"; 525 | } 526 | else 527 | { 528 | // 枚举没有基类型 529 | enumDefinition = $" {enumDecl.Modifiers} enum {enumDecl.Identifier}"; 530 | } 531 | definesBuilder.AppendLine(enumDefinition); 532 | definesBuilder.AppendLine(" {"); 533 | 534 | var fullcode = enumDecl.Members.ToFullString().Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 535 | // 遍历枚举成员 536 | for (int i = 0; i < enumDecl.Members.Count; i++) 537 | { 538 | var enumMember = enumDecl.Members[i]; 539 | 540 | // 获取成员注释 541 | string memberComment = GetComment(enumMember); 542 | if (string.IsNullOrWhiteSpace(memberComment)) 543 | { 544 | var line = fullcode.FirstOrDefault(o => o.Contains(enumMember.Identifier.Text)); 545 | if (!string.IsNullOrEmpty(line)) 546 | { 547 | var index = line.IndexOf("//"); 548 | if (index > 0) 549 | memberComment = line.Substring(index + 2).Trim(); 550 | else if ((index = line.IndexOf("/*")) > 0) 551 | { 552 | memberComment = line.Substring(index + 2).Trim(); 553 | index = memberComment.IndexOf("*/"); 554 | if (index > 0) 555 | memberComment = memberComment[..index].Trim(); 556 | } 557 | } 558 | } 559 | 560 | // 转换为标准文档注释 561 | string memberDocComment = ConvertToDocComment(memberComment); 562 | if (!string.IsNullOrEmpty(memberDocComment)) 563 | { 564 | // 枚举成员注释:添加12个空格缩进 565 | string[] commentLines = memberDocComment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 566 | foreach (string line in commentLines) 567 | { 568 | definesBuilder.AppendLine($" {line}"); 569 | } 570 | } 571 | 572 | string enumMemberStr; 573 | if (enumMember.EqualsValue != null) 574 | { 575 | // 枚举成员有显式赋值 576 | enumMemberStr = $" {enumMember.Identifier} = {enumMember.EqualsValue.Value}"; 577 | } 578 | else 579 | { 580 | // 枚举成员没有显式赋值,只输出成员名称 581 | enumMemberStr = $" {enumMember.Identifier}"; 582 | } 583 | if (i < enumDecl.Members.Count - 1) 584 | { 585 | enumMemberStr += ","; 586 | } 587 | definesBuilder.AppendLine(enumMemberStr); 588 | } 589 | 590 | definesBuilder.AppendLine(" }"); 591 | } 592 | 593 | private void GenerateErrors() 594 | { 595 | errorsBuilder.AppendLine("using System.ComponentModel;"); 596 | errorsBuilder.AppendLine(); 597 | errorsBuilder.AppendLine("namespace QuickNV.HikvisionNetSDK"); 598 | errorsBuilder.AppendLine("{"); 599 | errorsBuilder.AppendLine(" /// "); 600 | errorsBuilder.AppendLine(" /// 海康SDK错误代码枚举"); 601 | errorsBuilder.AppendLine(" /// "); 602 | errorsBuilder.AppendLine(" public enum Errors"); 603 | errorsBuilder.AppendLine(" {"); 604 | 605 | for (int i = 0; i < errorList.Count; i++) 606 | { 607 | var error = errorList[i]; 608 | // 添加XML文档注释 609 | if (!string.IsNullOrEmpty(error.Description)) 610 | { 611 | errorsBuilder.AppendLine(" /// "); 612 | errorsBuilder.AppendLine($" /// {error.Description}"); 613 | errorsBuilder.AppendLine(" /// "); 614 | } 615 | errorsBuilder.AppendLine($" [Description(\"{error.Description}\")]"); 616 | errorsBuilder.Append($" {error.Name} = {error.Value}"); 617 | if (i < errorList.Count - 1) 618 | { 619 | errorsBuilder.AppendLine(","); 620 | } 621 | else 622 | { 623 | errorsBuilder.AppendLine(); 624 | } 625 | } 626 | 627 | errorsBuilder.AppendLine(" }"); 628 | errorsBuilder.AppendLine("}"); 629 | } 630 | 631 | private void GenerateMethods() 632 | { 633 | // 生成Methods_Win.cs 634 | GeneratePlatformMethods("Methods_Win", "HCNetSDK.dll"); 635 | 636 | // 生成Methods_Linux.cs 637 | GeneratePlatformMethods("Methods_Linux", "hcnetsdk.so"); 638 | 639 | // 生成Methods.cs 640 | GenerateCrossPlatformMethods(); 641 | } 642 | 643 | private void GeneratePlatformMethods(string className, string dllPath) 644 | { 645 | StringBuilder sb = new StringBuilder(); 646 | sb.AppendLine("using System;"); 647 | sb.AppendLine("using System.Runtime.InteropServices;"); 648 | sb.AppendLine("using static QuickNV.HikvisionNetSDK.Defines;"); 649 | sb.AppendLine(); 650 | sb.AppendLine("namespace QuickNV.HikvisionNetSDK"); 651 | sb.AppendLine("{"); 652 | sb.AppendLine($" internal class {className}"); 653 | sb.AppendLine(" {"); 654 | sb.AppendLine($" public const string DllPath = \"{dllPath}\";"); 655 | sb.AppendLine(); 656 | 657 | // 调试信息 658 | Console.WriteLine($"Generating {className}.cs with {methodList.Count} methods"); 659 | 660 | int methodCount = 0; 661 | foreach (var methodInfo in methodList) 662 | { 663 | // 直接使用存储的MethodDecl对象 664 | MethodDeclarationSyntax methodDecl = methodInfo.MethodDecl; 665 | 666 | if (methodDecl != null) 667 | { 668 | try 669 | { 670 | // 调试信息 671 | Console.WriteLine($"Processing method: {methodDecl.Identifier.Text}"); 672 | 673 | // 获取方法注释 674 | string methodComment = methodInfo.Comment; 675 | string docComment = ConvertToDocComment(methodComment); 676 | if (!string.IsNullOrEmpty(docComment)) 677 | { 678 | // 平台特定方法:添加8个空格的缩进(与方法声明一致) 679 | string[] commentLines = docComment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 680 | foreach (string line in commentLines) 681 | { 682 | sb.AppendLine($" {line}"); 683 | } 684 | } 685 | sb.AppendLine(" [DllImport(DllPath)]"); 686 | // 生成方法声明 687 | string modifiers = string.Join(" ", methodDecl.Modifiers); 688 | string returnType = methodDecl.ReturnType.ToString(); 689 | string methodName = methodDecl.Identifier.Text; 690 | 691 | // 生成参数列表 692 | // 处理参数列表 693 | string parameters = string.Join(", ", methodDecl.ParameterList.Parameters.Select(p => p.ToFullString().Trim())); 694 | 695 | // 写入方法 696 | sb.AppendLine($" {modifiers} {returnType} {methodName}({parameters});"); 697 | sb.AppendLine(); 698 | 699 | methodCount++; 700 | // 调试信息 701 | Console.WriteLine($" Method {methodCount} written: {methodName}"); 702 | } 703 | catch (Exception ex) 704 | { 705 | // 调试信息 706 | Console.WriteLine($" Error processing method {methodDecl.Identifier.Text}: {ex.Message}"); 707 | } 708 | } 709 | } 710 | 711 | // 关闭类和命名空间 712 | sb.AppendLine(" }"); 713 | sb.AppendLine("}"); 714 | 715 | File.WriteAllText($"{className}.cs", sb.ToString()); 716 | 717 | // 调试信息 718 | Console.WriteLine($"Generated {className}.cs successfully"); 719 | Console.WriteLine($" Methods written: {methodCount}"); 720 | } 721 | 722 | private void GenerateCrossPlatformMethods() 723 | { 724 | StringBuilder sb = new StringBuilder(); 725 | sb.AppendLine("using System;"); 726 | sb.AppendLine("using System.Collections.Generic;"); 727 | sb.AppendLine("using System.Runtime.InteropServices;"); 728 | sb.AppendLine("using System.Text;"); 729 | sb.AppendLine("using static QuickNV.HikvisionNetSDK.Defines;"); 730 | sb.AppendLine(); 731 | sb.AppendLine("namespace QuickNV.HikvisionNetSDK"); 732 | sb.AppendLine("{"); 733 | sb.AppendLine(" public class Methods"); 734 | sb.AppendLine(" {"); 735 | sb.AppendLine(" private static bool IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;\n\n" + 736 | " public static int Invoke(int result)\n" + 737 | " {\n if (result < 0)\n" + 738 | " {\n uint lastErrorCode = NET_DVR_GetLastError();\n" + 739 | " throw new HikvisionException(lastErrorCode);\n" + 740 | " }\n return result;\n" + 741 | " }\n" + 742 | "\n" + 743 | " public static bool Invoke(bool result)\n" + 744 | " {\n if (!result)\n" + 745 | " {\n uint lastErrorCode = NET_DVR_GetLastError();\n" + 746 | " throw new HikvisionException(lastErrorCode);\n" + 747 | " }\n return result;\n" + 748 | " }"); 749 | sb.AppendLine(); 750 | 751 | // 生成方法包装 752 | foreach (var methodInfo in methodList) 753 | { 754 | // 直接使用存储的MethodDecl对象 755 | MethodDeclarationSyntax methodDecl = methodInfo.MethodDecl; 756 | if (methodDecl != null) 757 | { 758 | GenerateMethodWrapper(sb, methodDecl); 759 | } 760 | } 761 | 762 | sb.AppendLine(" }"); 763 | sb.AppendLine("}"); 764 | 765 | File.WriteAllText("Methods.cs", sb.ToString()); 766 | } 767 | 768 | private void GenerateMethodWrapper(StringBuilder sb, MethodDeclarationSyntax methodDecl) 769 | { 770 | // 获取方法信息 771 | var methodInfo = methodList.FirstOrDefault(m => m.MethodDecl == methodDecl); 772 | if (methodInfo != null) 773 | { 774 | // 转换为标准文档注释 775 | string docComment = ConvertToDocComment(methodInfo.Comment); 776 | if (!string.IsNullOrEmpty(docComment)) 777 | { 778 | // 跨平台方法:添加8个空格的缩进 779 | string[] commentLines = docComment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 780 | foreach (string line in commentLines) 781 | { 782 | sb.AppendLine($" {line}"); 783 | } 784 | } 785 | } 786 | 787 | // 方法签名 788 | string returnType = methodDecl.ReturnType.ToString(); 789 | string methodName = methodDecl.Identifier.Text; 790 | 791 | // 生成参数列表 792 | List parameters = new List(); 793 | List paramCalls = new List(); 794 | foreach (var param in methodDecl.ParameterList.Parameters) 795 | { 796 | string paramType = param.Type.ToString(); 797 | string paramName = param.Identifier.Text; 798 | string paramModifiers = string.Join(" ", param.Modifiers); 799 | 800 | // 生成参数声明 801 | string paramFullText = param.ToFullString().Trim(); 802 | parameters.Add(paramFullText); 803 | // 生成参数调用,保留ref/out修饰符 804 | var callModifiers = param.Modifiers.ToString().Trim(); 805 | 806 | if (!string.IsNullOrEmpty(callModifiers)) 807 | { 808 | paramCalls.Add($"{callModifiers} {paramName}"); 809 | } 810 | else 811 | { 812 | paramCalls.Add(paramName); 813 | } 814 | } 815 | 816 | // 生成方法声明 817 | sb.AppendLine($" public static {returnType} {methodName}({string.Join(", ", parameters)})"); 818 | sb.AppendLine(" {"); 819 | 820 | // 生成方法体 821 | string returnStr = returnType == "void" ? "" : "return "; 822 | sb.AppendLine(" if (IsWindows)"); 823 | sb.AppendLine($" {returnStr}Methods_Win.{methodName}({string.Join(", ", paramCalls)});"); 824 | sb.AppendLine(" else"); 825 | sb.AppendLine($" {returnStr}Methods_Linux.{methodName}({string.Join(", ", paramCalls)});"); 826 | sb.AppendLine(" }"); 827 | sb.AppendLine(); 828 | } 829 | 830 | /// 831 | /// 从语法节点中提取注释 832 | /// 833 | /// 语法节点 834 | /// 提取的注释内容 835 | public string GetComment(SyntaxNode node) 836 | { 837 | // 使用HashSet来避免重复注释行 838 | HashSet commentSet = new HashSet(); 839 | bool hasLeadingComments = false; 840 | 841 | // 处理前置注释(优先使用前置注释) 842 | var leadingTrivia = node.GetLeadingTrivia(); 843 | foreach (var trivia in leadingTrivia) 844 | { 845 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) 846 | { 847 | // 单行注释 848 | string comment = trivia.ToString().TrimStart('/').Trim(); 849 | // 排除全局错误码标记行 850 | if (!string.IsNullOrEmpty(comment) && !comment.Contains("全局错误码") && !comment.Contains("NET_DVR_SUPPORT")) 851 | { 852 | commentSet.Add(comment); 853 | hasLeadingComments = true; 854 | } 855 | } 856 | else if (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 857 | { 858 | // 多行注释 859 | string comment = trivia.ToString(); 860 | 861 | // 移除开头的/*和结尾的*/ 862 | comment = comment.Substring(2, comment.Length - 4); 863 | 864 | // 按行分割 865 | string[] lines = comment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 866 | 867 | // 处理每行,移除开头的*或* 868 | for (int i = 0; i < lines.Length; i++) 869 | { 870 | string line = lines[i].Trim(); 871 | if (line.StartsWith("*")) 872 | { 873 | line = line.Substring(1).Trim(); 874 | } 875 | // 排除全局错误码标记行 876 | if (!string.IsNullOrEmpty(line) && !line.Contains("全局错误码") && !line.Contains("NET_DVR_SUPPORT")) 877 | { 878 | commentSet.Add(line); 879 | hasLeadingComments = true; 880 | } 881 | } 882 | } 883 | else if (trivia.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia)) 884 | { 885 | // 文档注释 886 | string comment = trivia.ToString().Trim(); 887 | if (!string.IsNullOrEmpty(comment)) 888 | { 889 | commentSet.Add(comment); 890 | hasLeadingComments = true; 891 | } 892 | } 893 | } 894 | 895 | // 如果没有前置注释,再处理后置注释 896 | if (!hasLeadingComments) 897 | { 898 | var trailingTrivia = node.GetTrailingTrivia(); 899 | foreach (var trivia in trailingTrivia) 900 | { 901 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) 902 | { 903 | string comment = trivia.ToString().TrimStart('/').Trim(); 904 | // 排除全局错误码标记行 905 | if (!string.IsNullOrEmpty(comment) && !comment.Contains("全局错误码") && !comment.Contains("NET_DVR_SUPPORT")) 906 | { 907 | commentSet.Add(comment); 908 | } 909 | } 910 | } 911 | } 912 | 913 | // 对于枚举成员,只在没有前置注释的情况下才处理其他注释 914 | if (node is EnumMemberDeclarationSyntax enumMember && !hasLeadingComments) 915 | { 916 | if (enumMember.EqualsValue != null) 917 | { 918 | // 处理等号后面的注释 919 | var equalsTrailingTrivia = enumMember.EqualsValue.GetTrailingTrivia(); 920 | foreach (var trivia in equalsTrailingTrivia) 921 | { 922 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 923 | { 924 | string comment = trivia.ToString(); 925 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) 926 | { 927 | comment = comment.TrimStart('/').Trim(); 928 | } 929 | else if (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 930 | { 931 | // 移除开头的/*和结尾的*/ 932 | comment = comment.Substring(2, comment.Length - 4).Trim(); 933 | } 934 | // 排除全局错误码标记行 935 | if (!string.IsNullOrEmpty(comment) && !comment.Contains("全局错误码") && !comment.Contains("NET_DVR_SUPPORT")) 936 | { 937 | commentSet.Add(comment); 938 | } 939 | } 940 | } 941 | } 942 | 943 | // 处理枚举成员名称后面的注释(如果有的话) 944 | var identifierTrailingTrivia = enumMember.Identifier.TrailingTrivia; 945 | foreach (var trivia in identifierTrailingTrivia) 946 | { 947 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 948 | { 949 | string comment = trivia.ToString(); 950 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) 951 | { 952 | comment = comment.TrimStart('/').Trim(); 953 | } 954 | else if (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 955 | { 956 | // 移除开头的/*和结尾的*/ 957 | comment = comment.Substring(2, comment.Length - 4).Trim(); 958 | } 959 | // 排除全局错误码标记行 960 | if (!string.IsNullOrEmpty(comment) && !comment.Contains("全局错误码") && !comment.Contains("NET_DVR_SUPPORT")) 961 | { 962 | commentSet.Add(comment); 963 | } 964 | } 965 | } 966 | } 967 | // 对于字段声明,只在没有前置注释的情况下才处理行尾注释 968 | else if (node is FieldDeclarationSyntax fieldDecl && !hasLeadingComments) 969 | { 970 | // 处理每个变量声明的注释 971 | foreach (var variable in fieldDecl.Declaration.Variables) 972 | { 973 | // 处理变量名后面的注释 974 | var identifierTrailingTrivia = variable.Identifier.TrailingTrivia; 975 | foreach (var trivia in identifierTrailingTrivia) 976 | { 977 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 978 | { 979 | string comment = trivia.ToString(); 980 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) 981 | { 982 | comment = comment.TrimStart('/').Trim(); 983 | } 984 | else if (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 985 | { 986 | // 移除开头的/*和结尾的*/ 987 | comment = comment.Substring(2, comment.Length - 4).Trim(); 988 | } 989 | // 排除全局错误码标记行 990 | if (!string.IsNullOrEmpty(comment) && !comment.Contains("全局错误码") && !comment.Contains("NET_DVR_SUPPORT")) 991 | { 992 | commentSet.Add(comment); 993 | } 994 | } 995 | } 996 | 997 | // 处理等号后面的注释(如果有的话) 998 | if (variable.Initializer != null) 999 | { 1000 | var equalsTrailingTrivia = variable.Initializer.EqualsToken.TrailingTrivia; 1001 | foreach (var trivia in equalsTrailingTrivia) 1002 | { 1003 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 1004 | { 1005 | string comment = trivia.ToString(); 1006 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) 1007 | { 1008 | comment = comment.TrimStart('/').Trim(); 1009 | } 1010 | else if (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 1011 | { 1012 | // 移除开头的/*和结尾的*/ 1013 | comment = comment.Substring(2, comment.Length - 4).Trim(); 1014 | } 1015 | // 排除全局错误码标记行 1016 | if (!string.IsNullOrEmpty(comment) && !comment.Contains("全局错误码") && !comment.Contains("NET_DVR_SUPPORT")) 1017 | { 1018 | commentSet.Add(comment); 1019 | } 1020 | } 1021 | } 1022 | 1023 | // 处理初始化器后面的注释 1024 | var initializerTrailingTrivia = variable.Initializer.GetTrailingTrivia(); 1025 | foreach (var trivia in initializerTrailingTrivia) 1026 | { 1027 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 1028 | { 1029 | string comment = trivia.ToString(); 1030 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) 1031 | { 1032 | comment = comment.TrimStart('/').Trim(); 1033 | } 1034 | else if (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 1035 | { 1036 | // 移除开头的/*和结尾的*/ 1037 | comment = comment.Substring(2, comment.Length - 4).Trim(); 1038 | } 1039 | // 排除全局错误码标记行 1040 | if (!string.IsNullOrEmpty(comment) && !comment.Contains("全局错误码") && !comment.Contains("NET_DVR_SUPPORT")) 1041 | { 1042 | commentSet.Add(comment); 1043 | } 1044 | } 1045 | } 1046 | } 1047 | } 1048 | 1049 | // 处理字段声明语句的行尾注释 1050 | var fieldTrailingTrivia = fieldDecl.GetTrailingTrivia(); 1051 | foreach (var trivia in fieldTrailingTrivia) 1052 | { 1053 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 1054 | { 1055 | string comment = trivia.ToString(); 1056 | if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) 1057 | { 1058 | comment = comment.TrimStart('/').Trim(); 1059 | } 1060 | else if (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)) 1061 | { 1062 | // 移除开头的/*和结尾的*/ 1063 | comment = comment.Substring(2, comment.Length - 4).Trim(); 1064 | } 1065 | // 排除全局错误码标记行 1066 | if (!string.IsNullOrEmpty(comment) && !comment.Contains("全局错误码") && !comment.Contains("NET_DVR_SUPPORT")) 1067 | { 1068 | commentSet.Add(comment); 1069 | } 1070 | } 1071 | } 1072 | } 1073 | 1074 | // 将HashSet转换为List并连接成字符串返回 1075 | return string.Join("\n", commentSet.ToList()); 1076 | } 1077 | 1078 | /// 1079 | /// 将注释转换为dotnet标准文档注释 1080 | /// 1081 | /// 原始注释 1082 | /// 转换后的文档注释 1083 | private string ConvertToDocComment(string comment) 1084 | { 1085 | if (string.IsNullOrEmpty(comment)) 1086 | { 1087 | return string.Empty; 1088 | } 1089 | 1090 | // 如果已经是文档注释,直接返回 1091 | if (comment.StartsWith("///")) 1092 | { 1093 | return comment; 1094 | } 1095 | 1096 | // 转换为文档注释,不添加固定缩进,由调用方根据上下文添加 1097 | StringBuilder sb = new StringBuilder(); 1098 | sb.AppendLine("/// "); 1099 | 1100 | // 处理多行注释 1101 | string[] lines = comment.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); 1102 | foreach (var line in lines) 1103 | { 1104 | string trimmedLine = line.Trim(); 1105 | if (!string.IsNullOrEmpty(trimmedLine)) 1106 | { 1107 | sb.AppendLine($"/// {trimmedLine}"); 1108 | } 1109 | else 1110 | { 1111 | // 保留空行,但不添加内容 1112 | sb.AppendLine("///"); 1113 | } 1114 | } 1115 | 1116 | sb.AppendLine("/// "); 1117 | 1118 | return sb.ToString(); 1119 | } 1120 | 1121 | public void WriteFiles(string outputDir) 1122 | { 1123 | // 确保输出目录存在 1124 | Directory.CreateDirectory(outputDir); 1125 | 1126 | // 写入Defines.cs 1127 | string definesContent = definesBuilder.ToString(); 1128 | File.WriteAllText(Path.Combine(outputDir, "Defines.cs"), definesContent); 1129 | 1130 | // 写入Errors.cs 1131 | string errorsContent = errorsBuilder.ToString(); 1132 | File.WriteAllText(Path.Combine(outputDir, "Errors.cs"), errorsContent); 1133 | } 1134 | } 1135 | } --------------------------------------------------------------------------------