作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当然有termios.h
,不过这里我说的是AT
命令。我希望他们被处决。
如何在 Linux 中通过 C
向串口发送 AT 命令并执行?
最佳答案
看看这个简短的例子(它有效):
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...
关于c - 如何通过C-Linux向串口发送AT命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14933311/
我是一名优秀的程序员,十分优秀!