466 #include #include #include #include #include #include #include #define AT_ATTN "+++" #define AT_RESET "ATZ\r" struct termios tty_old_settings, tty_settings; main() { int tty; unsigned char inchar; tty = open("/dev/cuaa2", O_RDWR); tcgetattr(tty, &tty_old_settings); tcgetattr(tty, &tty_settings); tty_settings.c_iflag &= ~(ICRNL | IXOFF | IXON); // tty_settings.c_iflag |= IGNCR; tty_settings.c_lflag &= ~(ECHO | ICANON | ISIG); tty_settings.c_cflag |= CRTSCTS; /* Hardware flow control! */ tty_settings.c_oflag &= ~OPOST; tty_settings.c_cc[VMIN] = 1; tty_settings.c_cc[VTIME] = 0; cfsetispeed(&tty_settings, B115200); cfsetospeed(&tty_settings, B115200); tcsetattr(tty, TCSAFLUSH, &tty_settings); write(tty, AT_ATTN, 3); sleep(1); write(tty, AT_RESET, 4); sleep(1); write(tty, AT_RESET, 4); sleep(1); while (read(tty, &inchar, 1) >0) { putchar(inchar); } tcsetattr(tty, TCSAFLUSH, &tty_old_settings); close(tty); } . 0