天嵌 ARM开发社区

 找回密码
 注册
查看: 2122|回复: 7

我买的GPRS 发短信程序 大家帮忙看看哪里有问题

[复制链接]
doublezxh 发表于 2011-2-17 14:08:24 | 显示全部楼层 |阅读模式
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>

int main(void)
{
   int fd;
   char sendmsg[] = "your car has been stolen! the position is:";
   struct termios oldtio,newtio;
   fd = open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);

   if( -1 == fd )
   {
      perror("can't open the serial port!");
      return -1;
   }

   if( tcgetaddr( fd,&oldtio ) != 0)
   {
       perror( "setup serial!" );
       return -1;
   }
   
   bzero( &newtio,sizeof(newtio) );
   newtio.c_cflag |= CLOCAL | CREAD;
   cfsetispeed( &newtio,B115200 );
   cfsetospeed( &newtio,B115200 );
   newtio.c_cflag &= ~CSIZE;
   newtio.c_cflag |= CS8;
   newtio.c_cflag &= ~PARENB;
   newtio.c_cflag &= ~CSTOPB;
   newtio.c_cc[VTIME] = 0;
   newtio.c_cc[VMIN] = 0;
   tcflush( fd,TCIFLUSH );

   if( ( tcsetattr( fd,TCSANOW,&newtio) ) )
   {
       perror("com set error!");
       return -1;
   }

   write( fd,"AT+CMGF=1",8 );//设置文本格式
   sleep(1);
   write( fd,"AT+CMGS=+8613800451500\r",23 );  //设置哈尔滨短信服务中心
   sleep(1);
   write( fd,"AT+CMGS=861390451234\r",20 ); //设置接收个人号码
   sleep(1);
   write( fd,sendmsg,sizeof(sendmsg) );// 发送英文短信
   sleep(1);
   write( fd,"\x01a",1);//发送CTRL+Z的ascii码
   sleep(3);
   close(fd);
   return 0;
天嵌_support1 发表于 2011-2-17 15:13:52 | 显示全部楼层
对不住网友呀,我不懂GPRS,但愿有人能和你分享
uboard 发表于 2011-2-18 13:56:22 | 显示全部楼层
不知道捏........................
lzw_happy 发表于 2011-2-18 17:22:01 | 显示全部楼层
CTRL+Z的ascii码是0x0d,0x1A
xstone 发表于 2011-3-24 10:04:59 | 显示全部楼层
文本格式怎么觉得不用设置短信中心的号码呀
xstone 发表于 2011-3-24 10:18:39 | 显示全部楼层
如果要写短信中心的话,也是用AT+CSCA指令吧
zbb564833642 发表于 2012-1-26 23:59:21 | 显示全部楼层
路过 帮顶  
lpdpzc 发表于 2012-1-30 21:56:37 | 显示全部楼层
这个驱动很简单的,我有C8051的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-10-5 14:27 , Processed in 1.027278 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表