intel realsense usb枚举,读写数据解析

0)intel realsense枚举设备的调用堆栈如下:
   rs_create_context--->
   rs_context* rs_context_base::acquire_instance(),首先调用query_devices 获取设备信息;调用的是windows的Media Foundation 枚举音频,视频捕获设备。


   通过获取vid,判断是不是intel的设备,通过获取pid判断是intel的哪种类型的设备,sr300,f200等等,然后调用相应的函数获取rs_device
          switch(get_product_id(*device))
        {
            case R200_PRODUCT_ID:  rs_dev = rsimpl::make_r200_device(device); break;
            case LR200_PRODUCT_ID: rs_dev = rsimpl::make_lr200_device(device); break;
            case ZR300_PRODUCT_ID: rs_dev = rsimpl::make_zr300_device(device); break;
            case F200_PRODUCT_ID:  rs_dev = rsimpl::make_f200_device(device); break;
            case SR300_PRODUCT_ID: rs_dev = rsimpl::make_sr300_device(device); break;        //sr300设备
        }

      

        将设备加入到设备列表:
        if (rs_dev && is_compatible(rs_dev))
        {
            devices.push_back(rs_dev);
        }


   其中:    std::shared_ptr<rs_device> make_sr300_device(std::shared_ptr<uvc::device> device)实现的功能如下:
     0.1)ivcam::claim_ivcam_interface(*device);----》claim_interface---》open_win_usb

     0.2)  auto calib = sr300::read_sr300_calibration(*device, mutex); //读取标定的SR300的数据
  



1)windows下枚举设备的代码在uvc-wmf.cpp 的open_win_usb函数如下:
   void open_win_usb(int vid, int pid, std::string unique_id, const guid & interface_guid, int interface_number)
参数说明:
    vid,pid:供应商ID(VID)和产品识别码(PID);
    unique_id:
    interface_guid:接口的GUID
    interface_number:接口号

    枚举过程:
    1.1)首先调用SetupDiGetClassDevs函数,通过interface_guid枚举device_info;
    1.2)然后通过device_info和interface_guid, 枚举所有的设备接口;
    1.3)Check if this is our device
       通过比较vid,pid,unique_id,interface_number,判断是否是我们的设备;
    1.4)通过DevicePath创建文件句柄;(DevicePath = 0x00000193760cadf4 L"\\\\?\\usb#vid_8086&pid_0aa5&mi_04#7&6d10b2e&0&0004#{175695cd-30d9-4f87-8be3-5a8270f49a31}")
    *file_handle = CreateFile(detail_data->DevicePath, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, nullptr);
                    if (*file_handle == INVALID_HANDLE_VALUE) throw std::runtime_error("CreateFile(...) failed");
    1.5)The WinUsb_Initialize function creates a WinUSB handle for the device specified by a file handle.
        WinUsb_Initialize
 WinUsb_Initialize call queries the underlying USB stack for various descriptors and allocates enough memory to store the retrieved descriptor data.
        WinUsb_Initialize first retrieves the device descriptor and then gets the associated configuration descriptor.
        From the configuration descriptor, the call derives the associated interface descriptors and stores them in an array.
        The interfaces in the array are identified by zero-based indexes. An index value of 0 indicates the first interface (the default interface),
        a value of 1 indicates the second associated interface, and so on.
        WinUsb_Initialize parses the default interface descriptor for the endpoint descriptors and caches information such as the associated pipes or state specific data.
        The handle received in the InterfaceHandle parameter is a pointer to the memory block allocated for the first interface in the array.



    1.6)打开设备后,进行读写,windows下读写的代码都在uvc_wmf.cpp里面,linux下的读写代码在uvc-libuvc.cpp 和uvc-v4L2.cpp里面。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值