Toll-Free Customer Support 24/7

GSM MODEM USB

/*
* Project name:
GSM "SENDING MESSAGE EXAMPLE"
* Copyright
(c) Researchdesignlab.com
* Test configuration:
BOARD: RASPBERRY PI & BEAGLEBONE
Software: ECLIPSE

*/

 

#include <stdio.h>
#include <stddef.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>

unsigned char rx_buffer[10];
unsigned char test[64];
unsigned char number[64];
int count,i,flag,k;

int main()
{

FILE *ofp_uart1_tx, *ofp_uart1_rx;


termios uart1;
int fd,f;
int m,n,d,e,a,b,c,q,r,x,y,z,t,u,o;

//IN CASE OF RASPBERRY PI THE FILE NAME IS /dev/AMA0

if((fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY )) < 0)
{
printf("Unable to open uart1 access.\n");
}

if(tcgetattr(fd, &uart1) < 0)
{
printf("Could not get attributes of UART1 at ttyO1\n");
}

if(cfsetospeed(&uart1, B9600) < 0)
{
printf("Could not set baud rate \n");
}
else
{
printf("Baud rate: 9600\n");
}

uart1.c_iflag = 0;
uart1.c_oflag = 0;
uart1.c_lflag = 0;
tcsetattr(fd, TCSANOW, &uart1);
tcflush(fd,TCIFLUSH);

printf("AT\r\n");
d = write(fd, "AT", 2);
sleep(2);
a = write(fd, "\r", 1);
b = write(fd, "\n", 1);
sleep(2);
printf("AT+CMGF=1\r\n");
d = write(fd, "AT+CMGF=1", 9);
sleep(2);
a = write(fd, "\r", 1);
b = write(fd, "\n", 1);
sleep(2);
printf("AT+CMGS=/"8123902188/"\r\n");
x = write(fd, "AT+CMGS=/"8123902188/"", 20);
sleep(2);
y = write(fd, "\r", 1);
z = write(fd, "\n", 1);
sleep(2);
printf("HELLO");
x = write(fd, "HELLO",5);
sleep(2);
y = write(fd, "\x1A", 1);
sleep(2);

close(fd);

}

Back to top