int main(void)
{
int fd;
int nread,nwrite,i;
char buff[32];
char reply[128];
char gsmMessage[20] = "Hello!";
if((fd=open_port(fd,2))<0){
perror("open_port error");
return -1;
}
if((i=set_opt(fd,115200,8,'N',1))<0){
perror("set_opt error");
return -1;
}
printf("fd=%d\n",fd);
memset(buff,0,sizeof(buff));
buff[0] = 'A';
buff[1] = 'T';
buff[2] = '\r';
nwrite = write(fd,buff,3);
printf("nwrite=%d,%s\n",nwrite,buff);
memset(reply,0,sizeof(reply));
nread = read(fd,reply,sizeof(reply));
printf("nread=%d,%s\n",nread,reply);
memset(buff,0,sizeof(buff));
strcpy(buff,"AT+CMGF=1");
strcat(buff,"\r");
nwrite = write(fd,buff,10);
printf("nwrite=%d,%s\n",nwrite,buff);
memset(reply,0,sizeof(reply));
nread = read(fd,reply,sizeof(reply));
printf("nread=%d,%s\n",nread,reply);
memset(buff,0,sizeof(buff));
strcpy(buff,"AT+CMGS=");
strcat(buff,"136");
strcat(buff,"\r");
nwrite = write(fd,buff,strlen(buff));
printf("nwrite=%d,%s\n",nwrite,buff);
memset(reply,0,sizeof(reply));
nread = read(fd,reply,sizeof(reply));
printf("nread=%d,%s\n",nread,reply);
strcat(gsmMessage, "\x1a");
nwrite = write(fd,gsmMessage,7);
printf("nwrite=%d,%s\n",nwrite,gsmMessage);
memset(reply,0,sizeof(reply));
nread = read(fd,reply,sizeof(reply));
printf("nread=%d,%s\n",nread,reply);
close(fd);
return 0;
}
gprs_sms_linuxSRC.rar
需积分: 9 49 浏览量
2009-01-08
11:37:15
上传
评论
收藏 2KB RAR 举报
辛鹤
- 粉丝: 272
- 资源: 978