Permalink
Browse files

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 <patthoyts@users.sourceforge.net>
  • Loading branch information...
1 parent 5255c17 commit ab0ef2bd135fbc0fb6731e4059aff100bc0a0760 @patthoyts committed Nov 5, 2009
Showing with 25 additions and 11 deletions.
  1. +11 −7 README
  2. +14 −4 tclftd2xx.c
View
18 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
View
18 tclftd2xx.c
@@ -19,6 +19,10 @@
#include <errno.h>
#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) {

0 comments on commit ab0ef2b

Please sign in to comment.