当前位置: 技术问答>linux和unix
Linux下发送短信问题,急死了!!!
来源: 互联网 发布时间:2017-02-17
本文导语: 采用的是西门子的tc35,用串口线之间连的pc机,想写个c程序进行发送短信 我是这样发送的短信(text模式) char cmd1[] = "ATr"; char cmd2[] = "AT+CMGF=1r"; char cmd3[] = "AT+CSCA=+8613800635500r"; char cmd4[] = "AT+CMGS=13562049562r"; ch...
采用的是西门子的tc35,用串口线之间连的pc机,想写个c程序进行发送短信
我是这样发送的短信(text模式)
char cmd1[] = "ATr";
char cmd2[] = "AT+CMGF=1r";
char cmd3[] = "AT+CSCA=+8613800635500r";
char cmd4[] = "AT+CMGS=13562049562r";
char cmd5[] = "tao shi gou shi";
char cmd6[] = "0x1Ar";//这里可能有问题!!!
printf("write: %dn", write(fd, cmd1, sizeof(cmd1)));
sleep(2);
printf("write: %dn", write(fd, cmd2, sizeof(cmd2)));
sleep(2);
printf("write: %dn", write(fd, cmd3, sizeof(cmd3)));
sleep(2);
printf("write: %dn", write(fd, cmd4, sizeof(cmd4)));
sleep(2);
printf("write: %dn", write(fd, cmd5, sizeof(cmd5)));
sleep(2);
printf("write: %dn", write(fd, cmd6, sizeof(cmd6)));
sleep(2);
在超级终端和minicom中输入前五个命令,然后ctrl-z,回车,能发送成功
可是在程序中,前五个命令执行都成功,到最后一个命令的时候(红色部分)就会出错
0x1A是ctrl-z的十六进制啊,怎么就不行呢???
怎么从程序中执行ctrl-z呢?
怎么才能执行成功???请各位帮帮忙啊
我是这样发送的短信(text模式)
char cmd1[] = "ATr";
char cmd2[] = "AT+CMGF=1r";
char cmd3[] = "AT+CSCA=+8613800635500r";
char cmd4[] = "AT+CMGS=13562049562r";
char cmd5[] = "tao shi gou shi";
char cmd6[] = "0x1Ar";//这里可能有问题!!!
printf("write: %dn", write(fd, cmd1, sizeof(cmd1)));
sleep(2);
printf("write: %dn", write(fd, cmd2, sizeof(cmd2)));
sleep(2);
printf("write: %dn", write(fd, cmd3, sizeof(cmd3)));
sleep(2);
printf("write: %dn", write(fd, cmd4, sizeof(cmd4)));
sleep(2);
printf("write: %dn", write(fd, cmd5, sizeof(cmd5)));
sleep(2);
printf("write: %dn", write(fd, cmd6, sizeof(cmd6)));
sleep(2);
在超级终端和minicom中输入前五个命令,然后ctrl-z,回车,能发送成功
可是在程序中,前五个命令执行都成功,到最后一个命令的时候(红色部分)就会出错
0x1A是ctrl-z的十六进制啊,怎么就不行呢???
怎么从程序中执行ctrl-z呢?
怎么才能执行成功???请各位帮帮忙啊
|
ctrl+z是不是终止符号啊
你直接关闭fd试试看呢
你直接关闭fd试试看呢
|
关注中。。。