登录 注册
当前位置:主页 > 资源下载 > 50 > 海康卫视研发了dll文件

海康卫视研发了dll文件

  • 更新:2024-05-18 17:20:56
  • 大小:356KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:C# - 后端
  • 格式:DLL

资源介绍

#region using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Threading; using SocketLibrary; #endregion namespace HkwsSDK { /// /// 在海康威视的SDK包上,再进行封装,供简单直接的调用. /// 目前可以控制硬盘录像机和解码器,需要两者密码一样. /// public class HKWS : IDisposable { #region (0)变量定义 /// /// 发现的文件信息结构 /// private readonly NetSDK.NET_DVR_FIND_DATA[] FindData = new NetSDK.NET_DVR_FIND_DATA[1000]; /// /// 远程录像状态 /// public int _StatusSaveMp4; /// /// 功能:设定播放延迟和流畅。 /// 调节播放的延时和流畅程度,如果buffNum值越大,播放的流畅性越好, /// 相应的延时比较大,buffNum值越小,播放的延时很小, /// 但是当网络不太顺畅的时候,会有丢帧现象,感觉播放不会很流畅。 /// 一般设置的帧缓冲大于等于6帧时,音频预览才会正常, /// 如果不需要音频预览,只需要视频实时性则这个值可以设置的更小。 /// public int buffNum = 10; public int bytesReturned; public int channel = 1; public int channelCount = 5; // 共8个通道 public int channelStart = 1; /// /// 客户端信息结构 /// public NetSDK.NET_DVR_CLIENTINFO ClientInfo; /// /// 解码器通道信息 /// public NetSDK.NET_DVR_MATRIX_DEC_CHAN_INFO dci; /// /// 解码器设备配置信息结构 /// public NetSDK.NET_DVR_DEVICECFG DecoderDeviceCfg; /// /// 解码器设备信息结构体结构实体化 /// public NetSDK.NET_DVR_DEVICEINFO DecoderDeviceInfo; /// /// 解码器信息结构体实例化 /// public Server_Info DecoderInfo; /// /// 解码器登录用户id /// public int decoderUserID; /// /// 硬盘录像机设备配置信息结构 /// public NetSDK.NET_DVR_DEVICECFG DvrDeviceCfg; /// /// 硬盘录像机设备信息结构体结构 /// public NetSDK.NET_DVR_DEVICEINFO DvrDeviceInfo; /// /// 硬盘录像机信息结构体实例化 /// public Server_Info DvrInfo; public int[] fileCount = new int[9]; /// /// 输出最新的文件信息,初始化为最大为9的结构体数组 /// public NewRec FileLastRec = new NewRec(9); public int findHandle; // 查找文件的句柄 /// /// 在线视频播放状态,确保在线视频只播放一次 /// private int isOnline; /// /// jpeg文件格式配置结构 /// public NetSDK.NET_DVR_JPEGPARA JpegPara; /// /// 输出JPG文件名的数组,共9 /// public string[] jpgName = new string[9]; public DateTime[] lastFileTime = new DateTime[9]; public int lt; /// /// 解码器实时解码配置信息 /// public NetSDK.NET_DVR_MATRIX_DYNAMIC_DEC mdd; /// /// 保存录像到本地时候的mp4文件名数组,[1-8]输出1-8通道的文件名 /// public string[] mp4FileName = new string[9]; /// /// 实例化视频上传类 /// public NetFileTransferClient Ntc = new NetFileTransferClient(); /// /// playHandle,NET_DVR_PlayBackByName() /// 或者NET_DVR_PlayBackByTime()的返回值 /// 功能:用来回放文件 /// public int[] playHandle = new int[9]; /// /// RealPlay句柄,NET_DVR_RealPlay的返回值,作为NET_DVR_StopRealPlay等函数的参数 /// 功能:用来播放或者捕获在线视频 /// public int[] realHandle = new int[9]; /// /// 远程回放播放句柄,NET_DVR_PlayBackByName()或者NET_DVR_PlayBackByTime()的返回值 /// public int remotePlayHandle; public bool st; /// /// 专用信息字符输出,自带\r\n /// public string strOut; /// /// 丢弃B帧的个数,取值为0,1,2,0-不丢,1-丢1个B帧,2-丢2个B帧; /// 在多路播放时,将B帧丢弃可以降低CPU的利用率, /// 不过当一路时,最好不丢弃B帧 /// public int throwNum = 1; public int userID; /// /// 语音对讲的句柄 /// public int vocieHandle = -1; /// /// 硬盘录像机设备的状态信息 /// public NetSDK.NET_DVR_WORKSTATE WorkState; public int xm; /// /// 构造函数,实例化类的运行 /// public HKWS() { mdd = new NetSDK.NET_DVR_MATRIX_DYNAMIC_DEC(); dci = new NetSDK.NET_DVR_MATRIX_DEC_CHAN_INFO(); ClientInfo = new NetSDK.NET_DVR_CLIENTINFO(); DvrDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DecoderDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); JpegPara = new NetSDK.NET_DVR_JPEGPARA(); DvrInfo = new Server_Info(); DecoderInfo = new Server_Info(); DvrDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); DecoderDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); WorkState = new NetSDK.NET_DVR_WORKSTATE(); } #region Nested type: NewRec /// /// 输出最新的文件信息的结构体 /// public struct NewRec { /// /// 文件大小 /// public uint[] fileSize; /// /// 是否有文件信息 /// public bool[] info; /// /// 文件名 /// public string[] NewFileName; /// /// 开始录像时间 /// public NetSDK.NET_DVR_TIME[] startTime; /// /// 结束录像时间 /// public NetSDK.NET_DVR_TIME[] stopTime; /// /// 构造函数 /// /// 实例化参数 public NewRec(int i) { info = new bool[i]; fileSize = new uint[i]; NewFileName = new string[i]; startTime = new NetSDK.NET_DVR_TIME[i]; stopTime = new NetSDK.NET_DVR_TIME[i]; } } #endregion #region Nested type: Server_Info /// /// 硬盘录像机信息 /// public struct Server_Info { /// /// 报警输入个数 /// public int mAlarmInNum; /// /// 报警输出个数 /// public int mAlarmOutNum; /// /// 设备软件版本 /// public long mDevSoftVersion; /// /// 硬盘个数 /// public int mDiskNum; /// /// 序列号 /// public string mSerialNumber; /// /// Admin用户名 /// public string mServerAdminName; /// /// Admin密码 /// public string mServerAdminPasswd; /// /// 通道个数 /// public int mServerChannelNumber; /// /// ID /// public int mServerID; /// /// IP /// public string mServerIP; /// /// IP值 /// public int mServerIPvalue; /// /// 多点IP /// public string mServerMultiIP; /// /// 多点端口 /// public int mServerMultiIPvalue; /// /// 名称 /// public string mServerName; /// /// 端口号 /// public int mServerPort; /// /// DVR类型 /// public int mServerType; /// /// 起始通道 /// public int mStartChannel; } #endregion #endregion #region (1)初始化函数 /// /// 手工内存清理,可以被客户直接调用 /// public void Dispose() { // 必须以Dispose(true)方式调用, // 以true告诉Dispose(bool disposing)函数是被客户直接调用的 Dispose(true); } /// /// 析构函数自动生成 Finalize 方法和对基类的 Finalize 方法的调用. /// 默认情况下,一个类是没有析构函数的,也就是说, /// 对象被垃圾回收时不会被调用Finalize方法 /// ~HKWS() { // 为了保持代码的可读性性和可维护性,千万不要在这里写释放非托管资源的代码 // 必须以Dispose(false)方式调用, // 以false告诉Dispose(bool disposing)函数是从垃圾回收器在调用Finalize时调用的 Dispose(false); } /// /// 无法被客户直接调用 /// 如果 disposing 是 true, 那么这个方法是被客户直接调用的,那么托管的,和非托管的资源都可以释放 /// 如果 disposing 是 false, 那么函数是从垃圾回收器在调用Finalize时调用的,此时不应当引用其他托管对象所以,只能释放非托管资源 /// /// true或者false protected virtual void Dispose(bool disposing) { // 那么这个方法是被客户直接调用的,那么托管的,和非托管的资源都可以释放 if (disposing) { // 释放 托管资源 } //释放非托管资源 st = NetSDK.NET_DVR_Cleanup(); ClientInfo = new NetSDK.NET_DVR_CLIENTINFO(); WorkState = new NetSDK.NET_DVR_WORKSTATE(); DvrDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DecoderDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); DecoderDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DecoderInfo = new Server_Info(); DvrDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DvrDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); DvrInfo = new Server_Info(); mp4FileName = new string[9]; jpgName = new string[9]; // 那么这个方法是被客户直接调用的, // 告诉垃圾回收器从Finalization队列中清除自己,从而阻止垃圾回收器调用Finalize方法. if (disposing) GC.SuppressFinalize(this); } /// /// 初始化,包含登录硬盘录像机(DVR)等动作 /// /// 硬盘录像机IP /// 硬盘录像机端口 /// 硬盘录像机用户名 /// 硬盘录像机密码 /// 1成功,0失败 public int Init(string serverIP, int serverPort, string serverAdminName, string serverAdminPasswd) { if (String.IsNullOrEmpty(serverIP)) throw new ArgumentException("serverIP is null or empty.", "serverIP"); if (String.IsNullOrEmpty(serverAdminName)) throw new ArgumentException("serverAdminName is null or empty.", "serverAdminName"); if (String.IsNullOrEmpty(serverAdminPasswd)) throw new ArgumentException("serverAdminPasswd is null or empty.", "serverAdminPasswd"); isOnline = 0; strOut = null; DvrInfo.mServerIP = serverIP; DvrInfo.mServerPort = serverPort; DvrInfo.mServerAdminName = serverAdminName; DvrInfo.mServerAdminPasswd = serverAdminPasswd; st = NetSDK.NET_DVR_Init(); xm = NetSDK.NET_DVR_IsSupport(); st = NetSDK.NET_DVR_SetConnectTime(2000, 1); userID = NetSDK.NET_DVR_Login(DvrInfo.mServerIP, DvrInfo.mServerPort, DvrInfo.mServerAdminName, DvrInfo.mServerAdminPasswd, ref DvrDeviceInfo); DvrInfo.mServerID = userID; DvrInfo.mServerType = DvrDeviceInfo.byDVRType; DvrInfo.mStartChannel = DvrDeviceInfo.byStartChan; DvrInfo.mAlarmInNum = DvrDeviceInfo.byAlarmInPortNum; DvrInfo.mAlarmOutNum = DvrDeviceInfo.byAlarmOutPortNum; DvrInfo.mServerChannelNumber = DvrDeviceInfo.byChanNum; DvrInfo.mDiskNum = DvrDeviceInfo.byDiskNum; // ReSharper disable SuggestUseVarKeywordEvident StringBuilder strTemp = new StringBuilder(200); // ReSharper restore SuggestUseVarKeywordEvident //判断一下登录是否成功, 并输出错误. if (userID < 0) { int nErr = NetSDK.NET_DVR_GetLastError(); switch (nErr) { case NetSDK.NET_DVR_PASSWORD_ERROR: strTemp.AppendFormat("DVR服务器 {0} 用户名密码错误! \r\n", DvrInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; default: strTemp.AppendFormat(" DVR服务器 {0} 由于网络原因或DVR忙, 注册失败! \r\n", DvrInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; } } /* st = NetSDK.NET_DVR_GetDVRConfig(userID, 100, -1, ref DvrDeviceCfg, 200, ref bytesReturned); if (bytesReturned < 1) { strTemp.AppendFormat(" DVR服务器 {0}获取设备参数失败! \r\n", DvrInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; } DvrInfo.mDevSoftVersion = DvrDeviceCfg.dwSoftwareVersion; strOut += " 硬盘录像机软件版本为:" + DvrInfo.mDevSoftVersion + "\r\n"; */ //初始化视频播放和语音句柄 for (int i = 1; i <= 5; i++) { realHandle[i] = -1; } vocieHandle = -1; strOut = "已经初始化SDK,并登陆硬盘录像机" + serverIP + "。\r\n"; return 1; } /// /// 初始化(不登录),不包含登录硬盘录像机(DVR)等动作 /// /// 1成功,0失败 public int Init() { isOnline = 0; strOut = null; st = NetSDK.NET_DVR_Init(); xm = NetSDK.NET_DVR_IsSupport(); strOut = "SDK初始化完成。\r\n"; return 1; } /// /// 登录硬盘录像机(DVR) /// /// 硬盘录像机IP /// 硬盘录像机端口 /// 硬盘录像机用户名 /// 硬盘录像机密码 /// 登录超时时间 /// public int DvrLoginIn(string serverIP, int serverPort, string serverAdminName, string serverAdminPasswd, int loginTimeOut) { if (String.IsNullOrEmpty(serverIP)) throw new ArgumentException("serverIP为null或empty.", "serverIP"); if (String.IsNullOrEmpty(serverAdminName)) throw new ArgumentException("serverAdminName is null or empty.", "serverAdminName"); if (String.IsNullOrEmpty(serverAdminPasswd)) throw new ArgumentException("serverAdminPasswd is null or empty.", "serverAdminPasswd"); isOnline = 0; strOut = null; DvrInfo.mServerIP = serverIP; DvrInfo.mServerPort = serverPort; DvrInfo.mServerAdminName = serverAdminName; DvrInfo.mServerAdminPasswd = serverAdminPasswd; st = NetSDK.NET_DVR_SetConnectTime((uint)loginTimeOut, 1); userID = NetSDK.NET_DVR_Login(DvrInfo.mServerIP, DvrInfo.mServerPort, DvrInfo.mServerAdminName, DvrInfo.mServerAdminPasswd, ref DvrDeviceInfo); DvrInfo.mServerID = userID; DvrInfo.mServerType = DvrDeviceInfo.byDVRType; DvrInfo.mStartChannel = DvrDeviceInfo.byStartChan; DvrInfo.mAlarmInNum = DvrDeviceInfo.byAlarmInPortNum; DvrInfo.mAlarmOutNum = DvrDeviceInfo.byAlarmOutPortNum; DvrInfo.mServerChannelNumber = DvrDeviceInfo.byChanNum; DvrInfo.mDiskNum = DvrDeviceInfo.byDiskNum; // ReSharper disable SuggestUseVarKeywordEvident StringBuilder strTemp = new StringBuilder(200); // ReSharper restore SuggestUseVarKeywordEvident //判断一下登录是否成功, 并输出错误. if (userID < 0) { int nErr = NetSDK.NET_DVR_GetLastError(); switch (nErr) { case NetSDK.NET_DVR_PASSWORD_ERROR: strTemp.AppendFormat("DVR服务器 {0} 用户名密码错误! \r\n", DvrInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; default: strTemp.AppendFormat(" DVR服务器 {0} 由于网络原因或DVR忙, 注册失败! \r\n", DvrInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; } } /* // 不再在登录时获取硬盘录像机设备参数。 st = NetSDK.NET_DVR_GetDVRConfig(userID, 100, -1, ref DvrDeviceCfg, 200, ref bytesReturned); if (bytesReturned < 1) { strTemp.AppendFormat(" DVR服务器 {0}获取设备参数失败! \r\n", DvrInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; } DvrInfo.mDevSoftVersion = DvrDeviceCfg.dwSoftwareVersion; strOut += " 硬盘录像机软件版本为:" + DvrInfo.mDevSoftVersion + "\r\n"; */ //初始化视频播放和语音句柄 for (int i = 1; i <= 5; i++) { realHandle[i] = -1; } vocieHandle = -1; return 1; } /// /// 注销当前Dvr的登录用户,断开Dvr连接 /// /// public int DvrLoginOut() { strOut = ""; st = NetSDK.NET_DVR_Logout(userID); if (!st) { strOut = "从硬盘录像机注销用户" + userID + "失败.\r\n"; return 0; } ClientInfo = new NetSDK.NET_DVR_CLIENTINFO(); WorkState = new NetSDK.NET_DVR_WORKSTATE(); DvrDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DecoderDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); DecoderDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DecoderInfo = new Server_Info(); DvrDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DvrDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); DvrInfo = new Server_Info(); return 1; } /// /// 关闭硬盘录像机,释放SDK资源 /// /// 1成功,0失败 public int Close() { strOut = ""; if (userID > -1) { st = NetSDK.NET_DVR_Logout(userID); } if (!st) { strOut = "从硬盘录像机注销用户" + userID + "失败.\r\n"; return 0; } // st = NetSDK.NET_DVR_Cleanup(); Dispose(); if (!st) { strOut = "释放SDK资源失败.\r\n"; return 0; } strOut = "已关闭并释放硬盘录像机(DVR)相关资源.\r\n"; return 1; } /// /// 获取硬盘录像机工作状态 /// /// 1成功,0失败 public int IsWork() { st = NetSDK.NET_DVR_GetDVRWorkState(userID, ref WorkState); if (!st) { strOut = string.Format("获取硬盘录像机工作状态失败.\r\n"); return 0; } return 1; } /// /// 叠加车号 /// /// 车号 /// 1为叠加,0为取消叠加 /// public int CardNo(string numberPlate, char choice) { if (String.IsNullOrEmpty(numberPlate)) throw new ArgumentException("numberPlate is null or empty.", "numberPlate"); int byRetrun = 0; NetSDK.NET_DVR_SHOWSTRING subString = new NetSDK.NET_DVR_SHOWSTRING(); for (int i = 1; i <= 5; i++) { Thread.Sleep(100); st = NetSDK.NET_DVR_GetDVRConfig(userID, NetSDK.NET_DVR_GET_SHOWSTRING, i, ref subString, Marshal.SizeOf(subString), ref byRetrun); if (!st) { strOut = "获取原有叠加字符信息失败.\r\n"; return 0; } subString.struStringInfo[0].wShowStringTopLeftX = 512; subString.struStringInfo[0].wShowStringTopLeftY = 32; subString.struStringInfo[0].wStringSize = (UInt16)numberPlate.Length; subString.struStringInfo[0].dwShowString = choice; subString.struStringInfo[0].sString = numberPlate; st = NetSDK.NET_DVR_SetDVRConfig(userID, NetSDK.NET_DVR_SET_SHOWSTRING, i, ref subString, Marshal.SizeOf(subString)); if (!st) { strOut = "设定监控画面字符叠加失败.\r\n"; return 0; } } strOut = "监控画面叠加字符处理成功.\r\n"; new NetSDK.NET_DVR_SHOWSTRING(); return 1; } #endregion #region (2)远程手工录像 /// /// 开始硬盘录像机远程手工录像 /// /// 起始的通道号 /// 录像通道的个数 /// 1成功,0失败 public int StartRemoteRec(int start, int cCount) { strOut = ""; xm = IsWork(); // 获取工作状态,刷新工作状态WorkState结构体内的数据. if (xm == 0) { return 0; } for (int i = start; i <= cCount; i++) { if (WorkState.struChanStatic[i - 1].byRecordStatic == 1) { strOut = string.Format("第{0}通道正在录像,开始录像前,需要停止前一个.\r\n", i); return 0; } st = NetSDK.NET_DVR_StartDVRRecord(userID, i, 0); if (!st) { strOut = string.Format("第{0}通道开始录像失败\r\n", i); return 0; } } return 1; } /// /// 结束硬盘录像机远程手工录像 /// /// 起始的通道号 /// 录像通道的个数 /// 1成功,0失败 public int StopRemoteRec(int start, int cCount) { strOut = ""; for (int i = start; i <= cCount; i++) { st = NetSDK.NET_DVR_StopDVRRecord(userID, i); if (!st) { strOut = string.Format("第{0}通道结束录像失败\r\n", i); return 0; } } return 1; } /// /// 由统计范围,来获取每个通道刚刚结束录像的文件名和时间信息, /// 使用结构FileLastRec[1-8]输出文件信息 /// /// 起始通道编号 /// 通道数量 /// 统计范围提前几个小时,应小于24,建议用1 /// public int LastRecInfo(int startChannel, int cCount, int hours) { //ReSharper disable SuggestUseVarKeywordEvident NetSDK.NET_DVR_TIME dvrStartTime = new NetSDK.NET_DVR_TIME(); NetSDK.NET_DVR_TIME dvrEndTime = new NetSDK.NET_DVR_TIME(); // ReSharper restore SuggestUseVarKeywordEvident DateTime curTime = DateTime.Now; // 初始化结束时间,为当前系统时间 dvrEndTime.dwYear = (UInt32) curTime.Year; dvrEndTime.dwMonth = (UInt32) curTime.Month; dvrEndTime.dwDay = (UInt32) curTime.Day; dvrEndTime.dwHour = (UInt32) curTime.Hour; dvrEndTime.dwMinute = (UInt32) curTime.Minute; dvrEndTime.dwSecond = 59; //初始化开始时间,为当前系统时间的前一小时 dvrStartTime.dwYear = (UInt32) curTime.Year; dvrStartTime.dwMonth = (UInt32) curTime.Month; if (curTime.Hour < hours) { dvrStartTime.dwDay = (UInt32) (curTime.Day - 1); dvrStartTime.dwHour = (UInt32) (curTime.Hour + 24 - hours); dvrStartTime.dwMinute = (UInt32) curTime.Minute; dvrStartTime.dwSecond = 0; } else { dvrStartTime.dwDay = (UInt32) curTime.Day; dvrStartTime.dwHour = (UInt32) (curTime.Hour - hours); dvrStartTime.dwMinute = (UInt32) curTime.Minute; dvrStartTime.dwSecond = 0; } for (int i = startChannel; i <= cCount; i++) { int fCount = 1; int con = 1; findHandle = NetSDK.NET_DVR_FindFile(userID, i, 6, ref dvrStartTime, ref dvrEndTime); while (con == 1) { lt = NetSDK.NET_DVR_FindNextFile(findHandle, ref FindData[fCount]); switch (lt) { case NetSDK.NET_DVR_FILE_SUCCESS: fCount++; break; case NetSDK.NET_DVR_FILE_NOFIND: strOut = "无新文件。\r\n"; return 0; case NetSDK.NET_DVR_ISFINDING: Thread.Sleep(500); break; case NetSDK.NET_DVR_NOMOREFILE: FileLastRec.startTime[i] = FindData[fCount - 1].struStartTime; // 获取到每个通道的最后一个录像的录像开始时间 FileLastRec.stopTime[i] = FindData[fCount - 1].struStopTime; // 获取到每个通道的最后一个录像的录像停止时间 // 获取到刚刚录像的新文件文件名 ASCIIEncoding encoding = new ASCIIEncoding(); FileLastRec.NewFileName[i] = encoding.GetString(FindData[fCount - 1].fileName); FileLastRec.NewFileName[i] = FileLastRec.NewFileName[i].Replace("\0", ""); FileLastRec.fileSize[i] = FindData[fCount - 1].dwFileSize; // 获取到刚刚录像的新文件大小 FileLastRec.info[i] = true; // 置本数组该序号为有文件信息 con = 0; break; case NetSDK.NET_DVR_FILE_EXCEPTION: break; default: break; } } } return 1; } #endregion #region (3)截图JPEG格式 /// /// JPEG格式截图,使用jpgName[1-8]返回保存后的jpg文件名 /// /// 起始通道编号 /// 截图的通道数量 /// 目录名,如"C:\\" /// 1成功,0失败 public int CaptureJPG(int startChanel, int cCount, string DirName) { if (String.IsNullOrEmpty(DirName)) throw new ArgumentException("DirName is null or empty.", "DirName"); // ReSharper disable RedundantAssignment StringBuilder strFileName = new StringBuilder(); StringBuilder Pfilename = new StringBuilder(); // ReSharper restore RedundantAssignment // ReSharper disable SuggestUseVarKeywordEvident StringBuilder strTime = new StringBuilder(); // ReSharper restore SuggestUseVarKeywordEvident // ReSharper restore SuggestUseVarKeywordEvident JpegPara.wPicQuality = 2; JpegPara.wPicSize = 0; strTime.AppendFormat("{0:yyyyMMdd}_{0:HHmmss}", DateTime.Now); Pfilename = new StringBuilder(); //Pfilename.Append(DirName); P_fileName = strFileName.AppendFormat("{0}_{1}_0", DvrInfo.mServerIP, strTime).ToString(); for (int i = startChanel; i <= cCount; i++) { strFileName = new StringBuilder(); strFileName.Append(DirName); strFileName.AppendFormat("{0}_{1}_0{2}.jpg", DvrInfo.mServerIP, strTime, i); st = NetSDK.NET_DVR_CaptureJPEGPicture(userID, i, ref JpegPara, strFileName); if (!st) { strOut = strFileName + "JPEG格式截图保存出错.\r\n"; return 0; } jpgName[i] = strFileName.ToString(); strOut = strFileName + "JPEG格式截图保存成功.\r\n"; } return 1; } public string P_fileName = ""; #endregion #region (4)后台录像到本地,不显示视频, /// /// 开始Mp4录像捕获,以mp4FileName[1-8]输出文件名 /// _StatusSaveMp4这个变量显示录像状态,1为正在录像,0为未录像状态 /// /// 起始通道编号 /// 通道数量 /// 要保存Mp4录像的目录,如"C:\\temp\\" /// 1成功,0失败 public int StartSaveMp4(int startChanel, int cCount, string DirName) { if (String.IsNullOrEmpty(DirName)) throw new ArgumentException("DirName is null or empty.", "DirName"); ClientInfo.linkMode = 0; ClientInfo.playWnd = new IntPtr(); ClientInfo.multiCastIP = "0.0.0.0"; StringBuilder strTime = new StringBuilder(); strTime.AppendFormat("{0:yyyyMMdd}_{0:HHmmss}", DateTime.Now); xm = IsWork(); // 获取工作状态,刷新工作状态WorkState结构体内的数据. if (xm == 0) { return 0; } for (int i = startChanel; i <= cCount; i++) { if (WorkState.struChanStatic[i].dwLinkNum > 5) { strOut = string.Format("第{0}通道的连接数已经有6个,无法继续连接该通道进行操作。\r\n", i); return 0; } ClientInfo.channel = i; realHandle[i] = NetSDK.NET_DVR_RealPlay(userID, ref ClientInfo); //NetSDK.NET_DVR_ClientSetVideoEffect(realHandle[i], 5, 5, 5, 5); //System.Diagnostics.Trace.WriteLine("StartMp4_userID:" + userID); string strFileNames = DirName + DvrInfo.mServerIP + "_" + strTime + "_0" + i + ".mp4"; st = NetSDK.NET_DVR_SaveRealData(realHandle[i], strFileNames); strOut = "开始保存第" + ClientInfo.channel + "路通道视频文件" + strFileNames + "\r\n"; Trace.WriteLine(strOut); Trace.WriteLine("realHandle句柄" + i + "为:" + realHandle[i] + "," + DateTime.Now); mp4FileName[i] = strFileNames; } strOut = "开始保存" + cCount + "路视频到本地计算机" + DirName + ".\r\n"; _StatusSaveMp4 = 1; return 1; } /// /// 开始Mp4录像捕获,以mp4FileName[1-8]输出文件名 /// _StatusSaveMp4这个变量显示录像状态,1为正在录像,0为未录像状态 /// 文件名称由头部+主体+通道号组成,格式为: 9092_081107165439_03.mp4 /// /// 起始通道编号 /// 通道数量 /// 要保存Mp4录像的目录,如"C:\\temp\\" /// 文件名头部,与文件名间用_连接 /// 文件名称主体 /// 1成功,0失败 public int StartSaveMp4(int startChanel, int cCount, string DirName, string FileNameBegin, string FileName) { if (String.IsNullOrEmpty(DirName)) throw new ArgumentException("DirName is null or empty.", "DirName"); if (String.IsNullOrEmpty(FileNameBegin)) throw new ArgumentException("FileNameBegin is null or empty.", "FileNameBegin"); if (String.IsNullOrEmpty(FileName)) throw new ArgumentException("FileName is null or empty.", "FileName"); ClientInfo.linkMode = 0; ClientInfo.playWnd = new IntPtr(); ClientInfo.multiCastIP = "0.0.0.0"; StringBuilder strTime = new StringBuilder(); strTime.AppendFormat("{0:yyyyMMdd}_{0:HHmmss}", DateTime.Now); xm = IsWork(); // 获取工作状态,刷新工作状态WorkState结构体内的数据. if (xm == 0) { return 0; } for (int i = startChanel; i <= cCount; i++) { if (WorkState.struChanStatic[i].dwLinkNum > 5) { strOut = string.Format("第{0}通道的连接数已经有6个,无法继续连接该通道进行操作。\r\n", i); return 0; } ClientInfo.channel = i; realHandle[i] = NetSDK.NET_DVR_RealPlay(userID, ref ClientInfo); //NetSDK.NET_DVR_ClientSetVideoEffect(realHandle[i], 5, 5, 5, 5); //System.Diagnostics.Trace.WriteLine("StartMp4_userID:" + userID); //string strFileNames = DirName + DvrInfo.mServerIP + "_" + strTime + "_0" + i + ".mp4"; string strFileNames = DirName + FileNameBegin + "_" + FileName + "_0" + i + ".mp4"; st = NetSDK.NET_DVR_SaveRealData(realHandle[i], strFileNames); strOut = "开始保存第" + ClientInfo.channel + "路通道视频文件" + strFileNames + "\r\n"; Trace.WriteLine(strOut); Trace.WriteLine("realHandle句柄" + i + "为:" + realHandle[i] + "," + DateTime.Now); mp4FileName[i] = strFileNames; } strOut = "开始保存" + cCount + "路视频到本地计算机" + DirName + ".\r\n"; _StatusSaveMp4 = 1; return 1; } /// /// 结束Mp4录像保存.以mp4FileName[1-8]输出文件名 /// _StatusSaveMp4这个变量显示录像状态,1为正在录像,0为未录像状态 /// /// 起始通道 /// 通道数量 /// 1成功,0失败 public int StopSaveMp4(int startChanel, int cCount) { for (int i = startChanel; i <= cCount; i++) { st = NetSDK.NET_DVR_StopSaveRealData(realHandle[i]); st = NetSDK.NET_DVR_StopRealPlay(realHandle[i]); Trace.WriteLine("结束保存第" + ClientInfo.channel + "路通道视频文件"); strOut = "已保存第" + ClientInfo.channel + "路通道视频文件\r\n"; } strOut = "已保存" + cCount + "路视频到本地计算机\r\n"; _StatusSaveMp4 = 0; return 1; } #endregion #region (5)在线播放,远程监控 /// /// 保留一个封送回调函数fRealDataCallBack指针的委托对象引用 /// 保证委托不被回收 /// private NetSDK.fRealDataCallBack rdc; /// /// 委托函数,替代C++的回调函数NetSDK.fRealDataCallBack /// /// 就是realHandle:NET_DVR_RealPlay()的返回值 /// /// #define NET_DVR_SYSHEAD 1 // 系统头数据 /// #define NET_DVR_STREAMDATA 2 // 流数据 /// /// 存放数据的缓冲区指针, /// 当用户开始接收数据时,第一个包是40个字节的文件头,用户可以用这个头来打开播放器,以后回调的就是压缩的码流。 /// /// 缓冲区的大小 /// 就是登录到硬盘录像机的userID public void RealDataCallBack(int handle, int dataType, byte[] buf, int bufSize, int dwUser) { //ASCIIEncoding encoding = new ASCIIEncoding(); //System.Diagnostics.Trace.WriteLine(" realHandle:" + handle + "" + // ", dataType:" + dataType + // ", vBuffer:" + encoding.GetString(buf) + // ", bufSize:" + bufSize + // ", userID:" + userID); } /// /// 在线播放(多路,建议5路,不能大于8路) /// /// 需要播放在线视频的路数 /// 需要播放在线视频的窗口的句柄 /// 1成功,0失败 public int StartOnline(int cCount, IntPtr[] playWnd) { if (playWnd == null || playWnd.Length == 0u) throw new ArgumentException("playWnd is null or empty.", "playWnd"); if (isOnline == 1) { strOut = string.Format("本机已经开始远程监控视频,无法叠加.请先停止远程监控.\r\n"); return 0; } strOut = null; rdc = RealDataCallBack; // RealDataCallBack赋为回调函数fRealDataCallBack的参数 xm = IsWork(); // 获取工作状态,刷新工作状态WorkState结构体内的数据. if (xm == 0) { return 0; } for (int i = 1; i <= cCount; i++) { if (WorkState.struChanStatic[i].dwLinkNum > 5) { strOut = string.Format("第{0}通道的连接数已经有6个,无法继续连接该通道进行操作。\r\n", i); return 0; } Trace.WriteLine("第" + i + "通道在线监测前有" + WorkState.struChanStatic[i].dwLinkNum + "用户连接。"); ClientInfo.channel = i; ClientInfo.linkMode = 0; ClientInfo.playWnd = playWnd[i]; ClientInfo.multiCastIP = "0.0.0.0"; // 通过ClientInfo中的对应信息,获取realHandle句柄,同一个硬盘录像机每个通道返回的句柄都不一样 realHandle[i] = NetSDK.NET_DVR_RealPlay(userID, ref ClientInfo); if (realHandle[i] == -1) { int err = NetSDK.NET_DVR_GetLastError(); strOut = "访问IP:" + DvrInfo.mServerIP + ",通道" + i + "连接启动失败 err = " + err + "\r\n"; } else { st = NetSDK.NET_DVR_SetPlayerBufNumber(realHandle[i], buffNum); st = NetSDK.NET_DVR_ThrowBFrame(realHandle[i], throwNum); NetSDK.NET_DVR_SetRealDataCallBack(realHandle[i], rdc, userID); if (!st) { int err = NetSDK.NET_DVR_GetLastError(); strOut = string.Format("访问IP:{0},通道{1}获取码流失败 err = {2}\r\n", DvrInfo.mServerIP, i, err); } } } isOnline = 1; return 1; } /// /// 停止在线播放(多路,建议5路,不能大于8路) /// /// 1成功,0失败 public int StopOnline(int cCount) { strOut = null; for (int i = 1; i <= cCount; i++) { if (realHandle[i] < 0) { strOut = "没有视频在线播放,无法停止\r\n"; return 0; } NetSDK.NET_DVR_StopRealPlay(realHandle[i]); } GC.KeepAlive(rdc); isOnline = 0; strOut = "已停止视频在线播放\r\n"; return 1; } #endregion #region (6)回放本地视频 /// /// 开始回放视频(多路,建议5路,不能大于8路) /// /// 需要回放的路数 /// 需要回放的文件[1-9]的string字符数组 /// 需要播放回放视频的窗口的句柄,[1-9]的IntPtr数组 /// public void StartPlay(int cCount, string[] strName, IntPtr[] playWnd) { if (strName == null || strName.Length == 0u) throw new ArgumentException("strName is null or empty.", "strName"); if (playWnd == null || playWnd.Length == 0u) throw new ArgumentException("playWnd is null or empty.", "playWnd"); for (int nPort = 1; nPort <= cCount; nPort++) { st = NetSDK.PlayM4_OpenFile(nPort, strName[nPort]); } for (int nPort = 1; nPort <= cCount; nPort++) { st = NetSDK.PlayM4_Play(nPort, playWnd[nPort]); } strOut = cCount + "路视频回放成功.\r\n"; } /// /// 减速播放,共支持4级变速 /// 变速在多路同时回放时,会出现不一致 /// /// 路数 /// public int SlowPlay(int cCount) { for (int nPort = 1; nPort <= cCount; nPort++) { st = NetSDK.PlayM4_Slow(nPort); } strOut = "已减速视频回放.\r\n"; return 1; } /// /// 加速播放,共支持4级变速 /// 变速在多路同时回放时,会出现不一致 /// /// 路数 /// public int FastPlay(int cCount) { for (int nPort = 1; nPort <= cCount; nPort++) { st = NetSDK.PlayM4_Fast(nPort); } strOut = "已加速视频回放.\r\n"; return 1; } /// /// 停止回放(多路,建议5路,不能大于8路) /// /// public int StopPlay(int cCount) { for (int nPort = 1; nPort <= cCount; nPort++) { st = NetSDK.PlayM4_Stop(nPort); } for (int nPort = 1; nPort <= cCount; nPort++) { st = NetSDK.PlayM4_CloseFile(nPort); } strOut = "已停止视频回放.\r\n"; return 1; } /// /// 暂停多路回放 /// /// /// public int PausePlay(int cCount) { for (int nPort = 1; nPort <= cCount; nPort++) { st = NetSDK.PlayM4_Pause(nPort, true); } strOut = "已暂停视频回放.\r\n"; return 1; } /// /// 恢复多路回放 /// /// /// public int ResurePlay(int cCount) { for (int nPort = 1; nPort <= cCount; nPort++) { st = NetSDK.PlayM4_Pause(nPort, false); } strOut = "已恢复视频回放.\r\n"; return 1; } #endregion #region (7)语音对讲 /// /// 保留一个封送回调函数fVoiceDataCallBack指针的委托对象引用 /// 保证委托不被回收 /// private static NetSDK.fVoiceDataCallBack vdc; /// /// fVoiceDataCallBack委托要用的函数参数 /// /// NET_DVR_StartVoiceCom ()的返回值 /// 原为存放数据的缓冲区指针,现为缓冲区 /// 缓冲区的大小 /// 数据类型 /// 0- 客户端采集的音频数据 /// 1- 客户端收到设备端的音频数据 /// 用户数据,就是NET_DVR_StartVoiceCom中用户数据 public void VoiceDataCallBack(int voiceComHandle, byte[] recvDataBuffer, int bufSize, byte audioFlag, int dwUser) { //ASCIIEncoding encoding = new ASCIIEncoding(); //System.Diagnostics.Trace.WriteLine(" voiceComHandle:" + voiceComHandle + "" + // ", audioFlag:" + audioFlag + // ", recvDataBuffer:" + encoding.GetString(recvDataBuffer) + // ", bufSize:" + bufSize + // ", dwUser:" + dwUser); } /// /// 开启语音对讲 /// /// 对讲音量 /// 1成功,0失败 public int StartVoiceTalk(uint clientVolume) { vdc = VoiceDataCallBack; // VoiceDataCallBack赋为回调函数fVoiceDataCallBack的参数 vocieHandle = NetSDK.NET_DVR_StartVoiceCom(userID, vdc, 88); if (vocieHandle >= 0) { strOut = "语音对讲开启成功\r\n"; } NetSDK.NET_DVR_SetVoiceComClientVolume(vocieHandle, clientVolume); return 1; } /// /// 停止语音对讲 /// /// 1成功,0失败 public int StopVocieTalk() { if (vocieHandle >= 0) { if (NetSDK.NET_DVR_StopVoiceCom(vocieHandle)) { vocieHandle = -1; strOut = "已关闭语音对讲!\r\n"; } else { strOut = "关闭语音对讲失败!\r\n"; return 0; } } else { strOut = "还未开始语音对讲,无法关闭.\r\n"; } GC.KeepAlive(vdc); GC.Collect(); return 1; } /// /// 开始语音对讲(DirectX) /// /// public int StartChat() { return 1; } /// /// 停止语音对讲(DirectX) /// /// public int StopChat() { return 1; } #endregion #region (8)电视墙控制 /// /// 切换dvr监控视频到指定电视墙等离子电视上 /// 使用前提:电视墙的9个解码器端口,用户名,密码都一样 /// /// 来源DVR的IP /// 来源DVR的端口 /// 来源DVR的用户名 /// 来源DVR的密码 /// 等离子电视编号 /// 统一的解码器端口 /// 统一的解码器用户名 /// 统一的解码器密码 /// /// 因为1解码器对应2等离子电视,本函数封装了解码器,解码器不直接可见 /// 所以解码器端口,用户名,密码都要统一成一样. /// /// 1成功,0失败 public int TVWallSwitch(string dvrIp, int dvrPort, string dvrUserName, string dvrPass, string tvNo, int decoderPort, string decoderUserName, string decoderUserPass) { if (String.IsNullOrEmpty(dvrIp)) throw new ArgumentException("dvrIp is null or empty.", "dvrIp"); if (String.IsNullOrEmpty(dvrUserName)) throw new ArgumentException("dvrUserName is null or empty.", "dvrUserName"); if (String.IsNullOrEmpty(dvrPass)) throw new ArgumentException("dvrPass is null or empty.", "dvrPass"); if (String.IsNullOrEmpty(tvNo)) throw new ArgumentException("tvNo is null or empty.", "tvNo"); if (String.IsNullOrEmpty(decoderUserName)) throw new ArgumentException("decoderUserName is null or empty.", "decoderUserName"); if (String.IsNullOrEmpty(decoderUserPass)) throw new ArgumentException("decoderUserPass is null or empty.", "decoderUserPass"); string eDec = ""; int part = 0; switch (int.Parse(tvNo)) { case 1: eDec = "172.20.194.151"; part = 1; break; case 2: eDec = "172.20.194.151"; part = 2; break; case 3: eDec = "172.20.194.152"; part = 1; break; case 4: eDec = "172.20.194.152"; part = 2; break; case 5: eDec = "172.20.194.153"; part = 1; break; case 6: eDec = "172.20.194.153"; part = 2; break; case 7: eDec = "172.20.194.154"; part = 1; break; case 8: eDec = "172.20.194.154"; part = 2; break; case 9: eDec = "172.20.194.155"; part = 1; break; case 10: eDec = "172.20.194.155"; part = 2; break; case 11: eDec = "172.20.194.156"; part = 1; break; case 12: eDec = "172.20.194.156"; part = 2; break; case 13: eDec = "172.20.194.157"; part = 1; break; case 14: eDec = "172.20.194.157"; part = 2; break; case 15: eDec = "172.20.194.158"; part = 1; break; case 16: eDec = "172.20.194.158"; part = 2; break; case 17: eDec = "172.20.194.159"; part = 1; break; case 18: eDec = "172.20.194.159"; part = 2; break; } // 初始化电视墙制定解码器,登录进解码器 xm = TVWallLoginIn(eDec, decoderPort, decoderUserName, decoderUserPass); // 更改eDec 解码器(通过4合1画面整合,物理连接了int.Parse(textBoxTVNo.Text)号等离子电视)的动态解码信息 // part=1时,使该解码器解码当前已经登录的硬盘录像机的第1-4路监控画面, // 对应解码器的第0-3动态解码 // part=2时,使该解码器解码当前已经登录的硬盘录像机的第5-8路监控画面, // 对应解码器的第4-7动态解码 // 本函数适合远程调度计量端使用.设定完后,登出解码器。 xm = TvWallSet(dvrIp, dvrPort, dvrUserName, dvrPass, part, int.Parse(tvNo)); if (xm != 1) { strOut += "切换出错。未能将DVR " + dvrIp + " 监控画面切换到" + tvNo + "号等离子电视上。\r\n"; return 0; } xm = TVWallLoginOut(); strOut += "已将DVR " + dvrIp + " 监控画面切换到 " + tvNo + " 号等离子电视上。\r\n"; return 1; } /// /// 电视墙对应的解码器初始化 /// /// 解码器IP地址 /// 解码器端口 /// 解码器用户名 /// 解码器密码 /// public int TVWallLoginIn(string decoderIP, int decoderPort, string decoderUserName, string decoderUserPass) { if (String.IsNullOrEmpty(decoderIP)) throw new ArgumentException("decoderIP is null or empty.", "decoderIP"); if (String.IsNullOrEmpty(decoderUserName)) throw new ArgumentException("decoderUserName is null or empty.", "decoderUserName"); if (String.IsNullOrEmpty(decoderUserPass)) throw new ArgumentException("decoderUserPass is null or empty.", "decoderUserPass"); isOnline = 0; strOut = null; DecoderInfo.mServerIP = decoderIP; DecoderInfo.mServerPort = decoderPort; DecoderInfo.mServerAdminName = decoderUserName; DecoderInfo.mServerAdminPasswd = decoderUserPass; st = NetSDK.NET_DVR_SetConnectTime(2000, 1); decoderUserID = NetSDK.NET_DVR_Login(DecoderInfo.mServerIP, DecoderInfo.mServerPort, DecoderInfo.mServerAdminName, DecoderInfo.mServerAdminPasswd, ref DecoderDeviceInfo); DecoderInfo.mServerID = decoderUserID; DecoderInfo.mServerType = DecoderDeviceInfo.byDVRType; DecoderInfo.mStartChannel = DecoderDeviceInfo.byStartChan; DecoderInfo.mAlarmInNum = DecoderDeviceInfo.byAlarmInPortNum; DecoderInfo.mAlarmOutNum = DecoderDeviceInfo.byAlarmOutPortNum; DecoderInfo.mServerChannelNumber = DecoderDeviceInfo.byChanNum; DecoderInfo.mDiskNum = DecoderDeviceInfo.byDiskNum; // ReSharper disable SuggestUseVarKeywordEvident StringBuilder strTemp = new StringBuilder(200); // ReSharper restore SuggestUseVarKeywordEvident //判断一下登录是否成功, 并输出错误. if (decoderUserID < 0) { int nErr = NetSDK.NET_DVR_GetLastError(); switch (nErr) { case NetSDK.NET_DVR_PASSWORD_ERROR: strTemp.AppendFormat("解码器 {0} 用户名密码错误! \r\n", DecoderInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; default: strTemp.AppendFormat(" 解码器 {0} 由于网络原因或解码器忙, 注册失败! \r\n", DecoderInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; } } /* st = NetSDK.NET_DVR_GetDVRConfig(decoderUserID, 100, -1, ref DecoderDeviceCfg, 200, ref bytesReturned); if (bytesReturned < 1) { strTemp.AppendFormat(" 解码器 {0}获取设备参数失败! \r\n", DecoderInfo.mServerIP); Trace.WriteLine(strTemp); strOut = strTemp.ToString(); return 0; } DecoderInfo.mDevSoftVersion = DvrDeviceCfg.dwSoftwareVersion; strOut += " 解码器软件版本为:" + DecoderInfo.mDevSoftVersion + "\r\n"; */ return 1; } /// /// 注销当前Dec的登录用户,断开Dec连接 /// /// public int TVWallLoginOut() { strOut = ""; st = NetSDK.NET_DVR_Logout(decoderUserID); if (!st) { strOut = "从解码器录像机注销用户" + decoderUserID + "失败.\r\n"; return 0; } ClientInfo = new NetSDK.NET_DVR_CLIENTINFO(); WorkState = new NetSDK.NET_DVR_WORKSTATE(); DvrDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DecoderDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); DecoderDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DecoderInfo = new Server_Info(); DvrDeviceCfg = new NetSDK.NET_DVR_DEVICECFG(); DvrDeviceInfo = new NetSDK.NET_DVR_DEVICEINFO(); DvrInfo = new Server_Info(); return 1; } /// /// 设置指定个等离子电视,显示指定解码器的0-3路或者4-7路 /// 解码器4路会通过画面分割器整合成1路到单个等离子电视上 /// 需要传入DVR的IP,端口,用户名,密码等参数 /// /// dvr的ip /// dvr的端口 /// dvr的用户名 /// dvr的密码 /// 1为显示指定解码器的0-3路,2为4-7路 /// 等离子电视编号 /// public int TvWallSet(string dvrIP, int dvrPort, string dvrUserName, string dvrUserPass, int selectPart, int tvNo) { if (String.IsNullOrEmpty(dvrIP)) throw new ArgumentException("dvrIP is null or empty.", "dvrIP"); if (String.IsNullOrEmpty(dvrUserName)) throw new ArgumentException("dvrUserName is null or empty.", "dvrUserName"); if (String.IsNullOrEmpty(dvrUserPass)) throw new ArgumentException("dvrUserPass is null or empty.", "dvrUserPass"); selectPart--; mdd.struDecChanInfo.sDVRIP = dvrIP; mdd.struDecChanInfo.sUserName = dvrUserName; mdd.struDecChanInfo.sPassword = dvrUserPass; mdd.struDecChanInfo.wDVRPort = (ushort)dvrPort; mdd.struDecChanInfo.byTransProtocol = 0; mdd.struDecChanInfo.byTransMode = 0; mdd.dwSize = Marshal.SizeOf(mdd); for (int i = 0; i < 4; i++) { mdd.struDecChanInfo.byChannel = (byte)(i + 1); st = NetSDK.NET_DVR_MatrixStartDynamic(decoderUserID, i + selectPart * 4, ref mdd); if (!st) { strOut = string.Format("{0}站点第{1}路监控通道压秤,切换监控至{2}号电视墙失败.\r\n", mdd.struDecChanInfo.sDVRIP, mdd.struDecChanInfo.byChannel, tvNo); return 0; } } return 1; } /// /// 设置指定个等离子电视,显示指定解码器的0-3路或者4-7路 /// 解码器4路会通过画面分割器整合成1路到单个等离子电视上 /// 参数使用,当前已登录硬盘录像机 /// /// 1为显示指定解码器的0-3路,2为4-7路 /// 等离子电视编号 /// public int TvWallSet(int selectPart, int tvNo) { selectPart--; if (DvrInfo.mServerIP == null) { strOut = "还未登录到硬盘录像机,请先登录。或者使用另一个重载函数。\r\n"; return 0; } mdd.struDecChanInfo.byRes = ""; mdd.struDecChanInfo.sDVRIP = DvrInfo.mServerIP; mdd.struDecChanInfo.sUserName = DvrInfo.mServerAdminName; mdd.struDecChanInfo.sPassword = DvrInfo.mServerAdminPasswd; mdd.struDecChanInfo.wDVRPort = (ushort)