我正在使用一个带有FTDI芯片(FT4232)的定制板,以便在Linux系统(Fedora24)上通过USB获得四个串行通信。当插入电路板时,它工作得很好,出现了通信端口,我可以通信了。
但是,我还需要读取EEPROM中的一些数据,一旦我使用libftdi1进行通信或其他操作,我所连接的通信端口就会消失。这是lsusb -t的输出
|__ Port 2: Dev 46, If 2, Class=Vendor Specific Class, Driver=ftdi_sio, 480M
|__ Port 2: Dev 46, If 0, Class=Vendor Specific Class, Driver=, 480M
|__ Port 2: Dev 46, If 3, Class=Vendor Specific Class, Driver=ftdi_sio, 480M
|__ Port 2: Dev 46, If 1, Class=Vendor Specific Class, Driver=ftdi_sio, 480M所以我们看到驱动程序已经被分离了。我尝试按照this question中的建议重新附加内核驱动程序,但没有成功。以下是为重现行为而执行的最小代码示例:
#include <stdio.h>
#include <libftdi1/ftdi.h>
#include <libusb-1.0/libusb.h>
int main(int argc, char * argv[])
{
struct ftdi_context ftdic;
libusb_device_handle * dev;
ftdi_init(&ftdic);
ftdi_usb_open(&ftdic, 0x0403, 0x6011);
dev = ftdic.usb_dev;
// Return error -6: LIBUSB_ERROR_BUSY
printf("%d\n", libusb_attach_kernel_driver(dev, 0));
ftdi_usb_close(&ftdic);
// Return error -99: LIBUSB_ERROR_OTHER
printf("%d\n", libusb_attach_kernel_driver(dev, 0));
return 0;
}简而言之:如何在使用libftdi1后重新附加内核驱动程序?我更喜欢c解决方案,但是bash解决方案也不错。
发布于 2021-07-02 00:27:41
使用libftdi之后,可以使用libusb和libusb_attach_kernel_driver函数重新访问原始驱动程序。
#define DEVICE_VID 0x0403
#define DEVICE_PID 0x6015
int libftdireset() {
libusb_context * context = NULL;
libusb_device_handle * dev_handle = NULL;
int rc = 0;
rc = libusb_init( &context);
dev_handle = libusb_open_device_with_vid_pid(context, DEVICE_VID, DEVICE_PID);
/*Check if kenel driver attached*/
if (libusb_kernel_driver_active(dev_handle, 0)) {
rc = libusb_detach_kernel_driver(dev_handle, 0); // detach driver
}
libusb_reset_device(dev_handle);
libusb_attach_kernel_driver(dev_handle, 0);
libusb_close(dev_handle);
libusb_exit(context);
return 0;
}https://stackoverflow.com/questions/45438252
复制相似问题