【发布时间】:2009-08-14 19:01:19
【问题描述】:
我正在尝试使用 C/C++ 在 linux 中使用硬件握手对串行通信进行编程。实现握手的信号是 CTS(清除发送)和 RTS(请求发送)。目前我设置 CTS 信号的功能如下:
int setCTS(int fd, int value) {
int status;
ioctl(fd, TIOCMGET, &status); // get the current port status
if (value)
status |= TIOCM_CTS; // rise the CTS bit
else
status &= ~TIOCM_CTS; // drop the CTS bit
ioctl(fd, TIOCMSET, $status); // set the modified status
return 0;
}
其中fd 是端口的文件描述符,value 是要为信号设置的值。为了编写这个函数,我基于http://www.easysw.com/~mike/serial/serial.html#5_1。
问题在于 gcc 无法识别示例中使用的任何常量。有什么建议吗?
-- 更新--
我找到了答案。再看另一个例子,sys/ioctl.h 声明了常量。
【问题讨论】:
-
我发现 grep 对于回答这类问题很有用 - 只需搜索包含路径中的所有文件。
标签: c++ c linux serial-port