c - libusb 如何理解开始阅读?
问题描述
在主机端,如何理解设备想要使用 libusb-1.0 发送数据?我的意思是除了轮询或设置时间间隔之外的方法。有什么方法可以根据信号、中断等来获取它吗?
解决方案
您可以使用“glibusb”,在此处阅读文档: https ://github.com/apmasell/vapis
"glibusb.h" 包含 "libusb"* 的所有功能,这个库是由https://github.com/apmasell的大胡子家伙制作的
依赖项:
- 焦2.0
- libusb-1.0
代码:
[CCode (cheader_filename = "glibusb.h")]
namespace LibUSB {
/**
* Create a source so that a context can be monitored using {@link GLib.MainLoop}.
*
* Once created, call {@link GLib.Source.attach} to attach it to a context.
*/
[CCode (cname = "glibusb_create_gsource")]
public GLib.Source create_source (owned Context ctx);
/**
* Initiate a USB control transfer on a device.
*
* @param dev the device to perform the transfer
* @param timeout return if no data has been provided after the specified number of milliseconds
* @param buffer the data to transfer
* @param actual_length the number of bytes transferred
*/
[CCode (cname = "glibusb_control_transfer")]
public async TransferStatus control_transfer (DeviceHandle dev, uint timeout, uint8[] buffer, out int actual_length);
/**
* Initiate a USB interrupt transfer on a device.
*
* @param dev the device to perform the transfer
* @param endpoint the target on the device
* @param timeout return if no data has been provided after the specified number of milliseconds
* @param buffer the data to transfer
* @param actual_length the number of bytes transferred
*/
[CCode (cname = "glibusb_interrupt_transfer")]
public async TransferStatus interrupt_transfer (DeviceHandle dev, uint8 endpoint, uint timeout, uint8[] buffer, out int actual_length);
/**
* Initiate a USB bulk transfer on a device.
*
* @param dev the device to perform the transfer
* @param endpoint the target on the device
* @param timeout return if no data has been provided after the specified number of milliseconds
* @param buffer the data to transfer
* @param actual_length the number of bytes transferred
*/
[CCode (cname = "glibusb_bulk_transfer")]
public async TransferStatus bulk_transfer (DeviceHandle dev, uint8 endpoint, uint timeout, uint8[] buffer, out int actual_length);
}
推荐阅读
- c# - 在 C# 中使用 DDD 实现域服务
- xamarin - 如何在长文本的情况下向上或向下滚动时在用户点击编辑器的位置显示光标?
- tensorflow - TFHub 和模型花园有什么区别?
- python - 更改给定字符串中的大写字母 - Python
- gitlab - Gitlab CI/CD:使用多个when条件
- python - 从另一个数据框列中过滤数据框的单列
- c# - 如何从 MVC 中的不同控制器调用重载的动作方法
- css - 嵌入的 Google 表格中的字体错误
- html - 将 id 绑定到 Angular mat-checkbox
- python - 完成后立即显示每个任务结果的异步结果