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