前言
從上篇文章(10月4日)到本篇文章截止到今天(10月22日)一直在做這個sdk翻譯工作,耗時2周半,代碼超過1萬行,約有三分之二的行數是注釋。由于工作忙也隻能一天抽出那麼半個小時一個小時來整理,是以對關注此系列文章的朋友說句:“抱歉,讓大家久等了”。
臨時決定本系列使用wpf來做例子(買了一本wpf沒讀 - - #,是以......),藉此學習下wpf,也進一步熟悉.net framework 3.5,落伍的“老兵”奮起追擊下相對于“老兵”而言的新技術 :)
其實這篇文章在10月22日就寫好了,但是想和視訊預覽文章一起釋出,比較麻煩的是我這邊朋友的dvr一直不穩定,一直拖延到今天還是不行,是以還是把本文先發了。是以尋求能提供dvr裝置的廠家或者提供dvr遠端通路位址的朋友,以支援此系列能順利的完成,在這裡先謝謝了!我的聯系方式:13811821337、[email protected]
提醒
系列
更新
本文會随着後續實踐文章有相應的改動,請及時更新!
主要更新了大部分結構體中byte[]初始大小指定,加上了[marshalas(unmanagedtype.byvalarray, sizeconst = hcnetsdk.serialno_len)]類似的标記。
正文
一、代碼截圖
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);
三、下章預告
實作最基本的連接配接伺服器并預覽圖像的功能。
結束語
首先我必須強調本章的翻譯是一個體力活!本章可能會再随後的文章不斷的更新,主要是資料類型對應可能有問題,這裡也是憑經驗來進行對應了,也歡迎有朋友盡早的向我送出勘誤,我好及時的更新文章。
轉載:http://www.cnblogs.com/over140/archive/2009/10/24/1577975.html