C ++ libusb:如何将数据发送到设备
c++ libusb: how to send data to device?
美好的一天。
我正在使用libusb为"MGX模拟信号发生器N5181B"编程接口。
首先,我必须初始化设备,因此下一步是发送数据。例如,我想更改将在生成器中显示的频率。
我的代码:
#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;
}
编译这个让我遵循:
libusb:错误 [submit_bulk_transfer] submiturb 失败错误 -1 errno=2
拜托,我做错了什么?
感谢您的关注。
如果要在当前设备上进行批量传输,请使用libusb_detach_kernel_driver和libusb_claim_interface。交易后release_inerface并关闭设备
您忘记将设备终端节点批量传输它将是这样的:
libusb_bulk_transfer(dev_handle, (0x81 | LIBUSB_ENDPOINT_IN), response, 24, &actual, 0);
注意:0x81是我的设备的端点
相关文章:
- 防止主数据类型C++的隐式转换
- 用于访问容器<T>数据成员的正确 API
- 嵌套在类中时无法设置成员数据
- 使用流处理接收到的数据
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在cuda线程之间共享大量常量数据
- C++将文本文件中的数据读取到结构数组中
- 如何在C++中序列化结构数据
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 通过套接字[TCP]传输数据 如何在C / C ++中打包多个整数并使用send() recv()传输数据
- 在c代码之间共享数据的最佳方式
- 链表,反向函数,数据结构
- 数据成员SFINAE的C++17测试:gcc vs clang
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- 如何对点云数据进行排序
- 在 c++ libusb 中将数据写入得利捷 PM9500 扫描仪的正确格式
- C++使用 libusb 发送数据(使用 RS 232)
- C ++ libusb:如何将数据发送到设备
- 使用libusb从USB闪存驱动器读取数据