FTD2XX.dll [Solved!]

For issues with communication ports, protocols, etc.
Oceano
Posts: 43
Joined: Jun 05, 2009 20:37
Contact:

FTD2XX.dll [Solved!]

Postby Oceano » Mar 28, 2010 16:33

Why not work?


Code: Select all

#Inclib "FTD2XX"

Declare Function FT_OPEN Alias "FT_Open" (ByVal As Integer, ByRef As Long) As Long

Dim FtStatus As Integer

Dim FtHandle As Long

FtStatus = FT_OPEN(0, ftHandle)

Print FtStatus

Sleep



I implemented the library "libftd2xx.dll.a" this way:
--------------------------------------------------
pexports ftd2xx.dll > ftd2xx.dll.def

dlltool -k -d ftd2xx.dll.def -l libftd2xx.dll.a
--------------------------------------------------

I copied "libftd2xx.dll.a" in my working folder and inside the folder freebasic libraries.

I think it does not work because it does not recognize the functions of the library. I do not know what I'm doing wrong.

The error says:

('test' is the name file bas)

Build error(s)
C:\Archivos de programa\FreeBASIC\fbc -s console "test.bas"
test.o:fake:(.text+0x37): undefined reference to `FT_Open@8'



What can I do?

More info in C++, but I do not know how to implement it in FreeBasic.:
http://www.codeproject.com/KB/system/ftdi-chip.aspx

Thank you.
Last edited by Oceano on Jun 03, 2010 21:04, edited 1 time in total.
fdrn
Posts: 3
Joined: Jan 18, 2010 10:35
Location: UK

Postby fdrn » Mar 30, 2010 22:15

Hi Oceano,

Here is a short example that toggles the RTS line on an FT232R device -

Code: Select all

' Toggle RTS line on FT232R device

#include "FTDI.bi"
Const MaxDevice = 32
Dim FT_Status As UInteger
Dim FT_DriverVersion As UInteger
Dim FT_LibraryVersion As UInteger
Dim FT_NumDev As UInteger
Dim MyHandle As FT_HANDLE
Dim Shared DevInfo(1 To MaxDevice) As FT_DEVICE_LIST_INFO_NODE

Declare Sub PrintInfoList(ByVal ListTop As UInteger)

' Main code
' Get the D2XX.DLL version number
FT_Status = FT_GetLibraryVersion(@FT_LibraryVersion)
If FT_Status = FT_OK Then
   Print "Library Version - ", Hex(FT_LibraryVersion)
Else
   Print "FT_Error - ",FT_Status
EndIf

' 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 "Number of devices - ", FT_NumDev
   If FT_NumDev > 0 And FT_NumDev < 32 Then
      ' Get device info in DevInfo array
      If FT_GetDeviceInfoList(@DevInfo(1),@FT_NumDev) = FT_OK Then
         PrintInfoList(FT_NumDev)
         If DevInfo(1).DevType = FT_DEVICE_232R Then
            FT_Status = FT_Open(0,@MyHandle)         ' Open first device
            If FT_Status = FT_OK Then
               Print
               Print "Opened with handle", MyHandle
   
               ' Toggle RTS with a period of 1s - exit loop when key is pressed
               Do
                  FT_Status = FT_SetRts(MyHandle)
                  If FT_Status <> FT_OK Then
                     Print "RTS wasn't set"
                     Exit Do
                  EndIf
                  Sleep(500)
                  FT_Status = FT_ClrRts(MyHandle)
                  If FT_Status <> FT_OK Then
                     Print "RTS wasn't cleared"
                     Exit Do
                  EndIf
                  Sleep(500)
               Loop Until InKey$ <>""
               Print "Done"
            Else
               Print "Error code on open - "; FT_Status
            EndIf
         Else
            Print "First device is not FT232R"
         EndIf
      EndIf
   Else
      Print "No devices to open"
   EndIf
Else
   Print "FT_Error - ",FT_Status
EndIf

Sleep

Sub PrintInfoList(ByVal ListTop As UInteger)
   For DeviceNo As Integer = 1 To ListTop
      Print
      Print "Device Number - ", DeviceNo
      Print "Flags - ", DevInfo(DeviceNo).Flags
      Print "Type - ", DevInfo(DeviceNo).DevType
      Print "ID - ", DevInfo(DeviceNo).DevID
      Print "Location ID - ", DevInfo(DeviceNo).LocId
      Print "Serial No. - ", DevInfo(DeviceNo).SerialNumber
      Print "Description - ", DevInfo(DeviceNo).Description
      Print "Handle - ", DevInfo(DeviceNo).ftHandle
   Next
End Sub


It also displays a list of all the FTDI devices connected and expects an FT232R to be the first device.

You'd need the FTDI.bi file and a libftd2xx.dll.a file - if you're sure of the dll.a you've generated try using that one or I could email you a copy of the one I've got.

Put the dll.a file in the Freebasic/lib/win32 folder and the FTDI.bi file can go in your working directory.

Frank
Oceano
Posts: 43
Joined: Jun 05, 2009 20:37
Contact:

Re: FTD2XX.dll

Postby Oceano » Apr 01, 2010 19:55

Thank you very much Frank.
Volhout
Posts: 15
Joined: Feb 23, 2011 15:28

ftdi.bi file

Postby Volhout » Feb 23, 2011 15:38

Hi guys,

I want to add some GPIO to a netbook with only USB. The FT245BM seems a simple solution. Read through some threads, and have been able to generate the dll.a file from the dll, but I am not sure how to create the ftdi.bi file.

This is my first project with Freebasic, so don't asume too much knowledge.

Can someone help me ??

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

Re: ftdi.bi file

Postby TJF » Feb 23, 2011 19:41

Using the forums search-function I found this post

http://www.freebasic.net/forum/viewtopic.php?p=129848#129848

But the FTDI.bi header isn't complete. So I used h_2_bi to generate a full translation of the current (certified) version 2.08.02. But I cannot test it because I have no hardware.

Try this and report

Code: Select all

' This is file ftd2xx-2.08.02_TJF.bi
' (FreeBasic binding for ftd2xx library version 2.08.02)
'
' translated with help of h_2_bi.bas by
' Thomas[ dot ]Freiherr[ at ]gmx[ dot ]net.
'
' Licence:
' (C) 2011 Thomas[ dot ]Freiherr[ at ]gmx[ dot ]net
'
' This library binding is free software; you can redistribute it
' and/or modify it under the terms of the GNU Lesser General Public
' License as published by the Free Software Foundation; either
' version 2 of the License, or (at your option) ANY later version.
'
' This binding is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
' Lesser General Public License for more details, refer to:
' http://www.gnu.org/licenses/lgpl.html
'
'
' Original license text:
'
'/*++

'Copyright © 2001-2010 Future Technology Devices International Limited

'THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED "AS IS"
'AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
'OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
'FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
'SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
'OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION)
'HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
'TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
'EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'FTDI DRIVERS MAY BE USED ONLY IN CONJUNCTION WITH PRODUCTS BASED ON FTDI PARTS.

'FTDI DRIVERS MAY BE DISTRIBUTED IN ANY FORM AS LONG AS LICENSE INFORMATION IS NOT MODIFIED.

'IF A CUSTOM VENDOR ID AND/OR PRODUCT ID OR DESCRIPTION STRING ARE USED, IT IS THE
'RESPONSIBILITY OF THE PRODUCT MANUFACTURER TO MAINTAIN ANY CHANGES AND SUBSEQUENT WHQL
'RE-CERTIFICATION AS A RESULT OF MAKING THESE CHANGES.


'Module Name:

'ftd2xx.h

'Abstract:

'Native USB device driver for FTDI FT232x, FT245x, FT2232x and FT4232x devices
'FTD2XX library definitions

'Environment:

'kernel & user mode

'Revision History:

  '13/03/01 awm   Created.
  '13/01/03 awm   Added device information support.
  '19/03/03 awm   Added FT_W32_CancelIo.
  '12/06/03 awm   Added FT_StopInTask and FT_RestartInTask.
  '18/09/03 awm   Added FT_SetResetPipeRetryCount.
  '10/10/03 awm   Added FT_ResetPort.
  '23/01/04 awm   Added support for open-by-location.
  '16/03/04 awm   Added support for FT2232C.
  '23/09/04 awm   Added support for FT232R.
  '20/10/04 awm   Added FT_CyclePort.
  '18/01/05 awm   Added FT_DEVICE_LIST_INFO_NODE type.
  '11/02/05 awm   Added LocId to FT_DEVICE_LIST_INFO_NODE.
  '25/08/05 awm   Added FT_SetDeadmanTimeout.
  '02/12/05 awm   Removed obsolete references.
  '05/12/05 awm   Added FT_GetVersion, FT_GetVersionEx.
  '08/09/06 awm   Added FT_W32_GetCommMask.
  '11/09/06 awm   Added FT_Rescan.
  '11/07/07 awm   Added support for FT2232H and FT4232H.
  '10/08/07 awm   Added flags definitions.
  '21/11/07 mja   Added FT_GetComPortNumber.
  '05/06/08 mja   Added EEPROM extensions for FT2232H.


'--*/

#IFNDEF FTD2XX_H_TJF
#DEFINE FTD2XX_H_TJF

#IFDEF __FB_WIN32__
#PRAGMA push(msbitfields)
#ENDIF

#INCLUDE ONCE "windows.bi"

#INCLIB "ftd2xx"

TYPE AS ULONG ULONG_TJF
TYPE AS USHORT USHORT_TJF
TYPE AS BYTE BYTE_TJF

#LANG "fb"
EXTERN "C" ' (h_2_bi -P_oCD option)

' 001 start from: ftd2xx.h2bi ==> ftd2xx.h

#IFNDEF FTD2XX_H
#DEFINE FTD2XX_H

TYPE FT_HANDLE AS PVOID
TYPE FT_STATUS AS ULONG_TJF

ENUM
  FT_OK
  FT_INVALID_HANDLE
  FT_DEVICE_NOT_FOUND
  FT_DEVICE_NOT_OPENED
  FT_IO_ERROR
  FT_INSUFFICIENT_RESOURCES
  FT_INVALID_PARAMETER
  FT_INVALID_BAUD_RATE
  FT_DEVICE_NOT_OPENED_FOR_ERASE
  FT_DEVICE_NOT_OPENED_FOR_WRITE
  FT_FAILED_TO_WRITE_DEVICE
  FT_EEPROM_READ_FAILED
  FT_EEPROM_WRITE_FAILED
  FT_EEPROM_ERASE_FAILED
  FT_EEPROM_NOT_PRESENT
  FT_EEPROM_NOT_PROGRAMMED
  FT_INVALID_ARGS
  FT_NOT_SUPPORTED
  FT_OTHER_ERROR
  FT_DEVICE_LIST_NOT_READY
END ENUM

#DEFINE FT_SUCCESS(status) ((status)= FT_OK)
#DEFINE FT_OPEN_BY_SERIAL_NUMBER 1
#DEFINE FT_OPEN_BY_DESCRIPTION 2
#DEFINE FT_OPEN_BY_LOCATION 4
#DEFINE FT_LIST_NUMBER_ONLY &h80000000
#DEFINE FT_LIST_BY_INDEX &h40000000
#DEFINE FT_LIST_ALL &h20000000
#DEFINE FT_LIST_MASK (FT_LIST_NUMBER_ONLYOR FT_LIST_BY_INDEXOR FT_LIST_ALL)
#DEFINE FT_BAUD_300 300
#DEFINE FT_BAUD_600 600
#DEFINE FT_BAUD_1200 1200
#DEFINE FT_BAUD_2400 2400
#DEFINE FT_BAUD_4800 4800
#DEFINE FT_BAUD_9600 9600
#DEFINE FT_BAUD_14400 14400
#DEFINE FT_BAUD_19200 19200
#DEFINE FT_BAUD_38400 38400
#DEFINE FT_BAUD_57600 57600
#DEFINE FT_BAUD_115200 115200
#DEFINE FT_BAUD_230400 230400
#DEFINE FT_BAUD_460800 460800
#DEFINE FT_BAUD_921600 921600
#DEFINE FT_BITS_8 (UCHAR) 8
#DEFINE FT_BITS_7 (UCHAR) 7
#DEFINE FT_STOP_BITS_1 (UCHAR) 0
#DEFINE FT_STOP_BITS_2 (UCHAR) 1
#DEFINE FT_PARITY_NONE (UCHAR) 0
#DEFINE FT_PARITY_ODD (UCHAR) 1
#DEFINE FT_PARITY_EVEN (UCHAR) 2
#DEFINE FT_PARITY_MARK (UCHAR) 3
#DEFINE FT_PARITY_SPACE (UCHAR) 4
#DEFINE FT_FLOW_NONE &h0000
#DEFINE FT_FLOW_RTS_CTS &h0100
#DEFINE FT_FLOW_DTR_DSR &h0200
#DEFINE FT_FLOW_XON_XOFF &h0400
#DEFINE FT_PURGE_RX 1
#DEFINE FT_PURGE_TX 2

TYPE PFT_EVENT_HANDLER AS SUB(BYVAL AS DWORD, BYVAL AS DWORD)

#DEFINE FT_EVENT_RXCHAR 1
#DEFINE FT_EVENT_MODEM_STATUS 2
#DEFINE FT_EVENT_LINE_STATUS 4
#DEFINE FT_DEFAULT_RX_TIMEOUT 300
#DEFINE FT_DEFAULT_TX_TIMEOUT 300

TYPE FT_DEVICE AS ULONG_TJF

ENUM
  FT_DEVICE_BM
  FT_DEVICE_AM
  FT_DEVICE_100AX
  FT_DEVICE_UNKNOWN
  FT_DEVICE_2232C
  FT_DEVICE_232R
  FT_DEVICE_2232H
  FT_DEVICE_4232H
END ENUM

#IFDEF __cplusplus
#ENDIF ' __cplusplus

DECLARE FUNCTION FT_Open(BYVAL AS INTEGER, BYVAL AS FT_HANDLE PTR) AS FT_STATUS
DECLARE FUNCTION FT_OpenEx(BYVAL AS PVOID, BYVAL AS DWORD, BYVAL AS FT_HANDLE PTR) AS FT_STATUS
DECLARE FUNCTION FT_ListDevices(BYVAL AS PVOID, BYVAL AS PVOID, BYVAL AS DWORD) AS FT_STATUS
DECLARE FUNCTION FT_Close(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_Read(BYVAL AS FT_HANDLE, BYVAL AS LPVOID, BYVAL AS DWORD, BYVAL AS LPDWORD) AS FT_STATUS
DECLARE FUNCTION FT_Write(BYVAL AS FT_HANDLE, BYVAL AS LPVOID, BYVAL AS DWORD, BYVAL AS LPDWORD) AS FT_STATUS
DECLARE FUNCTION FT_IoCtl(BYVAL AS FT_HANDLE, BYVAL AS DWORD, BYVAL AS LPVOID, BYVAL AS DWORD, BYVAL AS LPVOID, BYVAL AS DWORD, BYVAL AS LPDWORD, BYVAL AS LPOVERLAPPED) AS FT_STATUS
DECLARE FUNCTION FT_SetBaudRate(BYVAL AS FT_HANDLE, BYVAL AS ULONG_TJF) AS FT_STATUS
DECLARE FUNCTION FT_SetDivisor(BYVAL AS FT_HANDLE, BYVAL AS USHORT_TJF) AS FT_STATUS
DECLARE FUNCTION FT_SetDataCharacteristics(BYVAL AS FT_HANDLE, BYVAL AS UCHAR, BYVAL AS UCHAR, BYVAL AS UCHAR) AS FT_STATUS
DECLARE FUNCTION FT_SetFlowControl(BYVAL AS FT_HANDLE, BYVAL AS USHORT_TJF, BYVAL AS UCHAR, BYVAL AS UCHAR) AS FT_STATUS
DECLARE FUNCTION FT_ResetDevice(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_SetDtr(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_ClrDtr(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_SetRts(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_ClrRts(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_GetModemStatus(BYVAL AS FT_HANDLE, BYVAL AS ULONG_TJF PTR) AS FT_STATUS
DECLARE FUNCTION FT_SetChars(BYVAL AS FT_HANDLE, BYVAL AS UCHAR, BYVAL AS UCHAR, BYVAL AS UCHAR, BYVAL AS UCHAR) AS FT_STATUS
DECLARE FUNCTION FT_Purge(BYVAL AS FT_HANDLE, BYVAL AS ULONG_TJF) AS FT_STATUS
DECLARE FUNCTION FT_SetTimeouts(BYVAL AS FT_HANDLE, BYVAL AS ULONG_TJF, BYVAL AS ULONG_TJF) AS FT_STATUS
DECLARE FUNCTION FT_GetQueueStatus(BYVAL AS FT_HANDLE, BYVAL AS DWORD PTR) AS FT_STATUS
DECLARE FUNCTION FT_SetEventNotification(BYVAL AS FT_HANDLE, BYVAL AS DWORD, BYVAL AS PVOID) AS FT_STATUS
DECLARE FUNCTION FT_GetStatus(BYVAL AS FT_HANDLE, BYVAL AS DWORD PTR, BYVAL AS DWORD PTR, BYVAL AS DWORD PTR) AS FT_STATUS
DECLARE FUNCTION FT_SetBreakOn(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_SetBreakOff(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_SetWaitMask(BYVAL AS FT_HANDLE, BYVAL AS DWORD) AS FT_STATUS
DECLARE FUNCTION FT_WaitOnMask(BYVAL AS FT_HANDLE, BYVAL AS DWORD PTR) AS FT_STATUS
DECLARE FUNCTION FT_GetEventStatus(BYVAL AS FT_HANDLE, BYVAL AS DWORD PTR) AS FT_STATUS
DECLARE FUNCTION FT_ReadEE(BYVAL AS FT_HANDLE, BYVAL AS DWORD, BYVAL AS LPWORD) AS FT_STATUS
DECLARE FUNCTION FT_WriteEE(BYVAL AS FT_HANDLE, BYVAL AS DWORD, BYVAL AS WORD) AS FT_STATUS
DECLARE FUNCTION FT_EraseEE(BYVAL AS FT_HANDLE) AS FT_STATUS

TYPE ft_program_data
  AS DWORD Signature1
  AS DWORD Signature2
  AS DWORD Version
  AS WORD VendorId
  AS WORD ProductId
  AS ZSTRING PTR Manufacturer
  AS ZSTRING PTR ManufacturerId
  AS ZSTRING PTR Description
  AS ZSTRING PTR SerialNumber
  AS WORD MaxPower
  AS WORD PnP
  AS WORD SelfPowered
  AS WORD RemoteWakeup
  AS UCHAR Rev4
  AS UCHAR IsoIn
  AS UCHAR IsoOut
  AS UCHAR PullDownEnable
  AS UCHAR SerNumEnable
  AS UCHAR USBVersionEnable
  AS WORD USBVersion
  AS UCHAR Rev5
  AS UCHAR IsoInA
  AS UCHAR IsoInB
  AS UCHAR IsoOutA
  AS UCHAR IsoOutB
  AS UCHAR PullDownEnable5
  AS UCHAR SerNumEnable5
  AS UCHAR USBVersionEnable5
  AS WORD USBVersion5
  AS UCHAR AIsHighCurrent
  AS UCHAR BIsHighCurrent
  AS UCHAR IFAIsFifo
  AS UCHAR IFAIsFifoTar
  AS UCHAR IFAIsFastSer
  AS UCHAR AIsVCP
  AS UCHAR IFBIsFifo
  AS UCHAR IFBIsFifoTar
  AS UCHAR IFBIsFastSer
  AS UCHAR BIsVCP
  AS UCHAR UseExtOsc
  AS UCHAR HighDriveIOs
  AS UCHAR EndpointSize
  AS UCHAR PullDownEnableR
  AS UCHAR SerNumEnableR
  AS UCHAR InvertTXD
  AS UCHAR InvertRXD
  AS UCHAR InvertRTS
  AS UCHAR InvertCTS
  AS UCHAR InvertDTR
  AS UCHAR InvertDSR
  AS UCHAR InvertDCD
  AS UCHAR InvertRI
  AS UCHAR Cbus0
  AS UCHAR Cbus1
  AS UCHAR Cbus2
  AS UCHAR Cbus3
  AS UCHAR Cbus4
  AS UCHAR RIsD2XX
  AS UCHAR PullDownEnable7
  AS UCHAR SerNumEnable7
  AS UCHAR ALSlowSlew
  AS UCHAR ALSchmittInput
  AS UCHAR ALDriveCurrent
  AS UCHAR AHSlowSlew
  AS UCHAR AHSchmittInput
  AS UCHAR AHDriveCurrent
  AS UCHAR BLSlowSlew
  AS UCHAR BLSchmittInput
  AS UCHAR BLDriveCurrent
  AS UCHAR BHSlowSlew
  AS UCHAR BHSchmittInput
  AS UCHAR BHDriveCurrent
  AS UCHAR IFAIsFifo7
  AS UCHAR IFAIsFifoTar7
  AS UCHAR IFAIsFastSer7
  AS UCHAR AIsVCP7
  AS UCHAR IFBIsFifo7
  AS UCHAR IFBIsFifoTar7
  AS UCHAR IFBIsFastSer7
  AS UCHAR BIsVCP7
  AS UCHAR PowerSaveEnable
  AS UCHAR PullDownEnable8
  AS UCHAR SerNumEnable8
  AS UCHAR ASlowSlew
  AS UCHAR ASchmittInput
  AS UCHAR ADriveCurrent
  AS UCHAR BSlowSlew
  AS UCHAR BSchmittInput
  AS UCHAR BDriveCurrent
  AS UCHAR CSlowSlew
  AS UCHAR CSchmittInput
  AS UCHAR CDriveCurrent
  AS UCHAR DSlowSlew
  AS UCHAR DSchmittInput
  AS UCHAR DDriveCurrent
  AS UCHAR ARIIsTXDEN
  AS UCHAR BRIIsTXDEN
  AS UCHAR CRIIsTXDEN
  AS UCHAR DRIIsTXDEN
  AS UCHAR AIsVCP8
  AS UCHAR BIsVCP8
  AS UCHAR CIsVCP8
  AS UCHAR DIsVCP8
END TYPE

DIM AS ft_program_data FT_PROGRAM_DATA
TYPE AS ft_program_data PTR PFT_PROGRAM_DATA

DECLARE FUNCTION FT_EE_Program(BYVAL AS FT_HANDLE, BYVAL AS PFT_PROGRAM_DATA) AS FT_STATUS
DECLARE FUNCTION FT_EE_ProgramEx(BYVAL AS FT_HANDLE, BYVAL AS PFT_PROGRAM_DATA, BYVAL AS ZSTRING PTR, BYVAL AS ZSTRING PTR, BYVAL AS ZSTRING PTR, BYVAL AS ZSTRING PTR) AS FT_STATUS
DECLARE FUNCTION FT_EE_Read(BYVAL AS FT_HANDLE, BYVAL AS PFT_PROGRAM_DATA) AS FT_STATUS
DECLARE FUNCTION FT_EE_ReadEx(BYVAL AS FT_HANDLE, BYVAL AS PFT_PROGRAM_DATA, BYVAL AS ZSTRING PTR, BYVAL AS ZSTRING PTR, BYVAL AS ZSTRING PTR, BYVAL AS ZSTRING PTR) AS FT_STATUS
DECLARE FUNCTION FT_EE_UASize(BYVAL AS FT_HANDLE, BYVAL AS LPDWORD) AS FT_STATUS
DECLARE FUNCTION FT_EE_UAWrite(BYVAL AS FT_HANDLE, BYVAL AS PUCHAR, BYVAL AS DWORD) AS FT_STATUS
DECLARE FUNCTION FT_EE_UARead(BYVAL AS FT_HANDLE, BYVAL AS PUCHAR, BYVAL AS DWORD, BYVAL AS LPDWORD) AS FT_STATUS
DECLARE FUNCTION FT_SetLatencyTimer(BYVAL AS FT_HANDLE, BYVAL AS UCHAR) AS FT_STATUS
DECLARE FUNCTION FT_GetLatencyTimer(BYVAL AS FT_HANDLE, BYVAL AS PUCHAR) AS FT_STATUS
DECLARE FUNCTION FT_SetBitMode(BYVAL AS FT_HANDLE, BYVAL AS UCHAR, BYVAL AS UCHAR) AS FT_STATUS
DECLARE FUNCTION FT_GetBitMode(BYVAL AS FT_HANDLE, BYVAL AS PUCHAR) AS FT_STATUS
DECLARE FUNCTION FT_SetUSBParameters(BYVAL AS FT_HANDLE, BYVAL AS ULONG_TJF, BYVAL AS ULONG_TJF) AS FT_STATUS
DECLARE FUNCTION FT_SetDeadmanTimeout(BYVAL AS FT_HANDLE, BYVAL AS ULONG_TJF) AS FT_STATUS
DECLARE FUNCTION FT_GetDeviceInfo(BYVAL AS FT_HANDLE, BYVAL AS FT_DEVICE PTR, BYVAL AS LPDWORD, BYVAL AS PCHAR, BYVAL AS PCHAR, BYVAL AS LPVOID) AS FT_STATUS
DECLARE FUNCTION FT_StopInTask(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_RestartInTask(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_SetResetPipeRetryCount(BYVAL AS FT_HANDLE, BYVAL AS DWORD) AS FT_STATUS
DECLARE FUNCTION FT_ResetPort(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_CyclePort(BYVAL AS FT_HANDLE) AS FT_STATUS
DECLARE FUNCTION FT_W32_CreateFile(BYVAL AS LPCTSTR, BYVAL AS DWORD, BYVAL AS DWORD, BYVAL AS LPSECURITY_ATTRIBUTES, BYVAL AS DWORD, BYVAL AS DWORD, BYVAL AS HANDLE) AS FT_HANDLE
DECLARE FUNCTION FT_W32_CloseHandle(BYVAL AS FT_HANDLE) AS BOOL
DECLARE FUNCTION FT_W32_ReadFile(BYVAL AS FT_HANDLE, BYVAL AS LPVOID, BYVAL AS DWORD, BYVAL AS LPDWORD, BYVAL AS LPOVERLAPPED) AS BOOL
DECLARE FUNCTION FT_W32_WriteFile(BYVAL AS FT_HANDLE, BYVAL AS LPVOID, BYVAL AS DWORD, BYVAL AS LPDWORD, BYVAL AS LPOVERLAPPED) AS BOOL
DECLARE FUNCTION FT_W32_GetLastError(BYVAL AS FT_HANDLE) AS DWORD
DECLARE FUNCTION FT_W32_GetOverlappedResult(BYVAL AS FT_HANDLE, BYVAL AS LPOVERLAPPED, BYVAL AS LPDWORD, BYVAL AS BOOL) AS BOOL
DECLARE FUNCTION FT_W32_CancelIo(BYVAL AS FT_HANDLE) AS BOOL

TYPE _FTCOMSTAT
  AS DWORD fCtsHold : 1
  AS DWORD fDsrHold : 1
  AS DWORD fRlsdHold : 1
  AS DWORD fXoffHold : 1
  AS DWORD fXoffSent : 1
  AS DWORD fEof : 1
  AS DWORD fTxim : 1
  AS DWORD fReserved : 25
  AS DWORD cbInQue
  AS DWORD cbOutQue
END TYPE

TYPE AS _FTCOMSTAT FTCOMSTAT, LPFTCOMSTAT

TYPE _FTDCB
  AS DWORD DCBlength
  AS DWORD BaudRate
  AS DWORD fBinary : 1
  AS DWORD fParity : 1
  AS DWORD fOutxCtsFlow : 1
  AS DWORD fOutxDsrFlow : 1
  AS DWORD fDtrControl : 2
  AS DWORD fDsrSensitivity : 1
  AS DWORD fTXContinueOnXoff : 1
  AS DWORD fOutX : 1
  AS DWORD fInX : 1
  AS DWORD fErrorChar : 1
  AS DWORD fNull : 1
  AS DWORD fRtsControl : 2
  AS DWORD fAbortOnError : 1
  AS DWORD fDummy2 : 17
  AS WORD wReserved
  AS WORD XonLim
  AS WORD XoffLim
  AS BYTE_TJF ByteSize
  AS BYTE_TJF Parity
  AS BYTE_TJF StopBits
  AS UBYTE XonChar
  AS UBYTE XoffChar
  AS UBYTE ErrorChar
  AS UBYTE EofChar
  AS UBYTE EvtChar
  AS WORD wReserved1
END TYPE

TYPE AS _FTDCB FTDCB, LPFTDCB

TYPE _FTTIMEOUTS
  AS DWORD ReadIntervalTimeout
  AS DWORD ReadTotalTimeoutMultiplier
  AS DWORD ReadTotalTimeoutConstant
  AS DWORD WriteTotalTimeoutMultiplier
  AS DWORD WriteTotalTimeoutConstant
END TYPE

TYPE AS _FTTIMEOUTS FTTIMEOUTS, LPFTTIMEOUTS

DECLARE FUNCTION FT_W32_ClearCommBreak(BYVAL AS FT_HANDLE) AS BOOL
DECLARE FUNCTION FT_W32_ClearCommError(BYVAL AS FT_HANDLE, BYVAL AS LPDWORD, BYVAL AS LPFTCOMSTAT) AS BOOL
DECLARE FUNCTION FT_W32_EscapeCommFunction(BYVAL AS FT_HANDLE, BYVAL AS DWORD) AS BOOL
DECLARE FUNCTION FT_W32_GetCommModemStatus(BYVAL AS FT_HANDLE, BYVAL AS LPDWORD) AS BOOL
DECLARE FUNCTION FT_W32_GetCommState(BYVAL AS FT_HANDLE, BYVAL AS LPFTDCB) AS BOOL
DECLARE FUNCTION FT_W32_GetCommTimeouts(BYVAL AS FT_HANDLE, BYVAL AS FTTIMEOUTS PTR) AS BOOL
DECLARE FUNCTION FT_W32_PurgeComm(BYVAL AS FT_HANDLE, BYVAL AS DWORD) AS BOOL
DECLARE FUNCTION FT_W32_SetCommBreak(BYVAL AS FT_HANDLE) AS BOOL
DECLARE FUNCTION FT_W32_SetCommMask(BYVAL AS FT_HANDLE, BYVAL AS ULONG_TJF) AS BOOL
DECLARE FUNCTION FT_W32_GetCommMask(BYVAL AS FT_HANDLE, BYVAL AS LPDWORD) AS BOOL
DECLARE FUNCTION FT_W32_SetCommState(BYVAL AS FT_HANDLE, BYVAL AS LPFTDCB) AS BOOL
DECLARE FUNCTION FT_W32_SetCommTimeouts(BYVAL AS FT_HANDLE, BYVAL AS FTTIMEOUTS PTR) AS BOOL
DECLARE FUNCTION FT_W32_SetupComm(BYVAL AS FT_HANDLE, BYVAL AS DWORD, BYVAL AS DWORD) AS BOOL
DECLARE FUNCTION FT_W32_WaitCommEvent(BYVAL AS FT_HANDLE, BYVAL AS PULONG, BYVAL AS LPOVERLAPPED) AS BOOL

TYPE _ft_device_list_info_node
  AS ULONG_TJF Flags
  AS ULONG_TJF Type
  AS ULONG_TJF ID
  AS DWORD LocId
  AS ZSTRING*16 SerialNumber
  AS ZSTRING*64 Description
  AS FT_HANDLE ftHandle
END TYPE

TYPE AS _ft_device_list_info_node FT_DEVICE_LIST_INFO_NODE

ENUM
  FT_FLAGS_OPENED = 1
  FT_FLAGS_HISPEED = 2
END ENUM

DECLARE FUNCTION FT_CreateDeviceInfoList(BYVAL AS LPDWORD) AS FT_STATUS
DECLARE FUNCTION FT_GetDeviceInfoList(BYVAL AS FT_DEVICE_LIST_INFO_NODE PTR, BYVAL AS LPDWORD) AS FT_STATUS
DECLARE FUNCTION FT_GetDeviceInfoDetail(BYVAL AS DWORD, BYVAL AS LPDWORD, BYVAL AS LPDWORD, BYVAL AS LPDWORD, BYVAL AS LPDWORD, BYVAL AS LPVOID, BYVAL AS LPVOID, BYVAL AS FT_HANDLE PTR) AS FT_STATUS
DECLARE FUNCTION FT_GetDriverVersion(BYVAL AS FT_HANDLE, BYVAL AS LPDWORD) AS FT_STATUS
DECLARE FUNCTION FT_GetLibraryVersion(BYVAL AS LPDWORD) AS FT_STATUS
DECLARE FUNCTION FT_Rescan() AS FT_STATUS
DECLARE FUNCTION FT_Reload(BYVAL AS WORD, BYVAL AS WORD) AS FT_STATUS
DECLARE FUNCTION FT_GetComPortNumber(BYVAL AS FT_HANDLE, BYVAL AS LPLONG) AS FT_STATUS

#IFDEF __cplusplus
#ENDIF ' __cplusplus
#ENDIF ' FTD2XX_H

' 001 back from ftd2xx.h ==> ftd2xx.h2bi

END EXTERN ' (h_2_bi -P_oCD option)
' 000 start from: ftd2xx.h2bi, section __END_BI__

#IFDEF __FB_WIN32__
#PRAGMA pop(msbitfields)
#ENDIF

#ENDIF ' FTD2XX_H_TJF

' Translated at 11-02-23 20:20:53, by h_2_bi (version 0.2.0.1,
' released under GPLv3 by Thomas[ dot ]Freiherr[ at ]gmx[ dot ]net)

'   Protocol: ftd2xx.bi
' Parameters:
'                                  Process time [s]: 0.08117903512902558
'                                  Bytes translated: 13861
'                                      Maximum deep: 1
'                                SUB/FUNCTION names: 80
' PFT_EVENT_HANDLER
' FT_Open
' FT_OpenEx
' FT_ListDevices
' FT_Close
' FT_Read
' FT_Write
' FT_IoCtl
' FT_SetBaudRate
' FT_SetDivisor
' FT_SetDataCharacteristics
' FT_SetFlowControl
' FT_ResetDevice
' FT_SetDtr
' FT_ClrDtr
' FT_SetRts
' FT_ClrRts
' FT_GetModemStatus
' FT_SetChars
' FT_Purge
' FT_SetTimeouts
' FT_GetQueueStatus
' FT_SetEventNotification
' FT_GetStatus
' FT_SetBreakOn
' FT_SetBreakOff
' FT_SetWaitMask
' FT_WaitOnMask
' FT_GetEventStatus
' FT_ReadEE
' FT_WriteEE
' FT_EraseEE
' FT_EE_Program
' FT_EE_ProgramEx
' FT_EE_Read
' FT_EE_ReadEx
' FT_EE_UASize
' FT_EE_UAWrite
' FT_EE_UARead
' FT_SetLatencyTimer
' FT_GetLatencyTimer
' FT_SetBitMode
' FT_GetBitMode
' FT_SetUSBParameters
' FT_SetDeadmanTimeout
' FT_GetDeviceInfo
' FT_StopInTask
' FT_RestartInTask
' FT_SetResetPipeRetryCount
' FT_ResetPort
' FT_CyclePort
' FT_W32_CreateFile
' FT_W32_CloseHandle
' FT_W32_ReadFile
' FT_W32_WriteFile
' FT_W32_GetLastError
' FT_W32_GetOverlappedResult
' FT_W32_CancelIo
' FT_W32_ClearCommBreak
' FT_W32_ClearCommError
' FT_W32_EscapeCommFunction
' FT_W32_GetCommModemStatus
' FT_W32_GetCommState
' FT_W32_GetCommTimeouts
' FT_W32_PurgeComm
' FT_W32_SetCommBreak
' FT_W32_SetCommMask
' FT_W32_GetCommMask
' FT_W32_SetCommState
' FT_W32_SetCommTimeouts
' FT_W32_SetupComm
' FT_W32_WaitCommEvent
' FT_CreateDeviceInfoList
' FT_GetDeviceInfoList
' FT_GetDeviceInfoDetail
' FT_GetDriverVersion
' FT_GetLibraryVersion
' FT_Rescan
' FT_Reload
' FT_GetComPortNumber
'                                mangled TYPE names: 0
'                                        files done: 0
'                                      files missed: 0
'                                       __FOLDERS__: 0
'                                        __MACROS__: 2
' 79: #define FTD2XX_API
' 79: #define WINAPI
'                                       __HEADERS__: 0
'                                         __TYPES__: 0
'                                     __POST_REPS__: 0
Volhout
Posts: 15
Joined: Feb 23, 2011 15:28

Does not compile

Postby Volhout » Feb 28, 2011 12:54

When I compile the main program that includes your ftdi.bi it immediatly starts with compiler errors. Apparently it does not understand #LANG
When I comment this out, then it starts generating errors about the next line EXTERN "C".

Here is the first detailed compiler error.

Command executed:
"C:\FreeBasic\fbc.exe" "C:\FreeBASIC\examples\ftdi\ftdi_test.bas"

Compiler output:
FTDI.bi(102) : error 10: Expected '=', found: 'fb'
#LANG "fb"
^

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 0.15 for win32 (target:win32)
OS: Windows XP (build 2600, Service Pack 3)
TJF
Posts: 3474
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Feb 28, 2011 15:23

Thanks for the good report!

And sorry for your trouble, but you need an up-to-date compiler for the header (at least version 0.20, better the current 0.21.1).
Volhout
Posts: 15
Joined: Feb 23, 2011 15:28

PVOID

Postby Volhout » Mar 01, 2011 13:48

Hi TJF,

Thanks for helping so fast. I was amazed !. I upgraded the compiler to the latest, used your .BI files, and it starts to work (adding functionality while experimenting).

But I seem to be stuck again, and could use your advise. See below code:

If FT_GetDeviceInfoList(@DevInfo,@FT_NumDev) = FT_OK Then
PrintInfoList(FT_NumDev)
FT_Status = FT_Open(0,@MyHandle) ' Open device
If FT_Status = FT_OK Then
Print "Opened with handle", MyHandle
If FT_SetDivisor(MyHandle, &h400) = FT_OK then 'set to 9600 baud
print "IO update rate set to 9600 baud"
EndIf
EndIf
EndIf

The handle I get is 4255944, which may be a bit odd, and SetDivisor simply fails to set the divisor. Returns everything but "0".
I saw in the .BI file that the handle was defined as a PVOID. But PVOID is not recognized by the IDE. I had similar problem with your ULONG_TJF that I defined as UInteger (versus the old ULONG). Is this because the FBIDE is much older than the compiler, and it's coloring editor does not recognize the actual compiler words ? Is there an upgrade for the editor ?

But what about PVOID ? Is that correct, and should I look elsewhere ?
Not sure what to do now...

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

Postby TJF » Mar 01, 2011 14:30

Volhout wrote:Hi TJF,

Thanks for helping so fast.

Your wellcome!

Volhout wrote:I had similar problem with your ULONG_TJF that I defined as UInteger (versus the old ULONG).

And you get no duplicated definition error?

The ULONG_TJF definition is in line 98 in the code above. (The _TJF gets automaticly mangled by h_2_bi to avoid naming conflicts between C- and FB-variables/types, so the new type ULONG_TJF has to get declared.)

Volhout wrote:Is there an upgrade for the editor ?

I don't use FBEdit. For handling of C code and cross-platform capability I use Geany.

Volhout wrote:I saw in the .BI file that the handle was defined as a PVOID. But PVOID is not recognized by the IDE.

My header includes windows.bi. This header includes win/windef.bi. This header includes win/winnt.bi. PVOID is defined in the latest.


I made some small bugfixes in the header. Since your test seems to be successful, I'll publish the fixed header on http://www.freebasic-portal.de/downloads/bibliotheken/ ASAP.
TJF
Posts: 3474
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Mar 01, 2011 15:07

Volhout
Posts: 15
Joined: Feb 23, 2011 15:28

Geany

Postby Volhout » Mar 02, 2011 8:25

Hi TJF,

Does Geany support the freebasic language set (coloring) for the 0.21.1 compiler version ? If that is the case, I would prefer it over FBIDE.

Regards,

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

Postby TJF » Mar 02, 2011 9:53

Why don't you try it? I sent a link to wikipedia in my post above. At this site you'll find a download link.

Geany supports syntax highlighting for several languages. It supports FreeBasic as well as C (and .html and .tex and ...).

As far as I remember some rar FB keywords are missing (ie like ANDALSO or ORELSE). But you can easily add them in the config file.
Volhout
Posts: 15
Joined: Feb 23, 2011 15:28

Geany

Postby Volhout » Mar 02, 2011 10:15

Hi TJF,

I'll give Geany a try...

For now I used your (published) .BI file, and get 1 compiler error:

Command executed:
"C:\FreeBasic\fbc.exe" "C:\FreeBASIC\examples\ftdi\ftdi_001.bas"

Compiler output:
C:\FreeBASIC\examples\ftdi\ftd2xx-2.08.02_TJF.bi(423) error 56: Illegal specification, at parameter 3 of FT_W32_ClearCommError() in 'DECLARE FUNCTION FT_W32_ClearCommError(BYVAL AS FT_HANDLE, BYVAL AS LPDWORD, BYVAL AS LPFTCOMSTAT) AS BOOL'

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 0.21.1 (08-11-2010) for win32 (target:win32)
OS: Windows XP (build 2600, Service Pack 3)


Seems like a problem with the LPFTCOMSTAT type.
fxm
Posts: 9083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Mar 02, 2011 10:24

- You can also find a portable version of Genay 0.20 at:
http://portableapps.com/apps/development/geany_portable

- In a previous post, I gave some guidance to configure Geany IDE under Windows:
http://www.freebasic.net/forum/viewtopi ... 787#148787

- If you compile with the option -exx in Geany, there is no problem to monitor a runtime error, because basically, the command "Execute" runs the executable file from a terminal window (shell script calling "cmd.exe" set per default in the menu "Edit/Preferences/Tools).
Last edited by fxm on Mar 02, 2011 14:51, edited 1 time in total.
TJF
Posts: 3474
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Geany

Postby TJF » Mar 02, 2011 10:40

Volhout wrote:...
Seems like a problem with the LPFTCOMSTAT type.

Ups, my fault -- sorry!

A new version is uploaded (use again the link above).

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 10 guests