C#封装的海康DVR客户端SDK
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
namespace HIK
{
public delegate void fVoiceDataCallBack(int lVoiceComHandle,
[MarshalAs(UnmanagedType.LPArray)] byte[] pRecvDataBuffer, uint
dwBufSize, byte byAudioFlag, uint dwUser);
public delegate void SerialDataCallBack(int lSerialHandle,
[MarshalAs(UnmanagedType.LPArray)] byte[] pRecvDataBuffer, uint
dwBufSize, uint dwUser);
public delegate void DrawFun(int
lRealHandle,System.Drawing.Graphics hDc,uint dwUser);
public delegate void RealDataCallBack(int lRealHandle, uint
dwDataType, [MarshalAs(UnmanagedType.LPArray, SizeConst = 11520)] byte[]
pBuffer, uint dwBufSize, uint dwUser);
public delegate void PlayDataCallBack(int lPlayHandle, uint
dwDataType, [MarshalAs(UnmanagedType.LPArray)] byte[] pBuffer, uint
dwBufSize, uint dwUser);
public struct NET_DVR_DEVICEINFO
{
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
public byte[] sSerialNumber;//[SERIALNO_LEN]; //序列号
public byte byAlarmInPortNum; //DVR报警输入个数
public byte byAlarmOutPortNum; //DVR报警输出个数
public byte byDiskNum; //DVR 硬盘个数
public byte byDVRType; //DVR类型,
public byte byChanNum; //DVR 通道个数
public byte byStartChan; //起始通道号,例如DVS-1,DVR - 1
}
public struct NET_DVR_DISKSTATE
{
public uint dwVolume;//硬盘的容量
public uint dwFreeSpace;//硬盘的剩余空间
public uint dwHardDiskStatic; //硬盘的状态,休眠,活动,不正常等
}
public struct NET_DVR_TIME
{
public uint dwYear; //年
public uint dwMonth; //月
public uint dwDay; //日
public uint dwHour; //时
public uint dwMinute; //分
public uint dwSecond; //秒
}
public struct NET_DVR_FIND_DATA
{
public string sFileName;//文件名
public NET_DVR_TIME struStartTime;//文件的开始时间
public NET_DVR_TIME struStopTime;//文件的结束时间
public uint dwFileSize;//文件的大小
}
public struct NET_DVR_CHANNELSTATE
{
public byte byRecordStatic; //通道是否在录像,0-不录像,1-录像
public byte bySignalStatic; //连接的信号状态,0-正常,1-信号丢失
public byte byHardwareStatic;//通道硬件状态,0-正常,1-异常,例如
DSP死掉
public char reservedData;
public uint dwBitRate;//实际码率
public uint dwLinkNum;//客户端连接的个数
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] //MAX_LINK
public uint[] dwClientIP;//客户端的IP地址
}
public struct NET_DVR_WORKSTATE
{
public uint dwDeviceStatic; //设备的状态,0-正常,1-CPU占用率太
高,超过85%,2-硬件错误,例如串口死掉
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public NET_DVR_DISKSTATE[] struHardDiskStatic; //MAX_DISKNUM
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public NET_DVR_CHANNELSTATE[] struChanStatic;//通道的状态MAX_CHANNUM
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] byAlarmInStatic; //报警端口的状态,0-没有报警,1-有
报警MAX_ALARMIN
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] byAlarmOutStatic; //报警输出端口的状态,0-没有输出,
1-有报警输出MAX_ALARMOUT
public uint dwLocalDisplay;//本地显示状态,0-正常,1-不正常
}
public struct NET_DVR_ETHERNET
{
public string sDVRIP; //DVR IP地址
public string sDVRIPMask; // DVR IP地址掩码
public uint dwNetInterface; //网络接口 1-10MBase-T 2-10MBase-T
全双工 3-100MBase-TX 4-100M全双工 5-10M/100M自适应
public ushort wDVRPort; //端口号
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] byMACAddr; //服务器的物理地址MACADDR_LEN
}
public struct NET_DVR_NETCFG
{
public uint dwSize;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public NET_DVR_ETHERNET[] struEtherNet; /* 以太网口 */
public string sManageHostIP; //远程管理主机地址
public short wManageHostPort; //远程管理主机端口号
public string sDNSIP; //DNS服务器地址
public string sMultiCastIP; //多播组地址
public string sGatew
ayIP; //网关地址
public string sNFSIP; //NAS主机IP地址
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public byte[] sNFSDirectory;//NAS目录PATHNAME_LEN
public uint dwPPPOE; //0-不启用,1-启用
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] sPPPoEUser; //PPPoE用户名NAME_LEN
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public string sPPPoEPassword;// PPPoE密码
public string sPPPoEIP; //PPPoE IP地址(只读)
public ushort wHttpPort; //HTTP端口号
}
public struct NET_DVR_ALARMOUTSTATUS
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] Output;//MAX_ALARMOUT
}
public struct NET_DVR_CLIENTINFO{
public int lChannel;//通道号
public int lLinkMode;//最高位(31)为0表示主码流,为1表示子码流,0-30位
表示码流连接方式: 0:TCP方式,1:UDP方式,2:多播方式,3 - RTP方式,4-音视
频分开(TCP)
public System.IntPtr hPlayWnd;//播放窗口的句柄,为NULL表示不播放图象
public string sMultiCastIP;//多播组地址
}
/// <summary>
/// 海康嵌入式
/// </summary>
public sealed class Hik_HCNetSDK
{
#region 常量定义
public const int NET_DVR_NOERROR = 0; //没有错误
public const int NET_DVR_PASSWORD_ERROR = 1; //用户名密码错误
public const int NET_DVR_NOENOUGHPRI = 2; //权限不足
public const int NET_DVR_NOINIT = 3; //没有初始化
public const int NET_DVR_CHANNEL_ERROR = 4; //通道号错误
public const int NET_DVR_OVER_MAXLINK = 5; //连接到DVR的客户端个
数超过最大
public const int NET_DVR_VERSIONNOMATCH = 6; //版本不匹配
public const int NET_DVR_NETWORK_FAIL_CONNECT = 7;//连接服务器失败
public const int NET_DVR_NETWORK_SEND_ERROR = 8; //向服务器发送失败
public const int NET_DVR_NETWORK_RECV_ERROR = 9;//从服务器接收数
据失败
public const int NET_DVR_NETWORK_RECV_TIMEOUT = 10; //从服务器接
收数据超时
public const int NET_DVR_NETWORK_ERRORDATA = 11; //传送的数据有误
public const int NET_DVR_ORDER_ERROR = 12;//调用次序错误
public const int NET_DVR_OPERNOPERMIT = 13; //无此权限
public const int NET_DVR_COMMANDTIMEOUT = 14;//DVR命令执行超时
public const int NET_DVR_ERRORSERIALPORT = 15;//串口号错误
public const int NET_DVR_ERRORALARMPORT = 16; //报警端口错误
public const int NET_DVR_PARAMETER_ERROR = 17; //参数错误
public const int NET_DVR_CHAN_EXCEPTION = 18;//服务器通道处于错
误状态
public const int NET_DVR_NODISK = 19;//没有硬盘
public const int NET_DVR_ERRORDISKNUM = 20;//硬盘号错误
public const int NET_DVR_DISK_FULL = 21; //服务器硬盘满
public const int NET_DVR_DISK_ERROR = 22;//服务器硬盘出错
public const int NET_DVR_NOSUPPORT = 23; //服务器不支持
public const int NET_DVR_BUSY = 24;//服务器忙
public const int NET_DVR_MODIFY_FAIL = 25; //服务器修改不成功
public const int NET_DVR_PASSWORD_FORMAT_ERROR = 26; //密码输入
格式不正确
public const int NET_DVR_DISK_FORMATING = 27; //硬盘正在格式化,
不能启动操作
public const int NET_DVR_DVRNORESOURCE = 28; //DVR资源不足
public const int NET_DVR_DVROPRATEFAILED = 29; //DVR操作失败
public const int NET_DVR_OPENHOSTSOUND_FAIL = 30; //打开PC声音失败
public const int NET_DVR_DVRVOICEOPENED = 31; //服务器语音对讲被占用
public const int NET_DVR_TIMEINPUTERROR = 32; //时间输入不正确
public const int NET_DVR_NOSPECFILE = 33; //回放时服务器没有指定
的文件
public const int NET_DVR_CREATEFILE_ERROR = 34;//创建文件出错
public const int NET_DVR_FILEOPENFAIL = 35; //打开文件出错
public const int NET_DVR_OPERNOTFINISH = 36; //上次的操作还没有完成
public const int NET_DVR_GETPLAYTIMEFAIL = 37; //获取当前播放的
时间出错
public const int NET_DVR_PLAYFAIL = 38; //播放出错
public const int NET_DVR_FILEFORMAT_ERROR = 39; //文件格式不正确
public const int NET_DVR_DIR_ERROR = 40; //路径错误
public const int NET_DVR_ALLOC_RESOUCE_ERROR = 41; //资源分配错误
public const int NET_DVR_AUDIO_MODE_ERROR = 42; //声卡模式错误
public const int NET_DVR_NOENOUGH_BUF = 43;//缓冲区太小
public const int NET_DVR_CREATESOCKET_ERROR = 44; //创建SOCKET出错
public const int NET_DVR_SETSOCKET_ERROR = 45; //设置SOCKET出错
public const int NET_DVR_MAX_NUM = 46;//个数达到最大
public const int NET_DVR_USERNOTEXIST = 47; //用户不存在
public const int NET_DVR_WRITEFLASHERROR = 48; //写FLASH出错
public const int NET_DVR_UPGRADEFAIL = 49; //DVR升级失败
public const int NET_DVR_CARDHAVEINIT = 50; //解码卡已经初始化过
public const int NET_DVR_PLAYERFAILED = 51; //播放器中错误
public const int NET_DVR_MAX_USERNUM = 52; //用户数达到最大
public const int NET_DVR_GETLOCALIPANDMACFAIL = 53; //获得客户端
的IP地址或物理地址失败
public const int NET_DVR_NOENCODEING = 54;//该通道没有编码
public const int NET_DVR_IPMISMATCH = 55; //IP地址不匹配
public const int NET_DVR_MACMISMATCH = 56;//MAC地址不匹配
public const int NET_DVR_UPGRADELANGMISMATCH = 57;//升级文件语言
不匹配
public const int NET_DVR_DDRAWDEVICENOSUPPORT = 58;//本地显卡不支持
//查找文件和日志函数返回值
public const int NET_DVR_FILE_SUCCESS = 1000; //获得文件信息
public const int NET_DVR_FILE_NOFIND = 1001;//没有文件
public const int NET_DVR_ISFINDING = 1002;//正在查找文件
public const int NET_DVR_NOMOREFILE = 1003; //查找文件时没有更多
的文件
public const int NET_DVR_FILE_EXCEPTION = 1004; //查找文件时异常
//NET_DVR_IsSupport()返回值
//1-9位分别表示以下信息(位与是TRUE)表示支持;
public const int NET_DVR_SUPPORT_DDRAW = 0x01;//支持DIRECTDRAW,
如果不支持,则播放器不能工作;
public const int NET_DVR_SUPPORT_BLT = 0x02;//显卡支持BLT操作,
如果不支持,则播放器不能工作;
public const int NET_DVR_SUPPORT_BLTFOURCC = 0x04;//显卡BLT支持
颜色转换,如果不支持,播放器会用软件方法作RGB转换;
public const int NET_DVR_SUPPORT_BLTSHRINKX = 0x08;//显卡BLT支持
X轴缩小;如果不支持,系统会用软件方法转换;
public const int NET_DVR_SUPPORT_BLTSHRINKY = 0x10;//显卡BLT支持
Y轴缩小;如果不支持,系统会用软件方法转换;
public const int NET_DVR_SUPPORT_BLTSTRETCHX = 0x20;//显卡BLT支
持X轴放大;如果不支持,系统会用软件方法转换;
public const int NET_DVR_SUPPORT_BLTSTRETCHY = 0x40;//显卡BLT支
持Y轴放大;如果不支持,系统会用软件方法转换;
public const int NET_DVR_SUPPORT_SSE = 0x80;//CPU支持SSE指令,
Intel Pentium3以上支持SSE指令;
public const int NET_DVR_SUPPORT_MMX = 0x100;//CPU支持MMX指令
集,Intel Pentium3以上支持SSE指令;
public const int SET_PRESET = 8;// 设置预置点
public const int CLE_PRESET = 9; // 清除预置点
public const int GOTO_PRESET = 39;// 转到预置点
public const int LIGHT_PWRON = 2; /* 接通灯光电源 */
public const int WIPER_PWRON = 3; /* 接通雨刷开关 */
public const int FAN_PWRON = 4;/* 接通风扇开关 */
public const int HEATER_PWRON = 5;/* 接通加热器开关 */
public const int AUX_PWRON = 6;/* 接通辅助设备开关 */
public const int ZOOM_IN = 11; /* 焦距以速度SS变大(倍率变大) */
public const int ZOOM_OUT = 12;/* 焦距以速度SS变小(倍率变小) */
public const int FOCUS_NEAR = 13; /* 焦点以速度SS前调 */
public const int FOCUS_FAR = 14;/* 焦点以速度SS后调 */
public const int IRIS_OPEN = 15; /* 光圈以速度SS扩大 */
public const int IRIS_CLOSE = 16; /* 光圈以速度SS缩小 */
public const int TILT_UP = 21;/* 云台以SS的速度上仰 */
public const int TILT_DOWN = 22;/* 云台以SS的速度下俯 */
public const int PAN_LEFT = 23;/* 云台以SS的速度左转 */
public const int PAN_RIGHT = 24; /* 云台以SS的速度右转 */
public const int PAN_AUTO = 29; /* 云台以SS的速度左右自动扫描 */
public const int RUN_CRUISE = 36; /* 开始轨迹 */
public const int RUN_SEQ = 37; /* 开始巡航 */
public const int STOP_SEQ = 38;/* 停止巡航 */
//显示模式
public enum DispMode { NORMALMODE = 0, OVERLAYMODE };
//发送模式
public enum TransMode { PTOPTCPMODE, PTOPUDPMODE, MULTIMODE,
RTPMODE, AUDIODETACH, NOUSEMODE };
public const int NET_DVR_SYSHEAD = 1;//系统头数据
public const int NET_DVR_STREAMDATA = 2; //流数据
//播放控制命令宏定义
NET_DVR_PlayBackControl,NET_DVR_PlayControlLocDisplay,NET_DVR_DecPlayBackCtrl
的宏定义
public const int NET_DVR_PLAYSTART = 1;//开始播放
public const int NET_DVR_PLAYSTOP = 2;//停止播放
public const int NET_DVR_PLAYPAUSE = 3;//暂停播放
public const int NET_DVR_PLAYRESTART = 4;//恢复播放
public const int NET_DVR_PLAYFAST = 5;//快放
public const int NET_DVR_PLAYSLOW = 6;//慢放
public const int NET_DVR_PLAYNORMAL = 7;//正常速度
public const int NET_DVR_PLAYFRAME = 8;//单帧放
public const int NET_DVR_PLAYSTARTAUDIO = 9;//打]]
>