hkcam_reset.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // +build ignore
  2. #include "./include/MvCameraControl.h"
  3. #include "../swapi/include_swapiLib.h"
  4. const char *MODULE_NAME = "HKCamReset";
  5. int main(int argc,char *argv[])
  6. {
  7. HANDLE hCam = NULL; MV_CC_DEVICE_INFO_LIST devList = { 0 };
  8. MV_CC_DEVICE_INFO *pDevInfo; int ret;
  9. // 1, 查找相机
  10. ret = MV_CC_Initialize();
  11. if(MV_OK != ret)
  12. {
  13. sw_log_error("[%s] 相机SDK初始化失败, errCode=0x%x!!", MODULE_NAME, ret);
  14. goto end_p;
  15. }
  16. ret = MV_CC_EnumDevices(MV_USB_DEVICE, &devList); // 目前只枚举USB连接的相机
  17. if(MV_OK != ret)
  18. {
  19. sw_log_error("[%s] USB口枚举相机失败, errCode=0x%x!!", MODULE_NAME, ret);
  20. goto end_p;
  21. }
  22. if(devList.nDeviceNum != 1)
  23. {
  24. ret = -1;
  25. sw_log_error("[%s] USB口相机数量错误, deviceNum=%u!!", MODULE_NAME, devList.nDeviceNum);
  26. goto end_p;
  27. }
  28. pDevInfo = devList.pDeviceInfo[0];
  29. if(!pDevInfo)
  30. {
  31. ret = -2;
  32. sw_log_error("[%s] unexpected internal error, unable to obtain detailed information about the industrial camera!!", MODULE_NAME);
  33. goto end_p;
  34. }
  35. // 2, 打开相机
  36. ret = MV_CC_CreateHandleWithoutLog(&hCam, pDevInfo);
  37. if(MV_OK == ret) ret = MV_CC_OpenDevice(hCam, MV_ACCESS_Exclusive, 0);
  38. if(MV_OK != ret)
  39. {
  40. sw_log_error("[%s] USB口相机打开失败, errCode=0x%x!!", MODULE_NAME, ret);
  41. goto end_p;
  42. }
  43. // 3, 重置相机
  44. ret = MV_CC_SetCommandValue(hCam, "DeviceReset");
  45. if(MV_OK != ret)
  46. {
  47. sw_log_error("[%s] USB口相机重置失败, errCode=0x%x!!", MODULE_NAME, ret);
  48. goto end_p;
  49. }
  50. // 4, 关闭相机
  51. end_p:
  52. if(hCam)
  53. {
  54. MV_CC_CloseDevice(hCam);
  55. MV_CC_DestroyHandle(hCam);
  56. }
  57. MV_CC_Finalize();
  58. return ret;
  59. }