串行编程(硬件握手) [英] Serial programming (hardware handshake)
问题描述
我想编程使用C / C ++使用硬件握手在linux串行通信。实现了握手的信号是CTS(清除发送)和RTS(请求发送)。目前我设置的CTS信号的功能如下所示:
I'm trying to to program a serial communication using hardware handshake in linux using C/C++. The signals that implement the handshake are CTS (Clear to send) and RTS (Request to send). Currently my function for setting the CTS signal looks as follows:
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 的是端口的文件描述符的值的是信号要设置的值。至code这个功能我根据 HTTP:// WWW。 easysw.com/~mike/serial/serial.html#5_1 。
where fd is the file descriptor for the port and value is the value to be set for the signal. To code this function I based on http://www.easysw.com/~mike/serial/serial.html#5_1.
问题是,的gcc 的不承认任何示例中使用的常量。有什么建议?
The problem is that gcc does not recognize any of the constants used in the example. Any suggestions?
- 更新 -
我已经找到了答案。展望另一个例子, SYS / ioctl.h
声明常量。
I've found an answer. Looking to another example, sys/ioctl.h
declares the constants.
推荐答案
这可能不适用于您的特定应用程序,但我想我会在这里发布的情况下,它可以帮助你或别人搜索。
This may not be applicable for your particular application, but I thought I'd post it here in case it helps you or someone else searching.
在与的termios
大多数系统中,可以设置在 CRTSCTS
标志 - > c_cflags
传递给 tcsetattr
,并具备了的termios
结构成员内核或硬件做RTS / CTS流量控制你。
On most systems with termios
, you can set the CRTSCTS
flag in the ->c_cflags
member of the termios
structure that you pass to tcsetattr
, and have the kernel or hardware do the RTS/CTS flow control for you.
(这不是POSIX,但因此它的它的两个BSD和衍生的SystemV系统几乎无处不在 - 包括Linux)。
(It's not POSIX, but it's on both BSD and SystemV derived systems so it's almost everywhere - including Linux).
这篇关于串行编程(硬件握手)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!