利用GSM模块SIM100开发短信收发系统.docx

上传人:b****6 文档编号:12915169 上传时间:2023-06-09 格式:DOCX 页数:9 大小:78.55KB
下载 相关 举报
利用GSM模块SIM100开发短信收发系统.docx_第1页
第1页 / 共9页
利用GSM模块SIM100开发短信收发系统.docx_第2页
第2页 / 共9页
利用GSM模块SIM100开发短信收发系统.docx_第3页
第3页 / 共9页
利用GSM模块SIM100开发短信收发系统.docx_第4页
第4页 / 共9页
利用GSM模块SIM100开发短信收发系统.docx_第5页
第5页 / 共9页
利用GSM模块SIM100开发短信收发系统.docx_第6页
第6页 / 共9页
利用GSM模块SIM100开发短信收发系统.docx_第7页
第7页 / 共9页
利用GSM模块SIM100开发短信收发系统.docx_第8页
第8页 / 共9页
利用GSM模块SIM100开发短信收发系统.docx_第9页
第9页 / 共9页
亲,该文档总共9页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

利用GSM模块SIM100开发短信收发系统.docx

《利用GSM模块SIM100开发短信收发系统.docx》由会员分享,可在线阅读,更多相关《利用GSM模块SIM100开发短信收发系统.docx(9页珍藏版)》请在冰点文库上搜索。

利用GSM模块SIM100开发短信收发系统.docx

利用GSM模块SIM100开发短信收发系统

利用GSM模块SIM100开发短信收发系统

利用GSM模块SIM100开发短信收发系统

利用GSM模块SIM100开发短信收发系统

一.引言

在开发远程通讯控制系统时,利用现有的GSM网络是一个很不错的选择。

这里利用PC串口控制GSM SIM100模块进行收发短消息来实现远程通讯。

二.SIM100通讯协议

1.COM1或COM2 以 9600,N,8,1格式通讯

2.DTR和RTS须置有效。

3.打开监控软件后,须对TE(terminal  equipment)初始化。

AT CR(0x0d),LF(0x0a)反馈:

xxOKxx

ATE0 CR(0x0d),LF(0x0a)反馈:

xxOKxx

ATS0=0 CR(0x0d),LF(0x0a)反馈:

xxOKxx

AT+COPS?

(0x0d),LF(0x0a)反馈:

中查到"CHINA MOBILE"

m_MSComm.SetDTREnable(true);

pFrame->m_wndStatusBar.SetPaneText(2,strCOM+":

没有打开!

"

;

if(!

m_MSComm.GetPortOpen())

{

m_MSComm.SetPortOpen(true);

m_bPortOpen=true;

pFrame->m_wndStatusBar.SetPaneText(2,strCOM+":

已就绪!

"

;

}

}

2.读缓冲区长度

short CMainInfoView:

:

GetBufferSize(void)

{

return m_MSComm.GetInBufferCount();

}

3.读缓冲区内容

CString CMainInfoView:

:

GetBufferString(void)

{

VARIANT variant_inp;

COleSafeArray safearray_inp;

LONG len,k;

BYTE rxdata[2048];

variant_inp=m_MSComm.GetInput();

safearray_inp=variant_inp;

len=safearray_inp.GetOneDimSize();

for(k=0;k

{

safearray_inp.GetElement(&k,rxdata+k);

}

CString strTmp,strRecv;

for(k=0;k

{

BYTE bt=*(char*)(rxdata+k);

strTmp.Format("%c",bt);

strRecv+=strTmp;

}

return strRecv;

}

4.发送短消息

bool CMainInfoView:

:

SendShortMessage(CString strNum, CString strMsg)

{

int i,j;

CString strReceive;

char ch1[10]={0x0d,0x0a,0x00};

CString strNumCR=CString(ch1);

char ch2[10]={0x1a,0x0d,0x0a,0x00};

CString strMsgCR=CString(ch2);

CString strSend;

strSend="AT+CMGS=\""+strNum+"\""+strNumCR;

m_MSComm.GetInput();

m_MSComm.SetOutput(COleVariant(strSend));

Sleep(100);

for(i=0;i<10;i++)

{

Sleep(100);

if(GetBufferSize()>0)

{

Sleep(100);

strReceive=GetBufferString();

if(-1!

=strReceive.Find('>'))

{

strSend=strMsg+strMsgCR;

m_MSComm.GetInput();

m_MSComm.SetOutput(COleVariant(strSend));

Sleep(500);

for(j=0;j<50;j++)

{

Sleep(100);

if(GetBufferSize()>=2)

{

Sleep(200);

strReceive=GetBufferString();

if(-1!

=strReceive.Find("OK"

{

//"发送短消息成功!

"

return true;

}

else

{

break;

}

}

else

{

continue;

}

}

//发送短消息失败:

没有OK"

return false;

}

else

{

break;

}

}

else

{

continue;

}

}

//"发送短消息失败:

没有>"

return false;

}

5.阅读短消息

bool CMainInfoView:

:

ReadShortMessage(CString& strReceived, int nLocation)

{

if(nLocation<0||nLocation>9)

{

MessageBox("Error:

ReadShortMessage:

nLocation error!

"

;

return false;

}

CMainFrame*pFrame=(CMainFrame*)AfxGetMainWnd();

char chCMGR[20]={'A','T','+','C','M','G','R','=','0',0x0d,0x0a,0x00};

CString strTemp;

chCMGR[8]='0'+nLocation;

CString strSend=CString(chCMGR);

m_MSComm.GetInput();

m_MSComm.SetOutput(COleVariant(strSend));

Sleep(400);

for(int i=0;i<20;i++)

{

Sleep(100);

if(GetBufferSize()>=2)

{

Sleep(500);

strReceived=GetBufferString();

if(-1!

=strReceived.Find("CMGR"

 && -1!

=strReceived.Find("OK"

 

{

//"读短消息成功!

"

}

else

{

//"读短消息失败:

空信息!

"

}

return true;

}

}

//"读短消息失败:

没有回应!

"

return false;

}

6.删除

bool CMainInfoView:

eleteShortMessage(int nLocation)

{

if(nLocation<0||nLocation>9)

{

MessageBox("Error:

ReadShortMessage:

nLocation error!

"

;

return false;

}

char chCMGD[20]={'A','T','+','C','M','G','D','=','0',0x0d,0x0a,0x00};

CString strReceive;

chCMGD[8]='0'+nLocation;

CStringstrSend=CString(chCMGD);

m_MSComm.SetOutput(COleVariant(strSend));

Sleep(100);

for(int i=0;i<20;i++)

{

Sleep(100);

if(GetBufferSize()>=2)

{

Sleep(100);

strReceive=GetBufferString();

if(-1!

=strReceive.Find("OK"

{

//"删除短消息:

OK"

}

else

{

//"删除短消息:

ERROR 321!

"

}

return true;

}

continue;

}

//"删除短消息:

超时!

"

return false;

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2