sms - C++ code to send messages with GSM -


i connected raspberry pi sm5100b gsm. test sending simple message in mobile. can emulators cutecom , minicom (because have raspbian linux version). there code in c++ job? not use arduino, sm5100b. wrote code until , of course not work yet

 #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 {     //perror("open_port: unable open /dev/ttyama0 - ");     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);   } //configure_port   int query_modem(int fd)   // query modem @ command  { char n; fd_set rdfs; struct timeval timeout;  // initialise timeout structure timeout.tv_sec = 10; // ten second timeout timeout.tv_usec = 0;   unsigned char send_bytes[] = "at+cmgf=1";      unsigned char send_bytes1[] = "at+cmgs=\"603*****\"";      unsigned char send_bytes3[] = "test";     // puts(send_bytes); write(fd, send_bytes, 13);  //send data      write(fd, send_bytes1, 13);      write(fd, send_bytes3, 13); //printf("wrote bytes. \n");  // select n = select(fd + 1, &rdfs, null, null, &timeout);  // check if error has occured if(n < 0) {  perror("select failed\n"); } else if (n == 0) {  puts("timeout!"); } else {  printf("\nbytes detected on port!\n"); }  return 0;      } //query_modem   int main(void)  {  int fd = open_port(); configure_port(fd); query_modem(fd); return(0);   } //main 

open relevant serial port (/dev/ttysx, x number), use write or fwrite write port, close port, exit program.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -