hkcam_reset.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // +build ignore
  2. #include "./include/MvCameraControl.h"
  3. #include "../swapi/include_swapiLib.h"
  4. const char *MODULE_NAME = "HKCamReset";
  5. static const char *manufacturer = "Hikrobot"; // 制造厂商
  6. int main(int argc,char *argv[])
  7. {
  8. HANDLE hCam = NULL; MV_CC_DEVICE_INFO_LIST devList = { 0 };
  9. MV_CC_DEVICE_INFO *pDevInfo; int ret, index = 0; char name[MAX_LINE_CHARS];
  10. // 1, 查找相机
  11. ret = MV_CC_Initialize();
  12. if(MV_OK != ret)
  13. {
  14. sw_log_error("[%s] 相机SDK初始化失败, errCode=0x%x!!", MODULE_NAME, ret);
  15. goto end_p;
  16. }
  17. ret = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &devList); // 目前只枚举G口和U口相机
  18. if(MV_OK != ret)
  19. {
  20. sw_log_error("[%s] 枚举相机,执行错误, errCode=0x%x!!", MODULE_NAME, ret);
  21. goto end_p;
  22. }
  23. if(devList.nDeviceNum < 1)
  24. {
  25. ret = -1;
  26. sw_log_error("[%s] 没有相机,数量=%u!!", MODULE_NAME, devList.nDeviceNum);
  27. goto end_p;
  28. }
  29. findp:
  30. if(index < devList.nDeviceNum) pDevInfo = devList.pDeviceInfo[index++];
  31. else goto end_p;
  32. if(!pDevInfo)
  33. {
  34. ret = -2;
  35. sw_log_error("[%s] unexpected internal error, unable to obtain detailed information about the industrial camera!!", MODULE_NAME);
  36. goto end_p;
  37. }
  38. name[0] = '\0'; if(0) ;
  39. else if(pDevInfo && pDevInfo->nTLayerType == MV_USB_DEVICE /*U口相机*/) strcpy(name, (const char *)pDevInfo->SpecialInfo.stUsb3VInfo.chManufacturerName);
  40. else if(pDevInfo && pDevInfo->nTLayerType == MV_GIGE_DEVICE/*G口相机*/) strcpy(name, (const char *)pDevInfo->SpecialInfo.stGigEInfo.chManufacturerName);
  41. if(xstrcasecmp(name, manufacturer) != 0) goto findp;
  42. // 2, 打开相机
  43. ret = MV_CC_CreateHandleWithoutLog(&hCam, pDevInfo);
  44. if(MV_OK == ret) ret = MV_CC_OpenDevice(hCam, MV_ACCESS_Exclusive, 0);
  45. if(MV_OK != ret)
  46. {
  47. sw_log_error("[%s] 打开相机时发生错误, errCode=0x%x!!", MODULE_NAME, ret);
  48. goto end_p;
  49. }
  50. // 3, 重置相机
  51. ret = MV_CC_SetCommandValue(hCam, "DeviceReset");
  52. if(MV_OK != ret)
  53. {
  54. sw_log_error("[%s] 重置相机时发生错误, errCode=0x%x!!", MODULE_NAME, ret);
  55. goto end_p;
  56. }
  57. if(index < devList.nDeviceNum) goto findp;
  58. // 4, 关闭相机
  59. end_p:
  60. if(hCam)
  61. {
  62. MV_CC_CloseDevice(hCam);
  63. MV_CC_DestroyHandle(hCam);
  64. }
  65. MV_CC_Finalize();
  66. return ret;
  67. }