Rev 3455 Rev 3589
1 // FT_List 1 // FT_List
2 // ---------------------------------------- 2 // ----------------------------------------
3 // 3 //
4 // (c) miho 2014 http://www.mlab.cz 4 // (c) miho 2014 http://www.mlab.cz
5 // 5 //
6 // This program if free. 6 // This program if free.
7 // 7 //
8 // 8 //
9 // History: 9 // History:
10 // 10 //
11 // 1.00 2014_01 Start 11 // 1.00 2014_01 Start
-   12 // 1.01 2014_03 Wait at the end of the program
12 // 13 //
13 // 14 //
14 // Purpose: 15 // Purpose:
15 // 16 //
16 // List all FTDI serial com port chips found in Windows system with theirs com port numbers. 17 // List all FTDI serial com port chips found in Windows system with theirs com port numbers.
17 // 18 //
18 // Environment: 19 // Environment:
19 // 20 //
20 // This is Win32 Console Application and run in WinXP / Win7 / Win8 both 32 and 64 bit. 21 // This is Win32 Console Application and run in WinXP / Win7 / Win8 both 32 and 64 bit.
21 // 22 //
22 // Compilation for Windows: 23 // Compilation for Windows:
23 // 24 //
24 // MS Visual C++ 2010 Express (free, registration required) 25 // MS Visual C++ 2010 Express (free, registration required)
25 // Create new _empty_ project for Win32 Console Application and name project FT_List 26 // Create new _empty_ project for Win32 Console Application and name project FT_List
26 // Header Files / Add / Existing Items - all .h files (not necessary) 27 // Header Files / Add / Existing Items - all .h files (not necessary)
27 // Source Files / Add / Existing Items - all .cpp files 28 // Source Files / Add / Existing Items - all .cpp files
28 // Library Files / Add / Existing Items - all .lib .h files from lib_win32 directory (not necessary) 29 // Library Files / Add / Existing Items - all .lib .h files from lib_win32 directory (not necessary)
29 // Select Release version (no debug info) 30 // Select Release version (no debug info)
30 // Set static linkage Project Properties / Configuration Release / Configuration Properties 31 // Set static linkage Project Properties / Configuration Release / Configuration Properties
31 // / Code Generation / Runtime Library = Multithreaded (/MT) 32 // / Code Generation / Runtime Library = Multithreaded (/MT)
32 // 33 //
33   34  
34 #define YEAR "2014" 35 #define YEAR "2014"
35 #define VERSION "1.00" 36 #define VERSION "1.01"
36   37  
37   38  
38 // Library Definitions 39 // Library Definitions
39 // ------------------- 40 // -------------------
40   41  
41 #include <stdio.h> // Standard IO (printf, ...) 42 #include <stdio.h> // Standard IO (printf, ...)
-   43 #include <conio.h> // Windows _getch
42 #include <windows.h> // Windows Console Application 44 #include <windows.h> // Windows Console Application
43 #include "lib_win32\ftd2xx.h" // FTDI Library 45 #include "lib_win32\ftd2xx.h" // FTDI Library
44   46  
45 // Link with library 47 // Link with library
46 #pragma comment (lib, "lib_win32/ftd2xx.lib") // Add this file to Resources 48 #pragma comment (lib, "lib_win32/ftd2xx.lib") // Add this file to Resources
47   49  
48   50  
-   51 void waitforkey()
-   52 {
-   53 printf("\nPress any Key ...\n");
-   54 _getch();
-   55 printf("\n");
-   56 }
-   57  
-   58  
49 // Main 59 // Main
50 // ---- 60 // ----
51   61  
52 int main(int argc, char *argv[]) 62 int main(int argc, char *argv[])
53 { 63 {
54 // Program Info 64 // Program Info
55 printf("\n"); 65 printf("\n");
56 printf("FTDI Comport Lister\n"); 66 printf("FTDI Comport Lister\n");
57 printf("===================\n"); 67 printf("===================\n");
58 printf("(c) miho " YEAR " v " VERSION "\n\n"); 68 printf("(c) miho " YEAR " v " VERSION "\n\n");
59   69  
60 // Enumerate FTDI Devices 70 // Enumerate FTDI Devices
61 // ---------------------- 71 // ----------------------
62   72  
63 FT_STATUS ftStatus; 73 FT_STATUS ftStatus;
64 FT_HANDLE ftHandle; 74 FT_HANDLE ftHandle;
65   75  
66 // Print Library Version 76 // Print Library Version
67 printf("FTDI Connect\n"); 77 printf("FTDI Connect\n");
68 DWORD dwLibraryVer; 78 DWORD dwLibraryVer;
69 ftStatus = FT_GetLibraryVersion(&dwLibraryVer); 79 ftStatus = FT_GetLibraryVersion(&dwLibraryVer);
70 if (ftStatus == FT_OK) 80 if (ftStatus == FT_OK)
71 printf(" Library Version 0x%x\n", dwLibraryVer); 81 printf(" Library Version 0x%x\n", dwLibraryVer);
72 else 82 else
73 fprintf(stderr, "\nFTDI: Error Reading Library Version\n"); 83 fprintf(stderr, "\nFTDI: Error Reading Library Version\n");
74   84  
75 // Create Device Information List 85 // Create Device Information List
76 DWORD numDevs = 0; 86 DWORD numDevs = 0;
77 ftStatus = FT_CreateDeviceInfoList(&numDevs); 87 ftStatus = FT_CreateDeviceInfoList(&numDevs);
78 if (ftStatus == FT_OK) 88 if (ftStatus == FT_OK && numDevs>0)
79 printf(" Devices Found %d\n", numDevs); 89 printf(" Devices Found %d\n", numDevs);
80 else 90 else
81 printf(" No FTDI Device Found\n"); 91 printf(" No FTDI Device Found\n");
82   92  
83 if (numDevs==0) 93 if (numDevs==0)
-   94 {
-   95 waitforkey();
84 return -1; 96 return -1;
-   97 }
85   98  
86 // List All FTDI Devices 99 // List All FTDI Devices
87 FT_HANDLE ftHandleTemp; 100 FT_HANDLE ftHandleTemp;
88 DWORD Flags; 101 DWORD Flags;
89 DWORD ID; 102 DWORD ID;
90 DWORD Type; 103 DWORD Type;
91 DWORD LocId; 104 DWORD LocId;
92 char SerialNumber[16]; 105 char SerialNumber[16];
93 char Description[64]; 106 char Description[64];
94 for (DWORD i=0; i<numDevs; i++) 107 for (DWORD i=0; i<numDevs; i++)
95 { 108 {
96 ftStatus = FT_GetDeviceInfoDetail(i, &Flags, &Type, &ID, &LocId, SerialNumber, Description, &ftHandleTemp); 109 ftStatus = FT_GetDeviceInfoDetail(i, &Flags, &Type, &ID, &LocId, SerialNumber, Description, &ftHandleTemp);
97 if (ftStatus == FT_OK) 110 if (ftStatus == FT_OK)
98 { 111 {
99 printf("\nDevice %d\n", i); 112 printf("\nDevice %d\n", i);
100 if (Flags & FT_FLAGS_OPENED) 113 if (Flags & FT_FLAGS_OPENED)
101 { 114 {
102 printf(" Description Device is used by another process\n"); 115 printf(" Description Device is used by another process\n");
103 } 116 }
104 else 117 else
105 { 118 {
106 printf(" Description \"%s\"\n", Description); 119 printf(" Description \"%s\"\n", Description);
107 printf(" SerialNumber \"%s\"\n", SerialNumber); 120 printf(" SerialNumber \"%s\"\n", SerialNumber);
108 // printf(" Flags 0x%x\n", Flags); 121 // printf(" Flags 0x%x\n", Flags);
109 // printf(" Type 0x%x\n", Type); 122 // printf(" Type 0x%x\n", Type);
110 // printf(" ID 0x%x\n", ID); 123 // printf(" ID 0x%x\n", ID);
111 printf(" Location 0x%x\n", LocId); 124 printf(" Location 0x%x\n", LocId);
112 { 125 {
113 long comPortNumber=-1; 126 long comPortNumber=-1;
114 ftStatus = FT_Open(i, &ftHandle); 127 ftStatus = FT_Open(i, &ftHandle);
115 FT_GetComPortNumber(ftHandle, &comPortNumber); 128 FT_GetComPortNumber(ftHandle, &comPortNumber);
116 if (comPortNumber==-1) 129 if (comPortNumber==-1)
117 { 130 {
118 printf(" Com Port not availabe"); 131 printf(" Com Port not availabe");
119 } 132 }
120 else 133 else
121 { 134 {
122 printf(" Com Port com%d", comPortNumber); 135 printf(" Com Port com%d", comPortNumber);
123 } 136 }
124 FT_Close(ftHandle); 137 FT_Close(ftHandle);
125 } 138 }
126 } 139 }
127 printf("\n\n"); 140 printf("\n");
128 } 141 }
129 } 142 }
-   143 waitforkey();
130 return 0; 144 return 0;
131 } 145 }