嗨,我正在写一个小代码,以控制在Linux (Mint Linux13Maya,x86)上的USB到串口转换芯片FT232的DTR线和RTS线。
我已经成功地编写了使用termios对FT232芯片进行读写的代码。现在我想控制DTR和RTS行,所以我使用ioctl()调用来设置和清除DTR和RTS行。
以下是代码
#include <stdio.h>
#include <fcntl.h> /* File Control Definitions */
#include <termios.h> /* POSIX Terminal Control Definitions */
#include <unistd.h> /* UNIX Standard Definitions */
#include <errno.h> /* ERROR Number Definitions */
#include <sys/ioctl.h> /* ioctl() */
main(void)
{
int fd; /*File Descriptor*/
int status;
fd = open("/dev/ttyUSB0",O_RDWR | O_NOCTTY ); //Opening the serial port
ioctl(fd,TIOCMGET,&status); /* GET the State of MODEM bits in Status */
status |= TIOCM_RTS; // Set the RTS pin
ioctl(fd, TIOCMSET, status);
getchar(); //To view the change in status pins before closing the port
close(fd);
}我已经将两个LED连接到FT232的RTS和DTR线路上,由于RTS和DTR线路是反转的,所以设置RTS会使LED熄灭。连接到RTS和DTR的Led开始亮起。
在使用"sudo ./serial“运行代码时
RTS和DTR Led都熄灭,而不仅仅是RTS (如编码状态|= TIOCM_RTS;),并在getchar()之后接通。
为什么DTR会随着RTS线路一起走低?另外,我不能改变其他调制解调器线路,如RI,DCD,DCD,DTR等通过使用TIOCM_CD,TIOCM_DTR等?
发布于 2015-08-17 21:30:41
对于TIOCMSET命令,发送最后一个参数作为参考:
ioctl(fd, TIOCMSET, &status);https://stackoverflow.com/questions/27673344
复制相似问题