gpt4 book ai didi

c++ - 未声明的 FTDI 标识符

转载 作者:行者123 更新时间:2023-11-28 04:53:35 24 4
gpt4 key购买 nike

我正在尝试基本的 FTDI 编码,这里有一个简单的程序,应该能够从单个 FTDI 设备读取字节:

#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 Studios 说所有用于声明变量的标识符(unsigned long int 除外)都是未声明的:

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

...等等

我没有发现我的代码或包含的头文件有任何语法错误;怎么了?

最佳答案

看起来 Visual Studio 找不到您的库。您可以在 Project>Properties>C/C++>General>Additional Include Directories 中添加它们 (VS 2017)。

记得在 Project>Properties>Linker>Additional Library Directories 中也提供 dll 以使编译后的程序运行。

关于c++ - 未声明的 FTDI 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47664510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com