[英]How to send AT commands to serial port through C - Linux
Of course there is termios.h
, but here I am talking about AT
commands. 当然有
termios.h
,但是在这里我正在谈论AT
命令。 I want them to get executed . 我希望他们被处决 。
How to send AT commands to serial port through C
in Linux so that they get executed ? 如何在Linux中通过
C
将AT命令发送到串行端口, 以便它们得以执行 ?
Look at this brief example (it works): 看这个简单的例子(它可以工作):
struct termios options;
int fd;
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0)
{
printf("Error opening serial port\n");
exit(1);
}
bzero(&options, sizeof(options));
options.c_cflag = B9600 | CS8 | CLOCAL | CREAD | IGNPAR;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &options);
if (write(fd, "ATZ\r", 4) < 4)
{
printf("Write error - %s \n", strerror(errno));
exit (1);
}
// read back for OK or KO then do your stuff...
Stumbled across this, might help: 偶然发现这可能会有所帮助:
http://en.wikibooks.org/wiki/Serial_Programming/Serial_Linux http://en.wikibooks.org/wiki/Serial_Programming/Serial_Linux
Also the definitive guide for Advanced Linux Programming in C http://www.advancedlinuxprogramming.com/alp-folder/ 也是C语言中高级Linux编程的权威指南http://www.advancedlinuxprogramming.com/alp-folder/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.