C++ - 控制串行端口 - 代码无法编译

发布于 2024-11-05 15:05:58 字数 856 浏览 1 评论 0原文

我正在尝试让连接到串行端口的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月静好 2024-11-12 15:05:58
dcbSerial.DCBlength=sizeof(dcbSerialParams);

应该是:

dcbSerialParams.DCBlength=sizeof(dcbSerialParams);

真的,您将不得不付出更多的努力来阅读和理解编译器错误消息 - 该消息已经尽可能清晰了。

dcbSerial.DCBlength=sizeof(dcbSerialParams);

should be:

dcbSerialParams.DCBlength=sizeof(dcbSerialParams);

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.

爱的十字路口 2024-11-12 15:05:58

dcbSerial 替换为 dcbSerialParams

Replace dcbSerial with dcbSerialParams.

恏ㄋ傷疤忘ㄋ疼 2024-11-12 15:05:58

您已声明一个名为 dcbSerialParams 的变量,但将其引用为 dcbSerial

DCB dcbSerialParams = {0};
dcbSerial.DCBlength=sizeof(dcbSerialParams);

You have declared a variable with name dcbSerialParams, but refer to it as dcbSerial

DCB dcbSerialParams = {0};
dcbSerial.DCBlength=sizeof(dcbSerialParams);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文