FTD2XX.dll [Solved!]

For issues with communication ports, protocols, etc.
Volhout
Posts: 15
Joined: Feb 23, 2011 15:28

Not working properly though

Postby Volhout » Mar 03, 2011 9:00

Hi TJF,

Your new header file copiles, and I am getting somewhere (it seems).
Am using Geany (not the portable version yet) and have configured as per your proposal. It works.

Have run into another problem though..... (this is my code so far)

Code: Select all

' test FTDI USB interface

#include "ftd2xx-2.08.02-1_TJF.bi"

Dim FT_Status As UInteger
Dim FT_NumDev As UInteger
Dim MyHandle As FT_HANDLE
Dim Shared DevInfo As _ft_device_list_info_node

Declare Sub PrintInfoList(ByVal DeviceNo As UInteger)


'Get DLL to generate device info list and return no. of devices
FT_Status = FT_CreateDeviceInfoList(@FT_NumDev)
If FT_Status = FT_OK Then
    Print "1 - We found at least one FTDI device"
    If FT_GetDeviceInfoList(@DevInfo,@FT_NumDev) = FT_OK Then
        PrintInfoList(FT_NumDev)
        If FT_Open(0,@MyHandle) = FT_OK Then
            Print "2 - Opened with handle", MyHandle

            'Set update rate for IO pins
            dim w as ushort = &h400
            If FT_SetDivisor(MyHandle, w) = FT_OK then
                Print "3 - Baudrate set to 9600"
            End If

            'Set bitbang mode
            dim b as ubyte = &hff
         If FT_SetBitMode(MyHandle, b, b) = FT_OK then
                Print "4 - BitBang mode set to all out"
         End if
            Print (FT_SetBitMode(MyHandle, b, b))
        End If
    End If
End If

'input a 'to keep output screen open
End


'----------------------------- SUBS --------------------------------

Sub PrintInfoList(ByVal DeviceNo As UInteger)
                Print
                'Print "Dev No- ", DeviceNo
                Print "Flags - ", DevInfo.Flags
                Print "Type - ", DevInfo.Type
                Print "ID - ", DevInfo.ID
                Print "Loc ID - ", DevInfo.LocId
                Print "Ser No- ", DevInfo.SerialNumber
                Print "Descr - ", DevInfo.Description
                Print "Handle - ", DevInfo.ftHandle
                Print
End Sub


When I run this I open the comms with the FTDI chip, and can set the divisor (succes), but cannot set the bitmode (returns "1"). If I reverse the order, I can set the bitmode, but cannot set the divisor. Something strange. Any idea ??

    1 - We found at least one FTDI device

    Flags - 0
    Type - 0
    ID - 67330049
    Loc ID - 65
    Ser No- DPB5A7O3
    Descr - DLP-USB245M
    Handle - 0

    2 - Opened with handle 3744256
    3 - Baudrate set to 9600
    1


Thanks for your help so far.

Volhout
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Mar 03, 2011 13:51

Volhout wrote:Hi TJF,

Your new header file copiles, and I am getting somewhere (it seems).
Am using Geany (not the portable version yet) and have configured as per your proposal. It works.

Fine (the proposal wasn't mine, it's from fxm)!


When I run this I open the comms with the FTDI chip, and can set the divisor (succes), but cannot set the bitmode (returns "1"). If I reverse the order, I can set the bitmode, but cannot set the divisor. Something strange. Any idea ??

Sorry - no idea (the header seems to work properly).

As I said: I neither have the driver binaries on my HD nor do I have the chip in my box. So I cannot test anything. (I just made the header on-the-fly to test my h_2_bi software.)

Hopefuly anybody else can help furthermore.
Scottinmt
Posts: 11
Joined: May 09, 2008 15:49
Location: Montana, USA

Postby Scottinmt » Mar 04, 2011 7:43

but cannot set the bitmode (returns "1"). If I reverse the order, I can set the bitmode, but cannot set the divisor. Something strange. Any idea ??


From FTDI D2XX programmer's guide:

Code: Select all

5.3 FT_SetBitMode
Supported Operating Systems
Linux
Mac OS X (10.4 and later)
Windows (2000 and later)
Windows CE (4.2 and later)

Summary
Enables different chip modes.

Definition
FT_STATUS FT_SetBitmode (FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucMode)
Parameters
ftHandle   Handle of the device.
ucMask    Required value for bit mode mask. This sets up which bits are inputs and outputs. A bit value of 0 sets the corresponding pin to an input, a bit value of 1 sets the corresponding pin to an output.

        In the case of CBUS Bit Bang, the upper nibble of this value     controls which pins are inputs and outputs, while the lower nibble controls which of the outputs are high and low.

ucMode                   Mode value. Can be one of the following:
0x0 = Reset
0x1 = Asynchronous Bit Bang
0x2 = MPSSE (FT4232H, FT2232H and FT2232 devices only)
0x4 = Synchronous Bit Bang (FT4232H, FT2232H, FT232R, FT245R and FT2232 devices only)
0x8 = MCU Host Bus Emulation Mode (FT4232H, FT2232H and FT2232 devices only)
0x10 = Fast Opto-Isolated Serial Mode (FT4232H, FT2232H and          FT2232 devices only)
0x20 = CBUS Bit Bang Mode (FT232R devices only)
0x40 = Single Channel Synchronous 245 FIFO Mode (FT2232H devices only)

Return Value

FT_OK if successful, otherwise the return value is an FT error code.

Remarks

For a description of available bit modes for the FT232R, see the application note "Bit Bang Modes for the FT232R and FT245R".

For a description of available bit modes for the FT2232, see the application note "Bit Mode Functions for
the FT2232".

For a description of Bit Bang Mode for the FT232B and FT245B, see the application note "FT232B/FT245B Bit Bang Mode".

Application notes are available for download from the FTDI website.

Note that to use CBUS Bit Bang for the FT232R, the CBUS must be configured for CBUS Bit Bang in the EEPROM.

Note that to use Single Channel Synchronous 245 FIFO mode for the FT2232H, channel A must be
configured for FT245 FIFO mode in the EEPROM.


Example

FT_HANDLE ftHandle;
FT_STATUS ftStatus;
UCHAR Mask = 0xff;
UCHAR Mode = 1; // Set asynchronous bit-bang mode
ftStatus = FT_Open(0, &ftHandle);
if(ftStatus != FT_OK) {
        // FT_Open failed
        return;
}
ftStatus = FT_SetBitMode(ftHandle, Mask, Mode);
if (ftStatus == FT_OK) {
        // 0xff written to device
}
else {
        // FT_SetBitMode FAILED!
}
FT_Close(ftHandle);



The function needs: FT_STATUS FT_SetBitmode (FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucMode)

Perhaps sending &hff for both parameters is causing your problem :

Code: Select all

            'Set bitbang mode
            dim b as ubyte = &hff
                        If FT_SetBitMode(MyHandle, b, b) = FT_OK then
Volhout
Posts: 15
Joined: Feb 23, 2011 15:28

Memory completely hosed up ?

Postby Volhout » Mar 04, 2011 8:28

Hi Scottinmt and TJF,

I am not sure what is happening here, but it seems like Freebasic is modifying memory. Look at following code snippet:

Code: Select all

' test FTDI USB interface

#include "ftd2xx-2.08.02-1_TJF.bi"

Dim FT_Status As UInteger
Dim FT_NumDev As UInteger
Dim MyHandle As FT_HANDLE
Dim Shared DevInfo As _ft_device_list_info_node

Declare Sub PrintInfoList(ByVal DeviceNo As UInteger)


'Get DLL to generate device info list and return no. of devices
FT_Status = FT_CreateDeviceInfoList(@FT_NumDev)
If FT_Status = FT_OK Then
    Print "1 - We found at least one FTDI device"
    If FT_GetDeviceInfoList(@DevInfo,@FT_NumDev) = FT_OK Then
        PrintInfoList(FT_NumDev)
        If FT_Open(0,@MyHandle) = FT_OK Then
            Print "2 - Opened with handle", hex(MyHandle)

         print "MyHandle ", MyHandle
            'Set update rate for IO pins
            If FT_SetDivisor(MyHandle, &h0400) = FT_OK then
                Print "3 - Baudrate set to 9600"
            End If
         print "MyHandle ", MyHandle
         
            'Set bitbang mode
            dim b as ubyte = &hff
         If FT_SetBitMode(MyHandle, b, 1) = FT_OK then
            Print "4 - BitBang mode set to all out"
         end if
         print "MyHandle ", MyHandle
         
'            Print (FT_SetBitMode(MyHandle, b, b))
        End If
    End If
End If


There are 4 locations where I print the variable "MyHandle". It is (to my knowledge) nowhere modified, but has a different value. See listing:

    1 - We found at least one FTDI device

    Flags - 0
    Type - 0
    ID - 67330049
    Loc ID - 66
    Ser No- DPB5A7O3
    Descr - DLP-USB245M
    Handle - 0

    2 - Opened with handle 392200
    MyHandle 3744256
    3 - Baudrate set to 9600
    MyHandle 4227464
    MyHandle 1245016
    Press any key to continue . . .


Any idea ???
Scottinmt
Posts: 11
Joined: May 09, 2008 15:49
Location: Montana, USA

Postby Scottinmt » Mar 05, 2011 8:47

Probably not, I think you are returning the address of MyHandle instead of its value. TYPE FT_HANDLE AS PVOID (from FTD2XX-2.08.02_TJF.bi) Try @MyHandle.
Volhout
Posts: 15
Joined: Feb 23, 2011 15:28

pointer

Postby Volhout » Mar 08, 2011 8:49

OK, that works.
If I print @MyHandle, I get the same value all the time. But still I can't get the FT245BM to accept the second command.

TJF, could there be a mismatch between the dll you used to derive the bi file from, and the one on my system ?? The version on my PC is 2.08.02.
But in Windows I see that there are more drivers loaded for this device:

ftdibus.sys
ftbusui.dll
ftd2xx.dll -> the one we are using.
FTLang.dll

Could these other ones cause the problem ??
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: pointer

Postby TJF » Mar 08, 2011 10:44

Volhout wrote:TJF, could there be a mismatch between the dll you used to derive the bi file from, and the one on my system ?? The version on my PC is 2.08.02.
But in Windows I see that there are more drivers loaded for this device:

ftdibus.sys
ftbusui.dll
ftd2xx.dll -> the one we are using.
FTLang.dll

Could these other ones cause the problem ??

I got the C header from this file
http://www.ftdichip.com/Drivers/CDM/CDM20802%20WHQL%20Certified.zip
and translated it. It is version 2.08.02, as mentioned in the filename of my header.

Sorry, I don't use windows and I'm not an expert on installing issues (persistent installation problems are one reason why I switched to LINUX). As far as I know it works like:

When you compile your prog with FB the linker uses a file named 'ftd2xx.dll.a' to link against. The compiled binary then uses the 'ftd2xx.dll' file. You have to make sure that the .dll.a file and the .dll file are matching versions.

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest