• EM310模块的之_AT指令的熟悉,AT指令操作流程


    简介:

    本文通过实例来熟悉发送短信的AT指令流程.

    ps.昨天晚上用hifeicat.com的板子,插上手机卡后,成功实现了发送短信.关键的一步是编辑完成短信后发送短信结束的操作(勾选十六进制发送,然后发送1a,即可正确结束短信编辑,并发送.)]

    • 串口工具
    • 串口发送字符的方式
    • 模块初始化流程
    • 短信发送流程
    • TCP连接发送数据流程
     视频演示地址
    http://v.youku.com/v_show/id_XNTM3NzA1MTEy.html
    http://v.youku.com/v_show/id_XNTM3NzA1OTY0.html
    http://v.youku.com/v_show/id_XNTM3NzA3MzQ4.html

    串口工具

    串口工具有:

    串口调试助手V2.2.exe

    TKSudio自带的串口助手.

    串口发送字符的方式

    1. ascii字符发送,这种方式是可以直观理解的发送方式.(默认的是这种发送方式)
    2. 十六进制发送方式,也就是HEX发送方式.

    下图ascii字符发送方式,

    *输入AT

    *回车

    *单击"手动发送"

    【注意】这里的"十六进制发送"这里没有选中.    image

    下面的是16进制发送方式

    【注意】首先勾选“十六进制发送”

    *输入41 54 0D

    (上面的三个为“AT 回车”的十六进制)

    *单击“手动发送”

    image

    image

    image

    可以看到发送"AT 回车"后

    EM310模块返回来的数据是:

    A,T,回车,回车,换行,o,k,回车,换行

    前面的"A,T,回车,"是我们发送的回显,然后"回车,换行",然后输出"OK",然后再"回车,换行".

    手机状态的查询与信号强度查询

    指令功能:手机SIM卡是否安装好

    指令为:AT+CPIN?回车

    指令功能:查看手机信号强度

    指令为:AT+COPS?回车

    指令功能:重启模块

    指令为:

    AT+CFUN=0

    AT+CFUN=1

    模块初始化流程

          • 确认串口正常 AT  //确认串口正常,模块出厂默认波特率=9600
          • 打开回显 ATE0 //打开回显(可以根据需要设置为0,关闭回显)
          • 检查SIM安装是否正常 AT+CPIN? //检查SIM工作是否正常
          • 关闭睡眠模式 AT%SLEEP=0 //关闭睡眠模式,睡眠后,可以降低功耗,但是睡眠后的第一条AT指令会不响应
          • GSM网络注册提示 AT+CREG=1//设置模块网络注册提示,当模块从GSM 网络中掉线后,会自动上报+CREG: 1,0   (后面的0表示掉线,如果是1表示在线.)
          • GSM网络注册状态 AT+CREG? //检查GSM 网络注册情况
          • 检查信号强度 AT+CSQ   //检查当地的网络信号强度,31最大,0最小
          • GPRS网路注册提示 AT+CGREG=1//设置模块GPRS网络注册提示,当模块从GPRS网络中掉线后,会自动上报+CGREG: 1,0 (后面的0表示掉线,如果是1表示在线.)
          • 检查GPRS网络注册情况 AT+CGREG?//检查GPRS网络注册情况
          • 附着GPRS网络 at+cgatt=1 //附着GPRS网络
          • 查看附着状态 AT+CGATT?
          • 设置短信上报机制 AT+CNMI=2,1,0,0,0  //该命令设置成功需要开机25S左右的时

    还可以设置来电显示 AT+CLIP=1

      显示注册的运营商

    显示短信中心 AT+CSCA?

    显示设备厂商 AT+CGMI

    显示模块名称 AT+CGMM

    显示版本号  AT+CGMR

    显示sim卡ID  AT%CID

    显示产品序列号 AT+CGSN

    国际移动台设备标识请求 AT+CIMI

    ========>附上操作的结果=======>

    2013年04月04日00时37分12秒
    AT

    OK
    ATE1

    OK
    AT+CPIN?

    +CPIN: READY

    OK
    At%SLEEP=0At%SLEEP=0

    ERROR
    AT%SLEEP=0

    OK
    AT%CREG=1 //这样可以么?应该是下面的一行,这里输入???

    OK
    AT+CREG=1

    OK
    AT+CREG?

    +CREG: 1,5

    OK
    AT+CSQ

    +CSQ: 22,99

    OK
    AT+CGREG=1

    OK
    +CREG: 5
    %CREG: 5, , , 2, 0 //自动上报了网络状态.
    +CGREG: 5
    %CREG: 5, , , 2, 0
    %CREG: 5, , , 2, 0

    AT+CGREG?

    +CGREG: 1,5

    OK
    AT+CGATT=1

    OK
    AT+CGATT?

    +CGATT: 1

    OK
    AT+CNMI=2,1,0,0,0

    OK
    %CREG: 5, , , 2, 0

    短信发送流程

    • 1.确认存储介质和容量  at+cpms? //确认短信存储器为SIM卡,查询卡中短信容量
    • 2.设置短信格式           at+cmgf=1 //设置短信格式为文本
    • 3.设置文本格式参数  at+csmp=,,,0  //设置文本格式参数,不同的SIM 卡可能有不同的默认值,0 代表ASCII 码,8 代表UCS2 编码
    • 4..1设置发送短信号码 at+cmgs="10086"   //发送号码,引号引起。
    • 【注意】此时串口里有“>”符号提示输入短信内容。
    • 4.2设置短信内容 hello   //可以随意输入内容。
    • 4.3结束编辑,发送短信
    • 先勾选“十六进制发送”
    • 然后输入 “1a”
    • 点击“手动发送”
    • 5.查看短信内容。
    •  at+cmgl="ALL" //查看全部短信
    • at+cmgr=1 //查看指定条目的短信

    可能用到的:

    at+cmgd=1,1 //删除指定条目的短信

    ========附上过程====== 【有很多笔误,所以看橙色标记的地方。】

    2013年04月04日01时14分22秒
    AT+CMPS?

    ERROR
    AT+CPMS?

    +CPMS: "SM",21,40,"SM",21,40,"SM",21,40

    OK
    AT+CMGF=1AT+CMGF=1

    ERROR
    AT+CMGF=1

    OK
    AT+CSMP=,,,0

    OK
    AT+CGMS=10086

    ERROR
    AT+CMGS=10086

    > AT+CMGS=10086
    >
    +CMGS: 147

    OK
    %CREG: 5, , , 2, 0
    +CMTI: "SM",22 //自动上报短信了.
    %CREG: 5, , , 2, 0
    AT+CMGL="ALL"

    +CMGL: 1,"REC READ","1252015923184063",,"13/04/02,22:52:53+32",161,28
    00200054004500530054002E002E002E002E002030105DE65B663011
    +CMGL: 2,"REC READ","12520020",,"13/04/03,13:27:11+32",161,140
    050003670201301098DE4FE15B89516863D0793A301160A876845E1053F74E8E00320030003100335E740030003467080030003365E50031003365F6003200375206767B5F556210529FFF0C5982679C8FD94E0D662F60A8672C4EBA768464CD4F5CFF0C8BF756DE590D005300445BF95E1053F78FDB884C95015B9AFF0C8C2896324ED64EBA76D7752860A8
    +CMGL: 3,"REC READ","12520020",,"13/04/03,13:27:11+32",161,36
    05000367020276845E1053F7FF0C56DE590D005100580054005853D66D8863D091923002
    +CMGL: 4,"REC READ","10086",,"13/04/03,15:41:38+32",161,140
    0500034202015C0A656C76845BA26237FF0C4E3A60A863A883504FBF6377670D52A1FF1A514D8D3962E8625300310030003000380036003100316216514D8D3953D1900177ED4FE10031523000310030003000380036FF0C537353EF4FBF637767E58BE260A876848BDD8D394F59989D300100205957991052694F594FE1606F300291CD5E8679FB52A84E00
    +CMGL: 5,"REC READ","10086",,"13/04/03,15:41:38+32",161,46
    05000342020276F4572852AA529BFF0C4E3A60A863D04F9B201C0031003052066EE1610F201D7684670D52A1FF01
    +CMGL: 6,"REC READ","106575555564165854",,"13/04/03,17:00:46+32",161,140
    537365E58D7781F3003467080031003065E5901A8FC74EAC4E1C624B673A5BA262377AEF99966B214E0B53555B8C6210537353EF83B78D60003551434EAC523800200068007400740070003A002F002F006D002E006A0064002E0063006F006D002F00680065006C0070002F006D002F006A0064002E00680074006D006C0020005B4EAC4E1C554657CE005D
    +CMGL: 7,"REC READ","12520020",,"13/04/03,22:09:59+32",161,36
    0500033B020276845E1053F7FF0C56DE590D005100580054005853D66D8863D091923002
    +CMGL: 8,"REC READ","12520020",,"13/04/03,22:09:59+32",161,140
    0500033B0201301098DE4FE15B89516863D0793A301160A876845E1053F74E8E00320030003100335E740030003467080030003365E50032003265F6003000395206767B5F556210529FFF0C5982679C8FD94E0D662F60A8672C4EBA768464CD4F5CFF0C8BF756DE590D005300445BF95E1053F78FDB884C95015B9AFF0C8C2896324ED64EBA76D7752860A8
    +CMGL: 9,"REC READ","1252015923184063",,"13/04/03,23:50:14+32",161,42
    00730065006E0064002000660072006F006D002000660065006900780069006E002030105DE65B663011
    +CMGL: 10,"REC READ","1252015923184063",,"13/04/03,23:56:26+32",161,20
    00410054003400310035003430105DE65B663011
    +CMGL: 11,"REC READ","1252015923184063",,"13/04/03,23:58:59+32",161,12
    0041005430105DE65B663011
    +CMGL: 12,"REC READ","10086",,"13/04/04,00:03:25+32",161,136
    050003E403015C0A656C76845BA26237FF0C6839636E60A853D19001768451855BB9FF0C7CFB7EDF522465AD60A853EF80FD8981529E4EE54E0B4E1A52A1FF1A000A00310030003000350036002E624B673A4E0A7F516D4191CF67E58BE2000A00340030003100330037002E53D66D88624B673A4E0A7F51595799104E1A52A1FF084E0B6708751F
    +CMGL: 13,"REC READ","10086",,"13/04/04,00:03:25+32",161,62
    050003E40303002E67E58BE26D4191CF000A8BF776F463A556DE590D60A8624097004E1A52A1768465705B577F167801529E740630024E2D56FD79FB52A8
    +CMGL: 14,"REC READ","10086",,"13/04/04,00:03:25+32",161,136
    050003E403026548FF09000A0034003000310034002E624B673A4E0A7F5153E052A05305002857284E0A7F515957991057FA78404E0A53E052A0529E7406002C4E0D4F7F75284E0D65368D390029000A0034003000310035002E624B673A4E0A7F5151B26D6A530500286BCF65E5003070B9002D003770B94F7F75280029000A67E58BE26D4191CF
    +CMGL: 15,"REC UNREAD","10086",,"13/04/04,00:53:46+32",161,136
    0500035603015C0A656C76845BA26237FF0C6839636E60A853D19001768451855BB9FF0C7CFB7EDF522465AD60A853EF80FD8981529E4EE54E0B4E1A52A1FF1A000A00310030003000350036002E624B673A4E0A7F516D4191CF67E58BE2000A00340030003100330037002E53D66D88624B673A4E0A7F51595799104E1A52A1FF084E0B6708751F
    +CMGL: 16,"REC UNREAD","10086",,"13/04/04,00:53:46+32",161,136
    0500035603026548FF09000A0034003000310034002E624B673A4E0A7F5153E052A05305002857284E0A7F515957991057FA78404E0A53E052A0529E7406002C4E0D4F7F75284E0D65368D390029000A0034003000310035002E624B673A4E0A7F5151B26D6A530500286BCF65E5003070B9002D003770B94F7F75280029000A67E58BE26D4191CF
    +CMGL: 17,"REC UNREAD","10086",,"13/04/04,00:53:47+32",161,62
    050003560303002E67E58BE26D4191CF000A8BF776F463A556DE590D60A8624097004E1A52A1768465705B577F167801529E740630024E2D56FD79FB52A8
    +CMGL: 18,"REC UNREAD","10086",,"13/04/04,00:54:49+32",161,62
    050003420303002E67E58BE26D4191CF000A8BF776F463A556DE590D60A8624097004E1A52A1768465705B577F167801529E740630024E2D56FD79FB52A8
    +CMGL: 19,"REC UNREAD","10086",,"13/04/04,00:54:49+32",161,136
    0500034203026548FF09000A0034003000310034002E624B673A4E0A7F5153E052A05305002857284E0A7F515957991057FA78404E0A53E052A0529E7406002C4E0D4F7F75284E0D65368D390029000A0034003000310035002E624B673A4E0A7F5151B26D6A530500286BCF65E5003070B9002D003770B94F7F75280029000A67E58BE26D4191CF
    +CMGL: 20,"REC UNREAD","10086",,"13/04/04,00:54:49+32",161,136
    0500034203015C0A656C76845BA26237FF0C6839636E60A853D19001768451855BB9FF0C7CFB7EDF522465AD60A853EF80FD8981529E4EE54E0B4E1A52A1FF1A000A00310030003000350036002E624B673A4E0A7F516D4191CF67E58BE2000A00340030003100330037002E53D66D88624B673A4E0A7F51595799104E1A52A1FF084E0B6708751F
    +CMGL: 21,"REC UNREAD","1252013618252285","@Sgg","13/04/04,00:58:14+32",161,60
    535E670B670B003A80FD4E0D80FD65E970B97761FF1F53F0706F5F88523A773CFF0C6572952E76D858F05F8870E64EBA670967286709FF1FFF1FFF1F
    +CMGL: 22,"REC UNREAD","10086",,"13/04/04,01:10:10+32",161,46
    004D002D007A006F006E006552A8611F57305E26FF0C62117684573076D830016211505A4E3B54E6FF01FF01FF01

    OK
    AT+CMGR=22

    +CMGR: "REC READ","10086",,"13/04/04,01:10:10+32",161,36,0,8,"8613800230510",145,46
    004D002D007A006F006E006552A8611F57305E26FF0C62117684573076D830016211505A4E3B54E6FF01FF01FF01

    OK
    AT+CMGD=22,1

    OK
    AT+CMGD=22,1

    OK
    AT+CMGR="ALL"

    ERROR
    AT+CMGL="ALL"//已经清空短信

    OK

    TCP发送数据流程

    tcp发送数据首先配置好上位机,得到上位机的ip地址和端口。

    1.检测信号强度 at+csq

    2.sim卡状态 at+cpin?

    3. GPRS状态  at+cgreg?

    4.APN 无线接入点 at+cgdcont=1,"ip","cmnet"

    5.pp拨号 at%etcpip="",""

    【可以添加一个查看ip的,方便观看】at%etcpip? //检查获得本地IP地址,以及DNS服务器的地址

    6打开连接  AT%IPOPEN="TCP","server_IP",server_Port

    //server_IP 服务器IP地址

    //server_Port  服务器端口

    image

    7.发送数据  AT%IPSEND="Data_ToBeSend_in_hex"

    //Data_ToBeSend_in_hex 是待发送的数据(十六进制)

    //例如 4154   表示AT

    image

    可能用到的有

    at%ipopen?          // 查询链路状态,链路断开时模块会自动返回%IPCLOSE: 1

    at%etcpip?         //检查获得本地IP地址,以及DNS服务器的地址

    at%ipclose=1  //关闭TCP SOCKET连接,返回OK需要7-10s左右,请设计超
    时等待时注意。

    at%ipclose=5  // AT%IPCLOSE=1关闭成功后,才能AT%IPCLOSE=5。
    // 否则可能出现TCP连接异常断开,造成中心余留客户端IP地址。

    TCPTcpSendDataTcpSendData_helloTcpSendData_tudou

    2013年4月4日 01:43:06


  • 相关阅读:
    Java进阶——线程安全和非线程安全
    Java进阶——线程与多线程
    Java进阶——反射
    SpringBoot——SpringBoot框架介绍
    亲逢APP项目知识点
    诗韵APP项目技术点
    Spring框架——WebService
    Spring框架——ORM
    Spring框架——JDBC
    Spring框架——Spring响应
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2999104.html
Copyright © 2020-2023  润新知