首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未声明的FTDI标识符

未声明的FTDI标识符
EN

Stack Overflow用户
提问于 2017-12-05 23:42:05
回答 1查看 273关注 0票数 0

我正在尝试基本的FTDI编码,下面是一个简单的程序,应该可以从一个FTDI设备读取字节:

代码语言:javascript
复制
#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;
}

Visual Studio说,用于声明变量的所有标识符(未签名的长int除外)都未声明:

c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(17):错误C2065:'FT_STATUS':未声明的标识符 1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(17):error C2146:语法错误:缺少“;”在标识符“ftStatus”之前 1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(17):错误C2065:“ftStatus”:未声明的标识符 1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(18):错误C2065:'FT_HANDLE':未声明的标识符 1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(18):error C2146:语法错误:缺少“;”在标识符“ftHandle”之前 1>c:\users\histo\source\repos\ftdi_intro\ftdi_intro\ftdiintro.cpp(18):错误C2065:“ftHandle”:未声明的标识符

..。等。

我找不到我的代码或包含的头文件在语法上有什么问题;出了什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-12 07:48:18

看来Visual找不到您的库。您可以在Project>Properties>C/C++>General>附加包含目录中添加它们(VS 2017)。

请记住在Project>Properties>Linker>Additional库目录中也提供dll以使编译的程序运行。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47664510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档