hey frns pls help me out !!
i hav a code of c that i have to include in my project.
i am using a device (geomeda) that has unix based OS. it also support SIM card for connecting to server . I need to send SMS to user from this device..
below code is not working .. i am unable to send sms and the read system call is always returning 1.
/* terminal flags are set in above part of code*/
tty_fd=open(argv[1], O_RDWR | O_NONBLOCK);//argv[1] is /dev/modem
unsigned char buff_in[255];
unsigned char buff_out[255];
memset(buff_out,'\0',sizeof(buff_out)) sprintf(buff_in,"AT\r");
int m = write(tty_fd,buff_in,strlen(buff_in));
memset(buff_out,'\0',sizeof(buff_out));
if (read(tty_fd,&buff_out,2)>0)
{
printf("\nRead from tty_fd sucess");
if(strncmp(buff_out,"OK",2)==0)
{
printf("\nConnection with Modem works Fine");
}else
{
printf("\nError in connection with modem");
return 0;
}
}
memset(buff_in,'\0',sizeof(buff_in));
sprintf(buff_in,"AT+CMSS=1\r");
write(tty_fd,&buff_in,sizeof(buff_in));
memset(buff_out,'\0',sizeof(buff_out));
if (read(tty_fd,&buff_out,2)>0)
{
if(strcmp(buff_out,"OK")==0)
{
printf("\nSIM supports SMS services");
}else
{
printf("\nSIM do not supports SMS services");
return 0;
}
}
memset(buff_in,'\0',sizeof(buff_in));
sprintf(buff_in,"AT+CMGS=\"+91xxxxxxxx\"\r");
write(tty_fd,buff_in,strlen(buff_in));
sleep(5);
memset(buff_in,'\0',sizeof(buff_in));
sprintf(buff_in,"Hello SMS Test\r\x1A\r");
write(tty_fd,buff_in,strlen(buff_in));
memset(buff_out,'\0',sizeof(buff_out));
if (read(tty_fd,&buff_out,35)>0)
{
int value = buff_out[7];
printf("\n Value of buff_out[7] is :- %d",value);
if(value <0 || value >255)
{
printf("\nError in sending msg");
return 0;
}else
{
printf("\nMsg sent Sucessfully");
}
} close(tty_fd);
return 0;
}
But this code is not working .. i am unable to send sms .. and the read system call always returning -1
please help me !!