0

当然有termios.h,但这里我说的是AT命令。我希望他们被处决

C如何通过Linux向串口发送 AT 命令以便执行

4

2 回答 2

3

看看这个简短的例子(它有效):

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...
于 2013-02-18T09:57:13.603 回答
1

偶然发现这一点,可能会有所帮助:

http://en.wikibooks.org/wiki/Serial_Programming/Serial_Linux

也是 C 语言高级 Linux 编程的权威指南 http://www.advancedlinuxprogramming.com/alp-folder/

于 2013-02-18T09:57:15.730 回答