⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sms.bas

📁 这是一本学习串口编程喝计算机监控的好书里面是用VB开发的源代码
💻 BAS
字号:
Attribute VB_Name = "SMS"
'==========================================================='
'                                                           '
'              AT+CXXX=?       Test command                 '
'              AT+CXXX?        Read command                 '
'              AT+CXXX=<...>   Write command                '
'              AT+CXXX         Execution command            '
'                                                           '
'==========================================================='

'depend on StringProcess.bas

Option Explicit

Private Const MB_LEN = 11
Public Const MAX_SMS = 140
Public strCSCA As String
Public strPDU As String
Public strPDU_Len As String

Public Function SwapTwo(ByVal strData As String) As String
    If Len(strData) <> 2 Then Exit Function
    SwapTwo = Mid(strData, 2, 1) + Mid(strData, 1, 1)
End Function

Public Function GetMbAddress(ByVal strMB As String) As String
    Dim strTmp As String
    Dim strData As String
    Dim nLen As Integer
    Dim I As Integer
    
    If Len(strMB) <> MB_LEN Then Exit Function
    strTmp = "86" + Trim(strMB)
    If Len(strTmp) Mod 2 > 0 Then strTmp = strTmp + "F"
    
    nLen = Len(strTmp) / 2
    For I = 0 To nLen - 1
        strData = strData + SwapTwo(Mid(strTmp, I * 2 + 1, 2))
    Next I
    
    GetMbAddress = strData
End Function

Public Function GetRightMB(ByVal strData As String) As String
    Dim strTmp As String
    Dim nLen As Integer
    Dim I As Integer
    
    strTmp = strData
    nLen = Len(strTmp) / 2
    For I = 0 To nLen - 1
        GetRightMB = GetRightMB + SwapTwo(Mid(strTmp, I * 2 + 1, 2))
    Next I
    
    If InStr(1, GetRightMB, "F") <> 0 Then _
        GetRightMB = Mid(GetRightMB, 1, Len(GetRightMB) - 1)
    If InStr(1, GetRightMB, "86") = 1 Then GetRightMB = Mid(GetRightMB, 3)
End Function

Public Function GetPDU(strPhone As String, strDa As String, strData As String) As String
    Dim strTmp As String
    Dim strHex As String
    Dim nLen As Integer
    
    If strPhone = "" Then
        strTmp = "00"
    Else
        strTmp = "0891" + GetMbAddress(strPhone)
    End If
    
    strTmp = strTmp + "11000D91" + GetMbAddress(strDa) + "000801"
    strHex = StringToUnicodeChars(strData)
    
    nLen = Len(strHex) / 2
    
    If nLen <= MAX_SMS Then
        GetPDU = strTmp + ByteToTwoHexChars(nLen) + strHex
    Else
        GetPDU = strTmp + ByteToTwoHexChars(MAX_SMS) + Mid(strHex, 1, MAX_SMS * 2)
    End If
End Function

Public Function CheckMb(ByVal strNum As String) As Boolean
    Dim nTmp As Integer
    
    If CheckLegalChars(strNum, "0123456789") = False Then Exit Function
    If Len(strNum) <> MB_LEN Then Exit Function
    
    nTmp = Val(Mid(strNum, 1, 3))
    If nTmp < 130 Or nTmp > 139 Then Exit Function
    
    CheckMb = True
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -