You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Delphi环境下多FT232设备ChipID读取重复问题求助

Troubleshooting Duplicate FT232 ChipIDs in Delphi

Hey Lukas, let's dig into why all your connected FT232 devices are returning the same ChipID. I’ve worked with FTDI’s Delphi libraries before, so here are the most common culprits and fixes to try:

1. You’re reusing the same device handle across all reads

This is the most likely issue. If you only open the first device once and then repeatedly read its ChipID (instead of opening each device individually), you’ll get the same value every time.

Check your code to make sure you’re:

  • Enumerating all connected devices first
  • Opening each device with a unique handle
  • Closing the handle after reading the ChipID to free up resources

2. Your device enumeration isn’t capturing all FT232s

If FT_ListDevices isn’t properly returning all connected devices, you’ll only ever interact with the first one. Verify:

  • You’re using the correct flags (like FT_LIST_ALL) when calling FT_ListDevices
  • Your buffer size is large enough to hold info for all connected devices
  • You’re checking the return value of FT_ListDevices to confirm it succeeded

3. Global variables in FTChipID.pas are overriding values

Take a look at the FTChipID.pas file you downloaded. If it uses global variables for the device handle or ChipID storage, each subsequent read will overwrite the previous value. For example, if there’s a global FT_HANDLE variable, opening a new device will replace it, but if you don’t read the ChipID immediately before opening the next device, you might be reusing old data.

Fix Example: Enumerate and Read Each Device Properly

Here’s a cleaned-up code snippet that should correctly read ChipIDs for all connected FT232s:

uses
  FTChipID;

procedure TForm1.ButtonReadChipIDsClick(Sender: TObject);
var
  DeviceCount: DWORD;
  DeviceIndex: Integer;
  DeviceHandle: FT_HANDLE;
  CurrentChipID: DWORD;
  FTStatus: FT_STATUS;
begin
  Memo1.Lines.Clear;

  // Step 1: Get total number of connected FT232 devices
  FTStatus := FT_ListDevices(@DeviceCount, nil, FT_LIST_NUMBER_ONLY);
  if FTStatus <> FT_OK then
  begin
    Memo1.Lines.Add('Error: Could not retrieve device count (Status: ' + IntToStr(Integer(FTStatus)) + ')');
    Exit;
  end;

  if DeviceCount = 0 then
  begin
    Memo1.Lines.Add('No FT232 devices detected');
    Exit;
  end;

  // Step 2: Iterate through each device and read its ChipID
  for DeviceIndex := 0 to DeviceCount - 1 do
  begin
    // Open the device using its index
    FTStatus := FT_Open(DeviceIndex, DeviceHandle);
    if FTStatus <> FT_OK then
    begin
      Memo1.Lines.Add(Format('Device %d: Failed to open (Status: %d)', [DeviceIndex, Integer(FTStatus)]));
      Continue;
    end;

    // Read the ChipID
    FTStatus := FT_GetChipID(DeviceHandle, CurrentChipID);
    if FTStatus = FT_OK then
    begin
      Memo1.Lines.Add(Format('Device %d ChipID: %08X', [DeviceIndex, CurrentChipID]));
    end
    else
    begin
      Memo1.Lines.Add(Format('Device %d: Failed to read ChipID (Status: %d)', [DeviceIndex, Integer(FTStatus)]));
    end;

    // Always close the device handle when done
    FT_Close(DeviceHandle);
  end;
end;

Additional Checks

  • Update FTDI Drivers: Outdated drivers can cause multi-device enumeration bugs. Make sure you’re running the latest version from FTDI’s official site.
  • Use Serial Numbers for Opening: If your devices have unique serial numbers, you can enumerate those first and open devices by serial number instead of index. This avoids issues if devices are plugged in/out in different orders.
  • Check for Resource Leaks: If you forget to close handles, you might run into conflicts when trying to open subsequent devices.

内容的提问来源于stack exchange,提问作者Lukas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:28:54