mobile CCTV,mobile surveillance,police body worn cameras
标题:
关于对BVUsb.exe这个进程增加调用之后的释放命令
[打印本页]
author:
bftd
time:
2019-4-16 21:24
标题:
关于对BVUsb.exe这个进程增加调用之后的释放命令
对于在采集站程序中多线程调用接口文件后造成BVUsb.exe这个进程堆积在内存中,造成记录仪无法识别的问题,更改后的接口文件不能使用。
调用的底层库的代码如下:
DWORD MC_KernelWork::ThreadWork()
{
if(RESULT_FLAG_S_OK != BV_ZFY_Init())
{
LOG_ERROR("BV_ZFY_Init fail");
return false;
}
while(1)
{
int tCount = -1;
pDeviceArray tDeviceList;
int tLevel = 0;
char* const tPassword = "123456";
if(RESULT_FLAG_S_OK != BV_ZFY_devices(&tCount, &tDeviceList))
{
LOG_ERROR("BV_ZFY_devices fail");
Sleep(3000);
continue;
}
for(int i=0; i<tCount; i++)
{
char* tDeviceName = tDeviceList[i];
LOG_INFO("设备: %s 被发现", tDeviceName);
unsigned short tRet = 0;
int tIndex = 0;
if(false == BV_ZFY_Connect(tDeviceName, &tRet, &tIndex))
{
LOG_ERROR("BV_ZFY_Connect fail, device: %s, ret: %d", tDeviceName, tRet);
continue;
}
LOG_INFO("设备: %s 连接成功", tDeviceName);
if(RESULT_FLAG_S_OK != BV_ZFY_Login_By_Index(tIndex, &tLevel, tPassword))
{
LOG_ERROR("BV_ZFY_Login_By_Index fail, device: %s", tDeviceName);
BV_ZFY_Disconnect(tIndex);
continue;
}
LOG_INFO("设备: %s 登录成功", tDeviceName);
if(RESULT_FLAG_S_OK != BV_SyncDevTime(tIndex, tPassword, &tRet))
{
LOG_ERROR("BV_SyncDevTime fail, device: %s, ret: %d", tDeviceName, tRet);
BV_ZFY_Disconnect(tIndex);
continue;
}
LOG_INFO("设备: %s 校时成功", tDeviceName);
if(RESULT_FLAG_S_OK != BV_SetMSDC(tIndex, tPassword, &tRet))
{
LOG_ERROR("BV_ZFY_SetDevTime_by_Index fail, device: %s, ret: %d", tDeviceName, tRet);
BV_ZFY_Disconnect(tIndex);
continue;
}
LOG_INFO("设备: %s 转磁盘模式成功", tDeviceName);
BV_ZFY_Disconnect(tIndex);
}
Sleep(3000);
}
return true;
}
author:
admin
time:
2019-4-16 22:26
好的,研发在看了。
author:
Mitarai
time:
2019-4-17 10:04
你好,这边按照同样的方式,使用最新的libBVUsb.dll针对设备做些操作,运行结果如下:
看到并没有出现连接失败的情况,BVUsb.exe进程不会被累积。另外,在进入U盘调用成功后并且设备进入了U盘模式,再断开设备连接,设备退出U盘需要一个过程,
在设备还没有退出U盘之前调用进入U盘的接口,会偶尔出现失败。我这边实现的代码如下:
#include <stdio.h>
#include <Windows.h>
#include <process.h>
#include "BVUsb.h"
#ifdef _DEBUG
#pragma comment(lib, "..\\..\\lib\\Debug\\libBVUsb.lib")
#else
#pragma comment(lib, "..\\..\\lib\\Release\\libBVUsb.lib")
#endif // _DEBUG
static HANDLE g_hThread = NULL;
static BOOL g_bRun = FALSE;
static unsigned __stdcall Thread_Proc(void* param);
int main(int argc, char** argv)
{
g_bRun = TRUE;
g_hThread = (HANDLE)_beginthreadex(nullptr, NULL, Thread_Proc, NULL, 0, NULL);
if (g_hThread == NULL) return 0;
while (g_bRun)
{
Sleep(20);
}
g_bRun = FALSE;
WaitForSingleObject(g_hThread, INFINITE);
if (g_hThread) {
CloseHandle(g_hThread);
g_hThread = NULL;
}
system("pause");
return 0;
}
unsigned __stdcall Thread_Proc(void* param)
{
if (RESULT_FLAG_S_OK != BV_ZFY_Init())
{
printf("BV_ZFY_Init 失败\b");
return 0;
}
int iDeviceCount = 0;
pDeviceArray deviceList;
char* szPassword = "123456";
while (g_bRun)
{
int iDeviceCount = MAX_DEVICE_COUNTS;
if (RESULT_FLAG_S_OK != BV_ZFY_devices(&iDeviceCount, &deviceList))
{
printf("BV_ZFY_devices 失败\n");
Sleep(3000);
continue;
}
// int iDeviceIndex = 0;
char szDeviceName[MAX_DEVICE_NAME_LENGTH] = { 0 };
for (int iDeviceIndex = 0; iDeviceIndex < iDeviceCount; iDeviceIndex++)
{
strncpy_s(szDeviceName, deviceList[iDeviceIndex], _TRUNCATE);
printf("================================================\n");
printf("设备 {%s} 被发现\n", szDeviceName);
unsigned short iRet = 0;
int iDeviceHandle = 0;
int iLevel = 0;
if (RESULT_FLAG_S_OK != BV_ZFY_Connect(szDeviceName, &iRet, &iDeviceHandle))
{
printf("设备 {%s} 连接失败\n", szDeviceName);
continue;
}
printf("设备 {%s} 连接成功\n", szDeviceName);
if (RESULT_FLAG_S_OK != BV_ZFY_Login_By_Index(iDeviceHandle, &iLevel, szPassword))
{
printf("设备 {%s} 登录接口调用失败\n", szDeviceName);
BV_ZFY_Disconnect(iDeviceHandle);
continue;
}
printf("设备: {%s} 登录成功\n", szDeviceName);
if (RESULT_FLAG_S_OK != BV_SyncDevTime(iDeviceHandle, szPassword, &iRet))
{
printf("BV_SyncDevTime fail, device: %s, ret: %d\n", szDeviceName, iRet);
BV_ZFY_Disconnect(iDeviceHandle);
continue;
}
printf("设备: {%s} 校时成功\n", szDeviceName);
#if 1
if (RESULT_FLAG_S_OK != BV_SetMSDC(iDeviceHandle, szPassword, &iRet))
{
printf("BV_SetMSDC fail, device: %s, ret: %d\n", szDeviceName, iRet);
BV_ZFY_Disconnect(iDeviceHandle);
continue;
}
printf("设备: {%s} 转磁盘模式成功\n", szDeviceName);
#endif
BV_ZFY_Disconnect(iDeviceHandle);
printf("================================================\n");
}
Sleep(2000);
}
return 0;
}
和您的代码基本类似。还望贵公司再次测试确认。
author:
bftd
time:
2019-4-17 19:24
我们再次测试后发现还是有问题,这个新的接口文件只是偶尔可以使用,不能稳定工作
author:
Mitarai
time:
2019-4-18 10:46
bftd post on2019-4-17 19:24
我们再次测试后发现还是有问题,这个新的接口文件只是偶尔可以使用,不能稳定工作
你好,可以发一下你们的代码过来吗?我这边测试没有出现你们这样的情况
author:
bftd
time:
2019-4-19 17:59
你好,代码就是第一楼,这个应该没有太大区别。麻烦你用BFTD.EXE那个小工具再测试一下。个人感觉还是和运行环境有关。
欢迎光临 mobile CCTV,mobile surveillance,police body worn cameras (http://bbs.besovideo.com:8067/)
Powered by Discuz! X3.2