为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > AT指令发送短信详解

AT指令发送短信详解

2018-03-26 9页 doc 30KB 28阅读

用户头像

is_731942

暂无简介

举报
AT指令发送短信详解AT指令发送短信详解 AT 指令发送短信详解和 C源程序AT指令发送短信详解和C源程 序...............................................................................................1 1( 介 绍.........................................................................................................................
AT指令发送短信详解
AT指令发送短信详解 AT 指令发送短信详解和 C源程序AT指令发送短信详解和C源程 序...............................................................................................1 1( 介 绍...........................................................................................................................2 2( 初始化设备...............................................................................................................2 2(1 选择串口通讯工具包.............................................................................................2 2(2 初始化.....................................................................................................................3 3. 发送短信..............................................................................................................................3 3(1 使用TEXT模式发送短信.......................................................................................3 3(2 使用PDU模式发送短信.........................................................................................4 4(接收短信.............................................................................................................................7AT 指令发送短信说明 version:0.5 IBMS1( 介绍 短信已经应用到我们工作生活的各个方面,但是使用手机发送短信的效率是很低的,为 了克服这个问题,我们把手机或是短信模块与 PC 相连接,发送短信,就能够能活的使用 短信服务强大方便的通讯功能。 我们公司在 TC35 模块的串口通讯基础上,通过 AT 指令开发发送接收短信的二次开发 包,满足现阶段的短信业务要求。 在开发的工作中,也遇到了很多的问题,费了不少了精力和时间,本文的目的是帮助后 继的开发人员快速的掌握 AT 指令开发短信发送程序,作为开发工程中的参考。 如果可能请先阅读以下的资料,有助于你理解 AT 指令: 1( 2( ( 4( 在后继的介绍中,我们重点讲解难点和我所遇到的问题,主要就是使用 PDU 格式发送短信和怎么设置不通过 SIM 卡进行数据传输。 注: 1. 部分知识来自以上的网站,为了保护其作者的权利,特此声明。 2. 短信二次开发的软件平台为 Visual C6.0 Windows 2000 Pro SP4IE6.0,硬件为 TC35 模块,以动态连接库的形式提供给用户使用。 3(本文将结合一个具体的类为大家讲解。 4. 还为大家介绍了 Unicode 的转换。2( 初始化设备2(1 选择串口通讯工具包 使用 MSComm.ocx 控件通讯,这是最简单的通讯方式,但是不能满足在这个 地方的需求, 在开发项目开始的时候我也是习惯性使用的这个控件,但是在以 后的调试的过程中发现,它没有异步接收的功能,所以在同一个线程中,无法 收到发送的结果,让我郁闷了好几天。如果你不需要很复杂的控制,这个方式 也是可行的。 使用串口 API 通讯,这是很灵活的方式,网络上有很多优秀的的串口通讯封 装类。如果你要自己写,那么你一定很有时间,而且我相信你能学到比我多很 多的东西。 上面的网址就介绍了一个很不错的串口操作类。深圳太极软件公司 作者:邓杨均顺德太极智能化技术开发有限公司 Page 2 of 16 2004-1-15AT 指令发送短信说明 version:0.5 IBMS2(2 初始化 安装好 TC35 模块,然后选择一个通讯的串口和一定的频率,先用串口调式工具,把一般的 AT 指令都试一遍,一般来说,这些步骤都是没有问题的。如果有问题,请马上和硬件供应商联系。3. 发送短信 发送短信有两种方式:TEXT 和 PDU 模式,前一种模式非常的简单,如果你只是传输数据,而不需要使用中文,就使用 TEXT 模 式就可以了。如果你需要在短信中使用中文就必须用 PDU 模式。下面的程序为了 简单使用的同步机制,如果你想要完全控制整个的过程,请使用串口 API 异步的 接收数据。3(1 使用 TEXT 模式发送短信1( 首先设置模式为TEXT模式: ATCMGF1ltCRgt 1,成功执行,TE2返回OK,否则返回 ERROR。2( 然后使用: ATCMGS”8613802637519”ltCRgt,TE 返回gt,就可以输入短信的内容了。 短信的 内容为:datactrl_Z,ctrl_Z ACS?中的值为 26,意思是输入结束。如果你输入 了不 是 ACS?字符数据,那么发送将会失败。下面是发送模块的一部分,讲述了怎么 发 送 TEXT 短信.case TEXT: //ensure sending data only contains acs2 CString sCommand ifTEXTm_currentMode sCommandquotATCMGF1rquot //TEXT mode m_currentModeTEXT ExecCmdsCommand Sleep200 //wait TE Executed return sCommand.FormatquotATCMGSquotsquotrquotdestAddr ExecCmdsCommand Sleep200 ifm_sComDataquotgtquot1 代表换行符,在C语言中为‘/r’。2 TE:Terminal Equipment,终端设备,代表TC35 模块。深圳太极软件公司 作者:邓杨均顺德太 极智能化技术开发有限公司 Page 3 of 16 2004-1-15AT 指令发送短信说明 version:0.5 IBMS //return FALSE sCommanduserData int lengthsCommand.GetLength iflengthgt140 //the Max length of the sending data sCommandsCommand.Left140 //add end char ctrl_z26 sCommandctrl_z ExecCmdsCommand Sleep4500 //wait 4.5 seconds break 3(2 使用 PDU 模式发送短 信 这个是本文的重点。1( 设置输入模式为 PDU:ATCMGF0ltCRgt,成功执行, TE 返回 OK,否则返回 ERROR。2( AT指令:ATCMGSltlength3gtltCRgt,成功 执行,系统返回gt,然后输入PDUctrl_Z 问题的关键就是 PDU 编码。介绍这个方 面的的资料很多,不过都是讲了我也是没有太 懂,它们也就是把 PDU 讲了一 遍,我仍然是很迷茫,后来经过很多次痛苦的尝试, 终于成功的发送了一条中文的 短信。3( 先给出生成 PDU 数据这部分的源程序。/ Class : CGModem Function : HandleResponse Description: Handle the answer string Parameters : sDestAddr: the phone number who receive the SM userData: the content of the sm nDataLength: the length of the PDU exclude the CSCA Return :/CString CGModem::CreatePduSmsCString sDestAddrCString userData UINT nDataLength3 这 个参数和函数CreatePduSms的nDataLength是一致的。深圳太极软件公司 作者:邓 杨均顺德太极智能化技术开发有限公司 Page 4 of 16 2004-1-15AT 指令发送短信说 明 version:0.5 IBMS CString sResult sResultquot00quot //固定格式 sResultquot1100quot //固定格式 //address style sResultquot0D91quot char sNO20 memsetsNO0sizeofsNO strcpysNOsDestAddr //normal address format to BCD format sResultto_BCDsNOsDestAddr.GetLength sResultquot00quot //TP-PID sResultquot08quot //TP-DCSUCS2 sResultquotA7quot //TP-Validity-Period char sMS160 strcpysMSuserData int lengthuserData.GetLength userDatato_UCS2sMSuserData.GetLength lengthuserData.GetLength CString sLetter //UCS2 to int string forint i0 iltuserData.GetLengthi sLetterInt2HexStringBYTEuserData.GetAti sResultInt2HexStringsLetter.GetLength/2 sResultsLetter sResult.MakeUpper sResult.TrimLeft nDataLengthsResult.GetLength/2-1 return sResult 这个函数使用了几个公共的函数,为了不干扰主题,在文章的最后, 我们会给出这些函数。然后在发送模块中调用这个函数。深圳太极软件公司 作者: 邓杨均顺德太极智能化技术开发有限公司 Page 5 of 16 2004-1-15AT 指令发送短信 说明 version:0.5 IBMS case UDP ://default UINT nDataLength0 CString sDataCreatePduSmsdestAddruserDataampnDataLength CString sCommand ifUDPm_currentMode sCommandquotATCMGF0rquot //UDP Mode m_currentModeUDP ExecCmdsCommand Sleep100 sCommand.FormatquotATCMGSdrquotnDataLength ExecCmdsCommand Sleep200//wait execute return ifm_sComData.Findquotgtquot // return FALSE sCommandsData //the end character char ctrl_z26 sCommandctrl_z int iSizem_commandSet.GetSize ExecCmdsCommand Sleep4500 //wait 4.5 seconds break 4(发送短信函数的原型为:/ Class : CGModem Function : SendSms Description: Send a Short message by AT command Parameters : destAddr: the mobile number who recive the SM深圳太极软件公司 作者:邓杨均顺德太极智能化技术开发有限公司 Page 6 of 16 2004-1-15AT 指令发送短信说明 version:0.5 IBMS userData: the content of SM nSmsFormat: UDP in UDP Mode default TEXT in TEXT Mode Return :/BOOL CGModem::SendSmsLPCTSTR destAddr LPCTSTR userData UINT nSmsFormat/UDP/调用这个函数,就可以发送短信了。 比如:SendSmsquot8613802637519quotquot你 好,世界quot,就会往串口传输如下的数据: ATCMGS25ltcrgt0011000D91683108627315F90008A70A4F60597DFF0C4E16754Cltctrl_Zgt4(接收短信 如果你需要 TE 有新的短信的时候提醒你,可以在初始化设备 的时候,写入命令:ATCNMI11001ltCRgt 就 可 以 在 新 的 信 息 到 来 的 时 候 , 提 醒 你 。 然 后 使 用ATCMGRltindexgtltCRgt读取短信。Index 是短信 在 TE 中存储的位置索引。可以从新短信的到达的提示中获得这个索引,也可以使 用 CMGL 列出各种类型的短信,详细的使用你可以参看 AT 指令集。 接收 的关键是在于解析 UDP 数据。我们下面给出这个函数:函数返回结构体:struct STRU_SMS int iIndex char cSender20 char cTimeStamp24 char cMessage160 int iProperty // REC UNREAD 1:REC READ 2:STO UNSENT 3:STO SENT int iMemClass/ Class : CGModem Function : ResolvePduSm Description: Resolve UDP format data Parameters : sReceiveData: the UDP data iLength: the length of valid UDP data exclude the CSCA address iProperty: indicate the states of message in memory iCurrentIndex: the index of sm to resovle Return : sm struct contained the all information/STRU_SMS CGModem::ResolvePduSmCString sReceiveData int iLength int iProperty intiCurrentIndex深圳太极软件公司 作者:邓杨均顺德太极智能化技术开 发有限公司 Page 7 of 16 2004-1-15AT 指令发送短信说明 version:0.5 IBMS //the data is cant empty. ASSERT0sReceiveData.GetLength STRU_SMS newSm memsetampnewSm0sizeofSTRU_SMS //initialize newSm.iIndexiCurrentIndex newSm.iPropertyiProperty //Get Valid data CString sDatasReceiveData.RightiLength2 //Get Sender number---------------------------------------- //Get Address length int iLengthAddr ifquot0DquotsData.Mid22 iLengthAddr13 else ASSERTFALSE CString sSendersData.Mid6iLengthAddr1 //extra F //BCD Transilation char cSender20 memsetcSender0sizeofcSender strcpycSendersSender sSenderfrom_BCDcSendersSender.GetLength //trim F sSender.TrimRightquotFquot strcpynewSm.cSendersSender //Get TimeStamp--------------------------------------------深圳 太极软件公司 作者:邓杨均顺德太极智能化技术开发有限公司 Page 8 of 16 2004-1-15AT 指令发送短信说明 version:0.5 IBMS int iCurPos6iLengthAddr1 iCurPos4 CString sTimeStampsData.MidiCurPos14 //the Time format: mm/dd/YYYY HH:MM:SS CString sYearExchangesTimeStamp.Mid02 sYearquot20quotsYear //2000 year later CString sMonthExchangesTimeStamp.Mid22 CString sDayExchangesTimeStamp.Mid42 CString sHourExchangesTimeStamp.Mid62 CString sMinuteExchangesTimeStamp.Mid82 CString sSecondExchangesTimeStamp.Mid102 sTimeStamp.Formatquots/s/s s:s:squot sMonth sDay sYear sHour sMinute sSecond //Aleady Get stamp time strcpynewSm.cTimeStampconst char sTimeStamp //Get content----------------------------------------------- iCurPos16 //jump the time data and length data char cContent108 //the maxsize of 54x2 letterthe char buffer memsetcContent0sizeofcContent CString sContentsData.RightsData.GetLength-iCurPos forint i0 iltsContent.GetLength/2 i cContentiBYTEahtoiconst char sContent.Midi22 sContentto_MultiBytecContentsContent.GetLength/2 strcpynewSm.cMessage sContent TRACEquotSender:dquotsSender return newSm深圳太极软件公司 作者:邓杨均顺德 太极智能化技术开发有限公司 Page 9 of 16 2004-1-15AT 指令发送短信说明 version:0.5 IBMS附录 A:通用转换函数/ Copyright c 2003-2004Shenzhen TaiJi SoftWare All rights reserved. Name of the File: common.h symbol of the File: Summary: string transform Current Version: 1.0 Author: DengYangjun Created Date: 17:07 01-02-2004 Finished Date: Substitutional Version: Original Author: Finished Date:/ifndef _COMMON_H_define _COMMON_H_CString Int2Stringunsigned int nCString to_MultiBytechar strSM int nLengthCString to_UCS2char strSM int nLengthCString to_BCDchar strNormal int nLengthCString from_BCDchar strBCD int nLengthCString Int2HexStringBYTE nCString ampExchangeCString ampsOrgint ahtoiconst char pOrgendif // _COMMON_H_//-----------------------------------------------------------------------------------------------------------------/ Copyright c 2003-2004Shenzhen TaiJi SoftWare All rights reserved.深圳太极软件公司 作者:邓杨均顺德太极智能化技术开发有限公司 Page 10 of 16 2004-1-15AT 指令发送短信说明 version:0.5 IBMS Name of the File: common.cpp symbol of the File: Summary: string transform Current Version: 1.0 Author: DengYangjun Created Date: 17:07 01-02-2004 Finished Date: Substitutional Version: Original Author: Finished Date:/include quotstdafx.hquotinclude quotcommon.hquotinclude lt.
/
本文档为【AT指令发送短信详解】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索