一、代碼截圖
VS
二、 部分代碼
由于代碼過長(超過1W行),這裡就不貼全部了,大家直接在更新下面下載下傳最新的SDK即可。
/// 設定碼流速度
/// </summary>
public const int NET_DVR_SETSPEED = 24;
/// <summary>
/// 保持與裝置的心跳(如果回調阻塞,建議2秒發送一次)
public const int NET_DVR_KEEPALIVE = 25;
//遠端按鍵定義如下:
/* key value send to CONFIG program */
public const int KEY_CODE_1 = 1;
public const int KEY_CODE_2 = 2;
public const int KEY_CODE_3 = 3;
public const int KEY_CODE_4 = 4;
public const int KEY_CODE_5 = 5;
public const int KEY_CODE_6 = 6;
public const int KEY_CODE_7 = 7;
public const int KEY_CODE_8 = 8;
public const int KEY_CODE_9 = 9;
public const int KEY_CODE_0 = 10;
public const int KEY_CODE_POWER = 11;
public const int KEY_CODE_MENU = 12;
public const int KEY_CODE_ENTER = 13;
public const int KEY_CODE_CANCEL = 14;
public const int KEY_CODE_UP = 15;
public const int KEY_CODE_DOWN = 16;
public const int KEY_CODE_LEFT = 17;
public const int KEY_CODE_RIGHT = 18;
public const int KEY_CODE_EDIT = 19;
public const int KEY_CODE_ADD = 20;
public const int KEY_CODE_MINUS = 21;
public const int KEY_CODE_PLAY = 22;
public const int KEY_CODE_REC = 23;
public const int KEY_CODE_PAN = 24;
public const int KEY_CODE_M = 25;
public const int KEY_CODE_A = 26;
public const int KEY_CODE_F1 = 27;
public const int KEY_CODE_F2 = 28;
/* for PTZ control */
public const int KEY_PTZ_UP_START = KEY_CODE_UP;
public const int KEY_PTZ_UP_STOP = 32;
public const int KEY_PTZ_DOWN_START = KEY_CODE_DOWN;
public const int KEY_PTZ_DOWN_STOP = 33;
public const int KEY_PTZ_LEFT_START = KEY_CODE_LEFT;
public const int KEY_PTZ_LEFT_STOP = 34;
public const int KEY_PTZ_RIGHT_START = KEY_CODE_RIGHT;
public const int KEY_PTZ_RIGHT_STOP = 35;
/// 光圈+
public const int KEY_PTZ_AP1_START = KEY_CODE_EDIT; /* 光圈+ */
public const int KEY_PTZ_AP1_STOP = 36;
/// 光圈-
public const int KEY_PTZ_AP2_START = KEY_CODE_PAN; /* 光圈- */
public const int KEY_PTZ_AP2_STOP = 37;
/// 聚焦+
public const int KEY_PTZ_FOCUS1_START = KEY_CODE_A; /* 聚焦+ */
public const int KEY_PTZ_FOCUS1_STOP = 38;
/// 聚焦-
public const int KEY_PTZ_FOCUS2_START = KEY_CODE_M;/* 聚焦- */
public const int KEY_PTZ_FOCUS2_STOP = 39;
/// 變倍+
public const int KEY_PTZ_B1_START = 40; /* 變倍+ */
public const int KEY_PTZ_B1_STOP = 41;
/// 變倍-
public const int KEY_PTZ_B2_START = 42; /* 變倍- */
public const int KEY_PTZ_B2_STOP = 43;
//9000新增
public const int KEY_CODE_11 = 44;
public const int KEY_CODE_12 = 45;
public const int KEY_CODE_13 = 46;
public const int KEY_CODE_14 = 47;
public const int KEY_CODE_15 = 48;
public const int KEY_CODE_16 = 49;
/// 擷取網絡應用參數 EMAIL
public const int NET_DVR_GET_EMAILCFG = 228;//
/// 設定網絡應用參數 EMAIL
public const int NET_DVR_SET_EMAILCFG = 229; //
//對應NET_DVR_EMAILCFG結構
//
public const int NET_DVR_GET_ALLHDCFG = 300; //
#region DS9000新增指令(_V30)
//裝置編碼類型配置(NET_DVR_COMPRESSION_AUDIO結構)
/// 擷取裝置語音對講編碼參數
public const int NET_DVR_GET_COMPRESSCFG_AUD = 1058; //
/// 設定裝置語音對講編碼參數
public const int NET_DVR_SET_COMPRESSCFG_AUD = 1059; //
#endregion
/// 預覽異常
public const int NET_DVR_REALPLAYEXCEPTION = 111;//
/// 預覽時連接配接斷開
public const int NET_DVR_REALPLAYNETCLOSE = 112;//
/// 預覽5s沒有收到資料
public const int NET_DVR_REALPLAY5SNODATA = 113; //
/// 預覽重連
public const int NET_DVR_REALPLAYRECONNECT = 114; //
/// 回放資料播放完畢
public const int NET_DVR_PLAYBACKOVER = 101;//
/// 回放異常
public const int NET_DVR_PLAYBACKEXCEPTION = 102;//
/// 回放時候連接配接斷開
public const int NET_DVR_PLAYBACKNETCLOSE = 103;//
/// 回放5s沒有收到資料
public const int NET_DVR_PLAYBACK5SNODATA = 104;
#region DS-6001D/F
/// DS-6001D Decoder
/// NET_DVR_DECODERINFO, *LPNET_DVR_DECODERINFO;
public struct NET_DVR_DECODERINFO
{
/// <summary>
/// 解碼裝置連接配接的伺服器IP
/// public byte byEncoderIP[16];
/// </summary>
public byte[] byEncoderIP;
/// 解碼裝置連接配接的伺服器的使用者名
/// public byte byEncoderUser[16];
public byte[] byEncoderUser;
/// 解碼裝置連接配接的伺服器的密碼
/// public byte byEncoderPasswd[16];
public byte[] byEncoderPasswd;
/// 解碼裝置連接配接伺服器的連接配接模式
public byte bySendMode;
/// 解碼裝置連接配接的伺服器的通道号
public byte byEncoderChannel;
/// 解碼裝置連接配接的伺服器的端口号
public ushort wEncoderPort;
/// 保留
/// public byte reservedData[4];
public byte[] reservedData;
}
/// NET_DVR_DECODERSTATE, *LPNET_DVR_DECODERSTATE;
public struct NET_DVR_DECODERSTATE
/// 解碼裝置連接配接的伺服器的連接配接模式
/// 解碼裝置連接配接伺服器的狀态
public uint dwConnectState;
#region 解碼裝置控制碼定義
public const int NET_DEC_STARTDEC = 1;
public const int NET_DEC_STOPDEC = 2;
public const int NET_DEC_STOPCYCLE = 3;
public const int NET_DEC_CONTINUECYCLE = 4;
/// NET_DVR_EMAILPARA, *LPNET_DVR_EMAILPARA;
public struct NET_DVR_EMAILPARA
/// 郵件賬号
/// public byte sUsername[64];
public string sUsername;
/// 郵件密碼
/// public byte sPassword[64];
public string sPassword;
/// public byte sSmtpServer[64];
public string sSmtpServer;
/// public byte sPop3Server[64];
public string sPop3Server;
/// 郵件位址
/// public byte sMailAddr[64];
public string sMailAddr;
/// 上傳報警/異常等的email
/// public byte sEventMailAddr1[64];
public byte[] sEventMailAddr1;
/// public byte sEventMailAddr2[64];
public byte[] sEventMailAddr2;
/// public byte res[16];
public byte[] res;
/// NET_DVR_NETCFG_OTHER, *LPNET_DVR_NETCFG_OTHER;
public struct NET_DVR_NETCFG_OTHER
public uint dwSize;
/// char sFirstDNSIP[16];
public string sFirstDNSIP;
/// char sSecondDNSIP[16];
public string sSecondDNSIP;
/// char sRes[32];
public string sRes;
/// 連接配接的通道配置 2007-11-05
/// NET_DVR_MATRIX_DECCHANINFO, *LPNET_DVR_MATRIX_DECCHANINFO;
public struct NET_DVR_MATRIX_DECCHANINFO
/// 是否啟用 0-否 1-啟用
public uint dwEnable;
/// 輪循解碼通道資訊
public NET_DVR_MATRIX_DECINFO struDecChanInfo;
/// 壓縮參數?
/// NET_DVR_COMPRESSIONCFG_NEW, *LPNET_DVR_COMPRESSIONCFG_NEW;
public struct NET_DVR_COMPRESSIONCFG_NEW
/// 定時錄像
public NET_DVR_COMPRESSION_INFO_EX struLowCompression;
/// 事件觸發錄像
public NET_DVR_COMPRESSION_INFO_EX struEventCompression;
/// 抓圖模式
public enum CAPTURE_MODE
/// BMP模式
BMP_MODE = 0, //
/// JPEG模式
JPEG_MODE = 1 //
/// 實時聲音模式
public enum REALSOUND_MODE
/// 獨占模式
MONOPOLIZE_MODE = 1,
/// 共享模式
SHARE_MODE = 2
/// 錄象檔案參數(帶卡号)
/// NET_DVR_FINDDATA_CARD, *LPNET_DVR_FINDDATA_CARD;
public struct NET_DVR_FINDDATA_CARD
/// 檔案名
/// char sFileName[100];
public string sFileName;
/// 檔案的開始時間
public NET_DVR_TIME struStartTime;
/// 檔案的結束時間
public NET_DVR_TIME struStopTime;
/// 檔案的大小
public uint dwFileSize;
/// 卡号?
/// char sCardNum[32];
public char sCardNum;
/// 設定重新連接配接間隔
/// NET_DVR_API BOOL __stdcall NET_DVR_SetReconnect(DWORD dwInterval = 30000, BOOL bEnableRecon = TRUE);
/// <param name="dwInterval"></param>
/// <param name="bEnableRecon"></param>
/// <returns></returns>
[DllImport("HCNetSDK.dll")]
public static extern bool NET_DVR_SetReconnect(uint dwInterval, bool bEnableRecon);
/// 通過IPSever擷取裝置動态IP位址[Ex]
/// NET_DVR_API BOOL __stdcall NET_DVR_GetDVRIPByResolveSvr_EX(char *sServerIP, WORD wServerPort, unsigned char *sDVRName, WORD wDVRNameLen, BYTE *sDVRSerialNumber, WORD wDVRSerialLen, char* sGetIP, DWORD *dwPort);
/// <param name="sServerIP"></param>
/// <param name="wServerPort"></param>
/// <param name="sDVRName"></param>
/// <param name="wDVRNameLen"></param>
/// <param name="sDVRSerialNumber"></param>
/// <param name="wDVRSerialLen"></param>
/// <param name="sGetIP"></param>
/// <param name="dwPort"></param>
public static extern bool NET_DVR_GetDVRIPByResolveSvr_EX(string sServerIP, ushort wServerPort, string sDVRName, ushort wDVRNameLen, string sDVRSerialNumber, ushort wDVRSerialLen, StringBuilder sGetIP, ref uint dwPort);
/// NET_DVR_API BOOL __stdcall NET_DVR_PTZControlWithSpeed_EX(LONG lRealHandle, DWORD dwPTZCommand, DWORD dwStop, DWORD dwSpeed);
/// <param name="lRealHandle"></param>
/// <param name="dwPTZCommand"></param>
/// <param name="dwStop"></param>
/// <param name="dwSpeed"></param>
public static extern bool NET_DVR_PTZControlWithSpeed_EX(int lRealHandle, uint dwPTZCommand, uint dwStop, uint dwSpeed);
/// NET_DVR_API BOOL __stdcall NET_DVR_PTZMltTrack(LONG lRealHandle,DWORD dwPTZTrackCmd, DWORD dwTrackIndex);
/// <param name="dwPTZTrackCmd"></param>
/// <param name="dwTrackIndex"></param>
public static extern bool NET_DVR_PTZMltTrack(int lRealHandle, uint dwPTZTrackCmd, uint dwTrackIndex);
/// NET_DVR_API BOOL __stdcall NET_DVR_PTZMltTrack_Other(LONG lUserID,LONG lChannel,DWORD dwPTZTrackCmd, DWORD dwTrackIndex);
/// <param name="lUserID"></param>
/// <param name="lChannel"></param>
public static extern bool NET_DVR_PTZMltTrack_Other(int lUserID, int lChannel, uint dwPTZTrackCmd, uint dwTrackIndex);
/// NET_DVR_API BOOL __stdcall NET_DVR_PTZMltTrack_EX(LONG lRealHandle,DWORD dwPTZTrackCmd, DWORD dwTrackIndex);
public static extern bool NET_DVR_PTZMltTrack_EX(int lRealHandle, uint dwPTZTrackCmd, uint dwTrackIndex);
/// NET_DVR_API LONG __stdcall NET_DVR_FindNextFile_Card(LONG lFindHandle, LPNET_DVR_FINDDATA_CARD lpFindData);
/// <param name="lFindHandle"></param>
/// <param name="lpFindData"></param>
public static extern int NET_DVR_FindNextFile_Card(int lFindHandle, NET_DVR_FINDDATA_CARD lpFindData);
/// NET_DVR_API LONG __stdcall NET_DVR_FindFile_Card(LONG lUserID, LONG lChannel, DWORD dwFileType, LPNET_DVR_TIME lpStartTime, LPNET_DVR_TIME lpStopTime);
/// <param name="dwFileType"></param>
/// <param name="lpStartTime"></param>
/// <param name="lpStopTime"></param>
public static extern int NET_DVR_FindFile_Card(int lUserID, int lChannel, uint dwFileType, NET_DVR_TIME lpStartTime, NET_DVR_TIME lpStopTime);
/// NET_DVR_API int __stdcall NET_DVR_GetPlayBackPos(LONG lPlayHandle);
/// <param name="lPlayHandle"></param>
public static extern int NET_DVR_GetPlayBackPos(int lPlayHandle);
//解碼裝置DS-6001D/DS-6001F
/// NET_DVR_API BOOL __stdcall NET_DVR_StartDecode(LONG lUserID, LONG lChannel, LPNET_DVR_DECODERINFO lpDecoderinfo);
/// <param name="lpDecoderinfo"></param>
public static extern bool NET_DVR_StartDecode(int lUserID, int lChannel, NET_DVR_DECODERINFO lpDecoderinfo);
/// NET_DVR_API BOOL __stdcall NET_DVR_StopDecode(LONG lUserID, LONG lChannel);
public static extern bool NET_DVR_StopDecode(int lUserID, int lChannel);
/// NET_DVR_API BOOL __stdcall NET_DVR_GetDecoderState(LONG lUserID, LONG lChannel, LPNET_DVR_DECODERSTATE lpDecoderState);
/// <param name="lpDecoderState"></param>
public static extern bool NET_DVR_GetDecoderState(int lUserID, int lChannel, NET_DVR_DECODERSTATE lpDecoderState);
/// 儲存參數
/// NET_DVR_API BOOL __stdcall NET_DVR_SaveConfig(LONG lUserID);
public static extern bool NET_DVR_SaveConfig(int lUserID);
/// NET_DVR_API BOOL __stdcall NET_DVR_SetVideoEffect(LONG lUserID, LONG lChannel, DWORD dwBrightValue, DWORD dwContrastValue, DWORD dwSaturationValue, DWORD dwHueValue);
/// <param name="dwBrightValue"></param>
/// <param name="dwContrastValue"></param>
/// <param name="dwSaturationValue"></param>
/// <param name="dwHueValue"></param>
public static extern bool NET_DVR_SetVideoEffect(int lUserID, int lChannel, uint dwBrightValue, uint dwContrastValue, uint dwSaturationValue, uint dwHueValue);
/// NET_DVR_API BOOL __stdcall NET_DVR_GetVideoEffect(LONG lUserID, LONG lChannel, DWORD *pBrightValue, DWORD *pContrastValue, DWORD *pSaturationValue, DWORD *pHueValue);
/// <param name="pBrightValue"></param>
/// <param name="pContrastValue"></param>
/// <param name="pSaturationValue"></param>
/// <param name="pHueValue"></param>
public static extern bool NET_DVR_GetVideoEffect(int lUserID, int lChannel, out uint pBrightValue, out uint pContrastValue, out uint pSaturationValue, out uint pHueValue);
三、下章預告
實作最基本的連接配接伺服器并預覽圖像的功能。