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