sending AT commands to wavecom through C code
Hi all,
I am testing sending sms through wavecom modem. I tested with minicom, its responding correctly.. commands are AT OK AT+CMGS="mobilenum" (then press Enter key) >"message" (then press ctrl+z) its sending sms properly. Same thing i want to implement using a code. I am able to open serial port and done initialization now i want to send AT COMMANDS to wavecom modem using C code. can any one provide sample code for this.(In this how to include Enter key and Ctrl+z keys.) Thanks in advance nathan |
Quote:
But I doubt that anyone is going to write code for you...also, there is LOTS of sample code on the Internet, for serial communication. Have you checked? |
Quote:
Hi, Here i am pasting my code. 1). I am using read and write commands? is it proper way of using ? any other method, instead of using read and write commands? kindly suggest me where i went wrong. int main() { unsigned char char1[10]; unsigned char char_buf[8]="AT+CSQ\n"; // unsigned char sms_buf[20] = "AT+CMGS="xxxxxxxxx"; int wc_fd; /********* Init of serial port ************/ wc_fd = init_wc(wc_fd); sleep(3); //writing to serial port write(wc_fd,char_buf,sizeof(char_buf)); usleep(40000); //reading from serial port read(wc_fd,char1,sizeof(char1)); sleep(2); close(wc_fd); return 0; } // end of main // initialization of serial port struct termios options; ttys5_fd = open("/dev/ttyS5", O_RDWR ); if (ttys5_fd < 0) { printf("\nFail to open serial port 2\n"); return 0; } init_tty( ttys5_fd ,BAUD_RATE); return ttys5_fd; ----------------------------------- //initializing baud rate int init_tty( int fd ,long wBaud) { long baud; switch (wBaud) { case 9600: baud = B9600; break; case 19200: baud = B19200; break; case 38400: baud = B38400; break; case 57600 : baud = B57600; break; case 115200: baud = B115200; break; default: return 0; break; } options.c_cflag = baud | CS8 | CREAD | CLOCAL; options.c_cflag &= ~HUPCL; options.c_lflag = 0; options.c_iflag = IGNPAR; options.c_oflag = 0; options.c_cc[VTIME] = 0; options.c_cc[VMIN] = 0; tcflush(fd, TCIFLUSH); /* flush the buffer */ /* apply the settings */ if(tcsetattr(fd, TCSANOW, &options) < 0){ /* apply the settings */ printf("initport: Error in setting serial port params in non-canonical mode\n"); return (-1); } else{ return 1; } } |
All times are GMT -5. The time now is 12:33 AM. |