FT4222设备信息在Windows下正确,在Linux下不正确?

时间:2016-09-28 20:51:07

标签: c++ ftdi

我正在尝试使用libft4222与FT4222芯片进行通信。当我运行FTDI提供的以下示例代码时,我会在Windows和Linux平台之间收到不同的响应。

示例代码:

FT_STATUS ftStatus;
FT_DEVICE_LIST_INFO_NODE *devInfo;
DWORD numDevs;
// create the device information list
ftStatus = FT_CreateDeviceInfoList(&numDevs);
if (ftStatus == FT_OK) {
    printf("Number of devices is %d\n",numDevs);
}
if (numDevs > 0) {
    // allocate storage for list based on numDevs
    devInfo =
    (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);
    // get the device information list
    ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs);
    if (ftStatus == FT_OK) {
        for (int i = 0; i < numDevs; i++) {
            printf("Dev %d:\n",i);
            printf(" Flags=0x%x\n",devInfo[i].Flags);
            printf(" Type=0x%x\n",devInfo[i].Type);
            printf(" ID=0x%x\n",devInfo[i].ID);
            printf(" LocId=0x%x\n",devInfo[i].LocId);
            printf(" SerialNumber=%s\n",devInfo[i].SerialNumber);
            printf(" Description=%s\n",devInfo[i].Description);
            printf(" ftHandle=0x%x\n",devInfo[i].ftHandle);
        }
    }
}

在Windows上,我收到以下输出,看起来是正确的:

Dev 0:
Flags= 0x2, (CLOSE-HS)
Type= 0xa
ID= 0x403601c
LocId= 0x1131
SerialNumber= A
Description= FT4222 A
ftHandle= 0x0
Dev 1:
Flags= 0x0, (CLOSE-FS)
Type= 0xa
ID= 0x403601c
LocId= 0x1132
SerialNumber= B
Description= FT4222 B
ftHandle= 0x0

在Linux(x64 Ubuntu,运行i386版本的libft4222和我的测试应用程序)上,我收到以下输出,看起来不正确:

Dev 0:
Flags= 0x1, (OPEN-FS)
Type= 0x3
ID= 0x0
LocId= 0x0
SerialNumber=
Description=
ftHandle= 0x0
Dev 1:
Flags= 0x1, (OPEN-FS)
Type= 0x3
ID= 0x0
LocId= 0x0
SerialNumber=
Description=
ftHandle= 0x0

我好奇为什么系统之间存在差异?为什么一个显示为已关闭而另一个显示为开放?

编辑: lsusb -v显示此设备的以下内容:

Bus 001 Device 015: ID 0403:601c Future Technology Devices International, Ltd 
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0403 Future Technology Devices International, Ltd
  idProduct          0x601c 
  bcdDevice           18.00
  iManufacturer           1 
  iProduct                2 
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           55
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              2 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              2 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x04  EP 4 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               0

2 个答案:

答案 0 :(得分:1)

尝试使用Kali i386后,一切正常。我认为这意味着该库与amd64 OS风格不兼容,所以我尝试使用Ubuntu i386。与以前相同的问题 - 设备信息不正确。

发现真正的问题是Kali我在root帐户下登录。使用Ubuntu,root帐户登录不可用。用sudo执行我的测试应用程序后,从FT4222芯片检索到的信息是正确的。

正确的解决方案可能会使用udev规则来修改FT4222设备的权限。

答案 1 :(得分:0)

在debian下,这个udev规则帮助我避免了sudo权利:

 ACTION=="add", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE="0666",  RUN+="/bin/sh -c 'rmmod ftdi_sio && rmmod usbserial'

同样重要的是,您的$ USER是群组拨出的一部分