C++ - 控制串行端口 - 代码无法编译
我正在尝试让连接到串行端口的 LED 亮起。我已按照分步教程进行操作,可以在此处找到该教程。我已完全按照说明进行操作,但无法编译代码。从 PDF 指南来看,它是未编译的第 2 部分,我在此处重现:
//<Set serial port parameters>
DCB dcbSerialParams = {0};
dcbSerial.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(hSerial, &dcbSerialParams))
{
//error getting state
}
dcbSerialParams.BaudRate=CBR_19200;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
if(!SetCommState(hSerial, &dcbSerialParams))
{
//error setting serial port state
}
//</Set serial port parameters>
我已将其包含在指定的代码中,但收到错误消息“`dcbSerial' 未声明(首先使用此函数)”。我正在使用 Dev-C++。
本质上,我想做的就是获取一个使 LED 闪烁的命令,我可以将其放入我拥有的另一个程序中(眼动追踪设备 - 这个想法是当你的眼睛注视它时让 LED 闪烁) )。
非常感谢任何帮助。
I am trying to get an LED connected to a serial port to light up. I have followed a step-by-step tutorial which can be found here. I have followed the directions exactly but cannot get the code to compile. From the PDF guide, it is part 2 which does not compile, which I reproduce here:
//<Set serial port parameters>
DCB dcbSerialParams = {0};
dcbSerial.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(hSerial, &dcbSerialParams))
{
//error getting state
}
dcbSerialParams.BaudRate=CBR_19200;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
if(!SetCommState(hSerial, &dcbSerialParams))
{
//error setting serial port state
}
//</Set serial port parameters>
I have included in the code as specified, but I receive the error message "`dcbSerial' undeclared (first use this function)". I am using Dev-C++.
Essentially all I am trying to do is get a command which flashes the LED on and off, which I can put into another program I have (an eye tracking device - the idea is to get the LED to flash when your eyes are looking at it).
Any help very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应该是:
真的,您将不得不付出更多的努力来阅读和理解编译器错误消息 - 该消息已经尽可能清晰了。
should be:
Really, you are going to have to put a bit more effort into reading and understanding compiler error messages - that one was about as clear as it gets.
将
dcbSerial
替换为dcbSerialParams
。Replace
dcbSerial
withdcbSerialParams
.您已声明一个名为
dcbSerialParams
的变量,但将其引用为dcbSerial
You have declared a variable with name
dcbSerialParams
, but refer to it asdcbSerial