繁华落叶草 2016-11-03 09:19 采纳率: 0%
浏览 5927

关于海康威视调用实例的一些问题

在进行海康威视SDK中给的实例时,总是出现图片中的错误,求大神解答。<br> 图片说明
源代码如下:
#include
#include
#include "Windows.h"
#include "HCNetSDK.h"
using namespace std;

int saveRecordFile(int userId,char * srcfile,char * destfile)
{
int bRes = 1;
int hPlayback = 0;
//按文件名下载录像
if( (hPlayback = NET_DVR_GetFileByName(userId, srcfile, destfile)) < 0 )
{
printf( "GetFileByName failed. error[%d]\n", NET_DVR_GetLastError());
bRes= -1;
return bRes;
} //开始下载
if(!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART, NULL,0,NULL,NULL))
{
printf("play back control failed [%d]\n",NET_DVR_GetLastError());
bRes=-1;
return bRes;
}

int nPos = 0; 
for(nPos = 0;  nPos < 100&&nPos>=0; nPos = NET_DVR_GetDownloadPos(hPlayback)) 
{         printf("Be downloading...%d %%\n", nPos);   //下载进度 
    Sleep(5000);  //millisecond 
} 
printf("have got %d\n", nPos);     //停止下载 
if(!NET_DVR_StopGetFile(hPlayback)) 
{ 
    printf("failed to stop get file [%d]\n",NET_DVR_GetLastError()); 
    bRes = -1; 
    return bRes; 
} 
printf("%s\n",srcfile); 

if(nPos<0||nPos>100) 
{ 
    printf("download err [%d]\n",NET_DVR_GetLastError()); 
    bRes=-1; 
    return bRes; 
} 
else 
{ 
    return 0; 
} 

}
void main() {

//--------------------------------------- // 初始化
NET_DVR_Init(); //设置连接时间与重连时间
NET_DVR_SetConnectTime(2000, 1);
NET_DVR_SetReconnect(10000, true);

//--------------------------------------- // 注册设备
LONG lUserID;
NET_DVR_DEVICEINFO_V30 struDeviceInfo;
lUserID = NET_DVR_Login_V30("192.0.0.64", 8000, "admin", "12345", &struDeviceInfo);
if (lUserID < 0)
{
printf("Login error, %d\n", NET_DVR_GetLastError());
NET_DVR_Cleanup();

return;
}

NET_DVR_FILECOND_V40 struFileCond={0};
struFileCond.dwFileType = 0xFF; struFileCond.lChannel = 1; //通道号
struFileCond.dwIsLocked = 0xFF;
struFileCond.dwUseCardNo = 0; struFileCond.struStartTime.dwYear = 2011; //开始时间
struFileCond.struStartTime.dwMonth = 3;
struFileCond.struStartTime.dwDay = 1;
struFileCond.struStartTime.dwHour = 10;
struFileCond.struStartTime.dwMinute = 6;
struFileCond.struStartTime.dwSecond =50; struFileCond.struStopTime.dwYear = 2011; //结束时间
struFileCond.struStopTime.dwMonth = 3;
struFileCond.struStopTime.dwDay = 1;
struFileCond.struStopTime.dwHour = 11;
struFileCond.struStopTime.dwMinute = 7;
struFileCond.struStopTime.dwSecond = 0;

//--------------------------------------- //查找录像文件
int lFindHandle = NET_DVR_FindFile_V40(lUserID, &struFileCond);
if(lFindHandle < 0)
{
printf("find file fail,last error %d\n",NET_DVR_GetLastError());
return;
}
NET_DVR_FINDDATA_V40 struFileData;
while(true)
{ //逐个获取查找到的文件信息
int result = NET_DVR_FindNextFile_V40(lFindHandle, &struFileData);
if(result == NET_DVR_ISFINDING)
{
continue;
} else if(result == NET_DVR_FILE_SUCCESS) //获取文件信息成功
{
char strFileName[256] = {0};
sprintf(strFileName, "./%s", struFileData.sFileName);
saveRecordFile(lUserID, struFileData.sFileName, strFileName);
break;
} else if(result == NET_DVR_FILE_NOFIND || result == NET_DVR_NOMOREFILE) //未查找到文件或者查找结束
{

break;
}
else
{
printf("find file fail for illegal get file state");
break;
}
}

//停止查找
if(lFindHandle >= 0)
{
NET_DVR_FindClose_V30(lFindHandle);
}

//注销用户
NET_DVR_Logout(lUserID); //释放 SDK 资源
NET_DVR_Cleanup();
return;
}

  • 写回答

3条回答 默认 最新

  • devmiao 2016-11-03 14:20
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能