2017-12-05 2 views
0

Ich versuche Grundlagen- FTDI-Codierung, und hier ist ein einfaches Programm, das in der Lage sein sollte, Bytes aus einem einzelnen FTDI-Gerät zu lesen:Undeclared FTDI Identifiers

#include "stdafx.h" 
#include "ftd2xx.h" 
#include <iostream> 
#include <stdlib.h> 
#include <stdio.h> 

using namespace std; 

int scan_and_read() 
{ 
    unsigned long int ftDevCount = 0; 
    FT_STATUS ftStatus; 
    FT_HANDLE ftHandle; 
    FT_DEVICE_LIST_INFO_NODE *devInfo; 
    DWORD numDevs; 
    DWORD EventDWord; 
    DWORD TxBytes; 
    DWORD RxBytes; 
    DWORD BytesReceived; 
    char RxBuffer[256]; 


    // 
    // horrible assumption: there will only be one device connected 
    // or, the very least, the first device to be connected will be the desired device 
    // 
    ftStatus = FT_CreateDeviceInfoList(&numDevs); 
    if (ftStatus == FT_OK) { 
     cout << "Devices connected: " << numDevs << endl; 
    } 
    else { 
     // FT_CreateDeviceInfoList failed 
     return 1; 
    } 

    devInfo = 
     (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs); 
    ftStatus = FT_GetDeviceInfoList(devInfo, &numDevs); 
    string serial_info = devInfo[0].SerialNumber; 


    ftStatus = FT_OpenEx((PVOID)serial_info.c_str(), FT_OPEN_BY_SERIAL_NUMBER, &ftHandle); 
    if (ftStatus == FT_OK) { 
     cout << "Device opened" << endl; 
    } 
    else { 
     return 2; 
    } 

    FT_GetStatus(ftHandle, &RxBytes, &TxBytes, &EventDWord); 
    if (RxBytes > 0) { 
     ftStatus = FT_Read(ftHandle, RxBuffer, RxBytes, &BytesReceived); 
     if (ftStatus == FT_OK) { 
      for (int i = 0; i < RxBytes; i++) 
      { 
       cout << "Byte " << i << ": " << *(&(BytesReceived)+i) << endl; 
      } 
     } 
     else { 
      return 3; 
     } 
    } 
    FT_Close(ftHandle); 

    cout << "All data read." << endl; 

    return 0; 
} 


int main() 
{ 
    cout << scan_and_read() << endl; 

    return 0; 
} 

von Visual Studios sagt, dass alle der Kennungen (

c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(17): error C2065: 'FT_STATUS': undeclared identifier
1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(17): error C2146: syntax error: missing ';' before identifier 'ftStatus'
1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(17): error C2065: 'ftStatus': undeclared identifier
1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(18): error C2065: 'FT_HANDLE': undeclared identifier
1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(18): error C2146: syntax error: missing ';' before identifier 'ftHandle'
1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(18): error C2065: 'ftHandle': undeclared identifier

... etc.

ich kann nichts syntaktisch falsch mit meinem Code oder die er finden: andere als die unsigned long int) verwendet, um die Variablen zu deklarieren sind nicht deklariert Ader-Datei enthalten; Was ist los mit dir?

Antwort

0

Sieht aus wie Visual Studio Ihre Bibliotheken nicht finden kann. Sie können sie hinzufügen (VS 2017) unter Projekt> Eigenschaften> C/C++> Allgemein> Zusätzliche Include-Verzeichnisse.

Denken Sie daran, dlls auch unter Projekt> Eigenschaften> Linker> Weitere Bibliotheksverzeichnisse bereitzustellen, damit das kompilierte Programm ausgeführt wird.