PC机控制短信收发设备原理及实现(1)

最近公司某部门要在管理系统中集成短信收发功能,任务落到我头上,虽然短信平台并不是什么新鲜事,买设备也能提供二次开发库,但之前没接触过,于是也很投入地作了学习和研究。起初很神秘很刺激,在网上一通搜,发现纯收发短信功能其实并不复杂,也就是通过串口把AT 指令发送到短信收发设备,然后从串口读取传回的数据,解析其内容可以判断是指令响应还是返回的数据。

     这里附带说一下测试的工具,如果只是用来测试一般的AT指令,手头又没有可用的串口测试工具,windows自带的超级终端工具是个不错的选择,但是超级终端没法对已经编码的短信息进行解码,因此读取短信只能看到一堆乱码。
     说到短信息的编码,现在各类终端支持能支持Text和PDU两种模式,据说Text模式对中文支持不好,因此被我直接忽略,PDU模式要掌握也并不复杂,一是要了解PDU编码后的报文格式,二是要掌握编码解码的特定规则,一般的 PDU 编码分为十三段,由 A M 十三个英文字母表示,各段的简单说明我列了个表 :

 

序号

PDU 分段号

说明

1 </

Option Explicit Public g_blIsListSMS As Boolean Public g_blIsSysBusy As Boolean Public g_blIsWaiting As Boolean Public g_blIsNewSMSIn As Boolean Public g_blIsSendingSMS As Boolean Public g_blIsHexCommData As Boolean Public g_blMaySaveAllSMS As Boolean Public g_blwav As Boolean Public g_strSave As String Public g_strThisAT As String Public g_strLastAT As String Public g_strLatestAT As String Public n_CountListSMS As Long Public g_SysInfo As SysStruct Public TheForm As Form Public TheMenu As Menu Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'VB延时API函数 Public Declare Sub winhelp Lib "user32" (ByVal hWnd As Long, ByVal lphelpfile As String, ByVal wcommand As Long, ByVal dwData As Long) '调用帮助API函数 Public Declare Function htmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long Public Const HH_DISPLAY_INDEX = 2 Public Const HH_DISPLAY_TOC = 1 Public Const HH_DISPLAY_TOPIC = 0 Type SysStruct CommPort As Integer Baud As String ServiceNo As String DestNo As String SMSMelody As Integer Clock As Boolean ClockSet As String End Type Type SMSDef ListOrRead As Boolean '是否用列举(List)方法读取 SmsIndex As Long SourceNo As String ReachDate As String ReachTime As String SmsMain As String End Type '功能:解析串口中AT命令返回的信息 '输入参数: 串口数据 '输出参数: 'strATData: 短消息内容(UD) 'iSMSIdx: 短消息序号 'strSMSTime: 短消息接收时间 'strSMSSourceNO:源SIM卡号 'strSMSStatus: 短消息状态:"READ"—已读,"UNREAD"—未读,"SENT"—发送,"UNSENT"—未发送 Public Function GetDataFromCommPort(ByVal strInput As String, strATData As String, Optional CommandStatus As String, Optional TimedOut As Boolean, Optional iSMSIdx As Integer, Optional strSMSTime As String, Optional strSMSSourceNO As String, Optional strSMSStatus As String) As Boolean On Error GoTo ErrorG Dim strTmp As String, strTmp1 As String
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值