gsm - output of AT command c++ code -
i wrote following code sends simple message mobile gsm sm5100b. not work. check outputs of each printf line c++ code. example
at+cmfg=1 ok at+cmgs="69******" ok
etc. there why implement this?
my code
#include <stdio.h> // standard input / output functions #include <string.h> // string function definitions #include <unistd.h> // unix standard function definitions #include <fcntl.h> // file control definitions #include <errno.h> // error number definitions #include <termios.h> // posix terminal control definitionss #include <time.h> // time calls int open_port(void) { int fd; // file description serial port fd = open("/dev/ttyama0", o_rdwr | o_noctty | o_ndelay); if(fd == -1) // if open unsucessful { printf("open_port: unable open /dev/ttyama0. \n"); } else { fcntl(fd, f_setfl, 0); printf("port open.\n"); } return(fd); } //open_port int configure_port(int fd) // configure port { struct termios port_settings; // structure store port settings in cfsetispeed(&port_settings, b9600); // set baud rates cfsetospeed(&port_settings, b9600); port_settings.c_cflag &= ~parenb; // set no parity, stop bits, data bits port_settings.c_cflag &= ~cstopb; port_settings.c_cflag &= ~csize; port_settings.c_cflag |= cs8; tcsetattr(fd, tcsanow, &port_settings); // apply settings port return(fd); } void init_gsm() { printf("at+cmgf=1\r\n"); sleep(3); printf("at+cmgs=\"+34603****\"\r\n"); sleep(3); //printf("hello\r\n%c",26); printf("hello\x1a"); sleep(3); // printf("\x1a"); } int main(void) { int fd = open_port(); configure_port(fd); sleep(5); //query_modem(fd); init_gsm(); return(0); }
most seriously, not waiting final result code after sending @ command. using sleep
not valid solution. must fix proper parsing of response modem. see following answers more details, answer 1, answer 2.
then init_gsm
function ought have int fd
argument use sending @ commands reading response from.
Comments
Post a Comment