Author Topic: Using multiple FT232H devices on one computer  (Read 126 times)

0 Members and 1 Guest are viewing this topic.

Offline ifloridoTopic starter

  • Newbie
  • Posts: 1
  • Country: es
Using multiple FT232H devices on one computer
« on: Yesterday at 01:27:26 pm »
Hello, does anyone know how to independently control two FT232H devices, it is configured for UART communication with an A7640 and the other in i2c mode for some sensors.

Independently they work fine, but when I connect the two USBs they give me an error since it is not able to differentiate the addresses

When I check the connected devices I get this response.

Dispositivos FTDI encontrados:
Dispositivo 1: (UsbDeviceDescriptor(vid=1027, pid=24596, bus=8, address=26, sn=None, index=None, description='Single RS232-HS'), 1)
Dispositivo 2: (UsbDeviceDescriptor(vid=1027, pid=24596, bus=8, address=24, sn=None, index=None, description='Single RS232-HS'), 1)


The one that works in UART I use it by serial with this address

Code: [Select]
ftdi_url = 'ftdi://ftdi:232h/1'
The one who works in I2c

Code: [Select]
i2c.configure('ftdi://ftdi:232h/1', frequency=100000)  # 100 kHz

The only difference when identifying the devices is the address

address=26
address=24

How could I modify the addresses so that they work independently? something like

ftdi://ftdi:232h/1:24 or ftdi://ftdi:232h/1:26

right now it shows me

Error configuring I²C on ftdi://ftdi:232h/1: 2 USB devices match URL 'ftdi://ftdi:232h/1'

Thanks.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2426
  • Country: us
Re: Using multiple FT232H devices on one computer
« Reply #1 on: Yesterday at 06:09:49 pm »
You can supply a serial number or address in the URI.  See https://eblot.github.io/pyftdi/urlscheme.html
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2646
  • Country: us
Re: Using multiple FT232H devices on one computer
« Reply #2 on: Yesterday at 09:26:57 pm »
If you want to see a little code for opening by serial number:
I use the FTDI D2XX drivers and library version 2.12.28  for Win7.

If the serial number to FTDIopen() is left empty, it will open the first device.  Good if only one device and you don't care about its serial number.

Header:
Code: [Select]
#pragma once

#include <windows.h>
#include <string.h>
#include "ftd2xx.h"

class hdwr
{
public:
   DWORD ftNumDevs;
   char device_1[32];
   char device_2[32];
   char device_3[32];
   char device_4[32];
   char device_5[32];
   char device_6[32];
   char device_7[32];
   char device_8[32];

   bool hdwrConnected;

   hdwr();
   ~hdwr();

   int FTDIdevices(void);
   int FTDIopen(char *serial);
   int FTDIclose(void);

private:
   FT_HANDLE ftHandle;
};

Class:
Code: [Select]
#include "hdwr.h"

//======================================================================
hdwr::hdwr()
{
   ftHandle=0;

   ftNumDevs=0;
   device_1[0]=0;
   device_2[0]=0;
   device_3[0]=0;
   device_4[0]=0;
   device_5[0]=0;
   device_6[0]=0;
   device_7[0]=0;
   device_8[0]=0;

   hdwrConnected=false;
}

hdwr::~hdwr()
{
}

//======================================================================
int hdwr::FTDIdevices(void)
{
   FT_STATUS ftStatus;
   char *BufPtrs[10];

   // Initialize the array of pointers
   BufPtrs[0] = device_1;
   BufPtrs[1] = device_2;
   BufPtrs[2] = device_3;
   BufPtrs[3] = device_4;
   BufPtrs[4] = device_5;
   BufPtrs[5] = device_6;
   BufPtrs[6] = device_7;
   BufPtrs[7] = device_8;
   BufPtrs[8] = NULL;

   ftStatus = FT_ListDevices(BufPtrs, &ftNumDevs, FT_LIST_ALL|FT_OPEN_BY_SERIAL_NUMBER);

   return (int)ftStatus;
}

//======================================================================
int hdwr::FTDIopen(char *serial)
{
   FT_STATUS ftStatus;

   if ( strlen(serial) > 0 ) {
      ftStatus = FT_OpenEx(serial, FT_OPEN_BY_SERIAL_NUMBER, &ftHandle);
   } else {
      ftStatus = FT_Open(0, &ftHandle);               // Device indices are 0 based
   }
   if (ftStatus != FT_OK) return (int)ftStatus;

   ftStatus = FT_ResetDevice(ftHandle);
   if (ftStatus != FT_OK) return (int)ftStatus;

   ftStatus = FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX);
   if (ftStatus != FT_OK) return (int)ftStatus;

   ftStatus = FT_SetLatencyTimer(ftHandle,16);        // 1-255 (16ms default)
   if (ftStatus != FT_OK) return (int)ftStatus;

   ftStatus = FT_SetUSBParameters(ftHandle,256,256);  // USB In/Out transfer sizes (4096 default)
   if (ftStatus != FT_OK) return (int)ftStatus;

   ftStatus = FT_SetTimeouts(ftHandle,1000,1000);     // R/W timeout (1sec default)
   if (ftStatus != FT_OK) return (int)ftStatus;

   hdwrConnected = true;
   return (int)ftStatus;
}

//======================================================================
int hdwr::FTDIclose(void)
{
   hdwrConnected = false;
   return (int)FT_Close(ftHandle);
}
« Last Edit: Today at 07:00:31 am by MarkF »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf