From: Pat Thoyts Date: Thu, 5 Nov 2009 18:23:42 +0000 (+0000) Subject: Have the version command return a formatted version string. X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=tclftd2xx Have the version command return a formatted version string. Ensure we have at least Tcl 8.4 and provide a useful error message. Signed-off-by: Pat Thoyts --- diff --git a/README b/README index dfb6780..7e1e9da 100644 --- a/README +++ b/README @@ -51,21 +51,25 @@ ftd2xx purge channel purge the device buffers for the device identified by the channel +ftd2xx version + + return the FTDI library version (eg: 3.1.16) INSTALLATION The FTDI D2XX driver package should be downloaded from the website -(http://www.ftdichip.com/Drivers/D2XX.htm) and the Makefile.vc -modified such that FTDI_INCLUDE points to the directory containing the -ftdi2xx.h header and FTDI_LIB points to the directory containing the -library files. +(http://www.ftdichip.com/Drivers/D2XX.htm). Set the FTDI_DIR variable +when calling Makefile.vc to point to the driver directory that +contains the ftd2xx.h header. Using MSVC (6 to 9) do: - nmake -f Makefile.vc TCLDIR=c:\Tcl - nmake -f Makefile.vc TCLDIR=c:\Tcl install + nmake -f Makefile.vc TCLDIR=c:\Tcl FTDI_DIR=..\D2XX + nmake -f Makefile.vc TCLDIR=c:\Tcl FTDI_DIR=..\D2XX install If the ftd2xx.dll is not installed already, it should be manually -copied to the installation folder (eg: c:\tcl\lib\tclftd2xx). +copied to the installation folder (eg: c:\tcl\lib\tclftd2xx). It +is usually installed into the system32 folder when the device driver +is installed. You may have to install drivers for your device (ftdibus.sys or ftd2xx.sys). This should be provided by the device manufacturer as the diff --git a/tclftd2xx.c b/tclftd2xx.c index ed592f4..b26a022 100644 --- a/tclftd2xx.c +++ b/tclftd2xx.c @@ -19,6 +19,10 @@ #include #include "ftd2xx.h" +#if 10 * TCL_MAJOR_VERSION + TCL_MINOR_VERSION < 84 +#error This package requires at least Tcl 8.4 +#endif + typedef FT_STATUS (WINAPI FT_CloseProc)(FT_HANDLE); typedef FT_STATUS (WINAPI FT_CreateDeviceInfoListProc)(LPDWORD); typedef FT_STATUS (WINAPI FT_GetDeviceInfoListProc) @@ -1001,6 +1005,7 @@ static int VersionCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { FT_STATUS fts; + char s[TCL_INTEGER_SPACE * 3 + 4]; DWORD dwVersion = 0; if (objc != 2) { @@ -1014,7 +1019,11 @@ VersionCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const o return TCL_ERROR; } - Tcl_SetObjResult(interp, Tcl_NewWideIntObj((Tcl_WideInt)dwVersion)); + sprintf(s, "%d.%d.%d", + (dwVersion >> 16) & 0xff, + (dwVersion >> 8) & 0xff, + (dwVersion & 0xff)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(s, -1)); return TCL_OK; } @@ -1090,11 +1099,12 @@ Ftd2xx_Init(Tcl_Interp *interp) LPCSTR szDllName = "FTD2XX.dll"; #endif -#ifdef USE_TCL_STUBS - if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + if (Tcl_InitStubs(interp, "8.4", 0) == NULL) { return TCL_ERROR; } -#endif + if (Tcl_PkgRequire(interp, "Tcl", "8.4", 0) == NULL) { + return TCL_ERROR; + } hDll = LoadLibraryA(szDllName); if (hDll == NULL) {