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

📄 form1.frm

📁 通过电脑的串口
💻 FRM
字号:
VERSION 5.00
Begin VB.Form t39短信工具 
   Caption         =   "t39短信工具"
   ClientHeight    =   5025
   ClientLeft      =   165
   ClientTop       =   450
   ClientWidth     =   3585
   LinkTopic       =   "Form1"
   ScaleHeight     =   5025
   ScaleWidth      =   3585
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton cmdExit 
      Caption         =   "退出"
      Height          =   375
      Left            =   2520
      TabIndex        =   8
      Top             =   4560
      Width           =   975
   End
   Begin VB.CommandButton cmdClear 
      Caption         =   "清空"
      Height          =   375
      Left            =   1320
      TabIndex        =   7
      Top             =   4560
      Width           =   975
   End
   Begin VB.CommandButton cmdSend 
      Caption         =   "发送"
      Height          =   375
      Left            =   120
      TabIndex        =   6
      Top             =   4560
      Width           =   975
   End
   Begin VB.Frame Frame1 
      Height          =   4335
      Left            =   120
      TabIndex        =   0
      Top             =   0
      Width           =   3375
      Begin VB.Timer Timer2 
         Enabled         =   0   'False
         Interval        =   8000
         Left            =   2640
         Top             =   0
      End
      Begin VB.Timer Timer1 
         Enabled         =   0   'False
         Interval        =   5000
         Left            =   2160
         Top             =   0
      End
      Begin VB.TextBox sms_content 
         Appearance      =   0  'Flat
         Height          =   1815
         Left            =   480
         MaxLength       =   140
         TabIndex        =   5
         Top             =   2040
         Width           =   2535
      End
      Begin VB.TextBox sms_phone 
         Appearance      =   0  'Flat
         Height          =   285
         Left            =   1560
         TabIndex        =   4
         Text            =   "13926491783"
         Top             =   1320
         Width           =   1455
      End
      Begin VB.TextBox sms_addr 
         Appearance      =   0  'Flat
         Height          =   285
         Left            =   1560
         TabIndex        =   2
         Text            =   "13010200500"
         Top             =   705
         Width           =   1455
      End
      Begin VB.Line Line1 
         BorderColor     =   &H80000014&
         X1              =   480
         X2              =   3000
         Y1              =   1800
         Y2              =   1800
      End
      Begin VB.Label lbl 
         Caption         =   "对方号码:"
         Height          =   255
         Index           =   1
         Left            =   480
         TabIndex        =   3
         Top             =   1320
         Width           =   975
      End
      Begin VB.Label lbl 
         Caption         =   "短信中心:"
         Height          =   255
         Index           =   0
         Left            =   480
         TabIndex        =   1
         Top             =   720
         Width           =   975
      End
   End
   Begin VB.Menu settingform 
      Caption         =   "串口设置"
   End
End
Attribute VB_Name = "t39短信工具"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim str_asc As String
Dim TEMP As String
Dim typeSMS As typeSMS
Dim FLAG As Integer
Dim cp As New CommPort
Dim portAvailable As Boolean

Private Function Connect()
    If (cp.Opened) Then Exit Function
    cp.BaudRate = SettingsForm.BaudRateCombo.Text
    cp.Port = SettingsForm.PortCombo.Text
    cp.Parity = SettingsForm.ParityCombo.ListIndex
    cp.StopBits = SettingsForm.StopbitsCombo.ListIndex
'    cp.ByteSize = SettingsForm.BytesizeCombo.ItemData(SettingsForm.BytesizeCombo.ListIndex)
    cp.ReadTimeout = SettingsForm.ReadTimeoutCombo.Text
    cp.WriteTimeout = SettingsForm.WriteTimeoutCombo.Text
    cp.Open
    portAvailable = cp.Opened
    
    If (portAvailable) Then
        Debug.Print "connectting to com " & cp.Port & " rate: 9600" & Chr(13) & Chr(10)
    End If
End Function



Private Sub cmdClear_Click()
    sms_content.Text = ""
End Sub

Private Sub cmdExit_Click()
    Unload Me
    cp.Close
    Set cp = Nothing
End Sub

Private Sub cmdSend_Click()
    If sms_phone = "" Then
        MsgBox "没有填写要发送的号码!!", vbCritical, "错误"
        Exit Sub
    End If
    If sms_content = "" Then
        If MsgBox("你发送的内容为空。是否继续?", vbYesNo, "错误") = vbNo Then Exit Sub
    End If
    
    With typeSMS
        .sPhoneNumber = PDUHalf8bitEncode(sms_phone.Text)
        .PDUData = PDUChineseEncode(sms_content.Text)
        .PDUDataLen = Right("0" & Hex(LenB(sms_content.Text)), 2)
        
       str_asc = .SMSCLen & _
        .AddressType & _
        .SourceCenter & _
        .SMSDeliver1 & _
        .sPhoneNumLen & _
        .sPhoneNumType & _
        .sPhoneNumber & _
        .ProtocolFlag & _
        .EncodeType & _
        .TimePost & _
        .PDUDataLen & _
        .PDUData
    End With
    Debug.Print str_asc
    Connect
    cp.WriteString ("AT+CMGS=" & 15 + LenB(sms_content.Text) & Chr(13) & Chr(10))
    Timer1.Enabled = True
End Sub

    

Private Sub Form_Load()
    With typeSMS
        .SMSCLen = "08"
        .AddressType = "9168"  'SMSC的地址类型 (91意味着国际格式的电话号码)
        .SourceCenter = PDUHalf8bitEncode(sms_addr.Text)     '服务中心号码(半八位的十进制数),加入F来保证位数
        .SMSDeliver1 = "11"     'SMS_DELIVER的第一个8位
        .sPhoneNumLen = "000D"  '地址长度。发送号码的长度
        .sPhoneNumType = "9168" '发送号码的地址类型,91意味着国际格式的电话号码,否则为A1
        .sPhoneNumber = ""      '发送号码(半八位的十进制数),有一个F结尾
        .ProtocolFlag = "00"    '协议标识(00)
        .EncodeType = "08"      '编码方式,一般00为英文的7bit编码,08为中文的Unicode编码"
        .TimePost = "A7"        '时间邮戳(半8位)(A7)
        '.PDUDataLen  =         'TP-UDL.用户数据长度,信息的长度(编码前).
        '.PDUData     =         'PDU数据(以0x1A结束)
   End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set cp = Nothing
End Sub

Private Sub settingform_Click()
    SettingsForm.Show
End Sub

Private Sub Timer1_Timer()
    Dim stringtemp As String * 100
    stringtemp = cp.ReadString(20)
    Debug.Print stringtemp
    If InStr(stringtemp, ">") > 0 Then
        If MsgBox("ok!请确认是否发送?", vbYesNo, "手机反馈窗口") = vbNo Then Exit Sub
        cp.WriteString (str_asc & Chr(&H1A))
        Debug.Print str_asc & Chr(&H1A)
        Timer2.Enabled = True
    Else
        If InStr(stringtemp, "error") > 0 Then
            Timer1.Enabled = False
            Exit Sub
        End If
        MsgBox "连接串口超时", vbCritical, "出错"
        cp.WriteString (Chr(&H1A))
        Timer1.Enabled = False
        Exit Sub
    End If
    Timer1.Enabled = False
End Sub

Private Sub Timer2_Timer()
    Dim str_temp As String * 250
    str_temp = cp.ReadString(300)
    Debug.Print str_temp
    If InStr(str_temp, "OK") > 0 Then
        MsgBox "发送成功!!", vbInformation, "你好!"
    Else
        MsgBox "出错", vbCritical, "错误"
    End If
    Timer2.Enabled = False
End Sub

⌨️ 快捷键说明

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