简体   繁体   English

c ++ libusb:如何将数据发送到设备?

[英]c++ libusb: how to send data to device?

Good day. 美好的一天。
I'm progrmming interface for "MGX Analog Signal Generator N5181B" with libusb. 我正在用libusb编写“MGX模拟信号发生器N5181B”的接口。
For a starting I have to init device, so next step is send data. 对于一个启动我必须初始化设备,所以下一步是发送数据。 For example I wanna change frequency that will displayed in generator. 例如,我想改变将在发电机中显示的频率。
My code: 我的代码:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <libusb.h>


using namespace std;
int main(int argc, char *argv[]) {

    if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) != 1){
        cout<<"This platform hasn't support for hotplug callback notification"<<endl;
        return 0;
    }

    libusb_device_handle* dev_handle;
    libusb_device* dev;
    libusb_context* ctx = NULL;
    int r;

    r = libusb_init(&ctx);
    if (r < 0) {
        cout<<"Init error "<<r<<endl;
    }
    libusb_set_debug(ctx, 3);

    dev_handle = libusb_open_device_with_vid_pid(ctx, 1266, 45940);
    unsigned char data[15] = {':', 'F', 'R', 'E', 'Q', ' ', '5', '0', '0', '0', '0', ' ', 'K', 'H', 'Z'};
    int actual_length;
    r = libusb_bulk_transfer(dev_handle, LIBUSB_ENDPOINT_IN, data, sizeof(data), &actual_length, 0);

    libusb_exit(ctx);

    return 0;
}

Compile this get me follow: 编译这个让我跟随:
libusb: error [submit_bulk_transfer] submiturb failed error -1 errno=2 libusb:错误[submit_bulk_transfer]提交失败错误-1 errno = 2

Please, What I do wrong? 拜托,我做错了什么?
Thx for your attention. 谢谢你的关注。

use libusb_detach_kernel_driver and libusb_claim_interface if you want to make bulk transfer on current device. 如果要在当前设备上进行批量传输,请使用libusb_detach_kernel_driver和libusb_claim_interface。 After transaction release_inerface and close device 事务release_inerface和关闭设备之后

You forgot putting your device endpoint in bulk transfer it will be something like: 您忘记将设备端点置于批量传输中,它将类似于:

libusb_bulk_transfer(dev_handle, (0x81 | LIBUSB_ENDPOINT_IN), response, 24, &actual, 0);

note : 0x81 is endpoint of my device 注意:0x81是我设备的端点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM