gprs_sms_linux.txt

来自「GPRS SMS sample source code」· 文本 代码 · 共 53 行

TXT
53
字号
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;
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?