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