Form1.frm
资源名称:短信测试3.0.rar [点击查看]
上传用户:bofapump
上传日期:2010-03-19
资源大小:97k
文件大小:26k
源码类别:
Modem编程
开发平台:
Visual Basic
- VERSION 5.00
- Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
- Object = "{AEECEB18-1629-4D9E-AB2C-C11093920FC6}#1.0#0"; "SuperSMS.ocx"
- Begin VB.Form q
- Caption = "Saro-短信测试工具3.0 www.sangrong.com 0592-5932711 5932722"
- ClientHeight = 6060
- ClientLeft = 165
- ClientTop = 555
- ClientWidth = 9405
- Icon = "Form1.frx":0000
- LinkTopic = "Form1"
- ScaleHeight = 6060
- ScaleWidth = 9405
- StartUpPosition = 3 'Windows Default
- Begin SMS.SuperSMS SuperSMS1
- Left = 4800
- Top = 2760
- _ExtentX = 900
- _ExtentY = 900
- SMS_SLen = "8"
- End
- Begin VB.ComboBox Combo2
- Height = 315
- Left = 6840
- TabIndex = 30
- Text = "COM1"
- Top = 480
- Width = 975
- End
- Begin VB.TextBox Text9
- Height = 285
- Left = 720
- TabIndex = 28
- Text = "Text9"
- Top = 3720
- Visible = 0 'False
- Width = 1095
- End
- Begin VB.CommandButton Command12
- Caption = "查看日志"
- Height = 375
- Left = 5880
- TabIndex = 27
- Top = 960
- Width = 855
- End
- Begin VB.CheckBox Check1
- Caption = "不经过SIM卡直接接收"
- Height = 255
- Left = 2040
- TabIndex = 26
- Top = 1080
- Width = 2055
- End
- Begin VB.ComboBox Combo1
- Height = 315
- Left = 8160
- TabIndex = 25
- Text = "Combo1"
- Top = 480
- Width = 1215
- End
- Begin VB.CommandButton Command11
- Caption = "短信位置"
- Height = 375
- Left = 3000
- TabIndex = 23
- Top = 5520
- Width = 1095
- End
- Begin VB.CommandButton Command10
- Caption = "查看已发送"
- Height = 375
- Left = 6960
- TabIndex = 22
- Top = 5640
- Width = 1095
- End
- Begin VB.CommandButton Command9
- Caption = "接收已读短信"
- Height = 375
- Left = 5640
- TabIndex = 21
- Top = 5640
- Width = 1215
- End
- Begin VB.TextBox Text8
- Height = 1575
- Left = 6360
- TabIndex = 20
- Top = 1920
- Visible = 0 'False
- Width = 1095
- End
- Begin VB.CommandButton Command8
- Caption = "关闭串口"
- Height = 375
- Left = 6840
- TabIndex = 19
- Top = 960
- Width = 855
- End
- Begin VB.CommandButton Command7
- Caption = "删除此条:"
- Height = 375
- Left = 120
- TabIndex = 17
- Top = 5520
- Width = 1095
- End
- Begin VB.TextBox Text7
- Height = 375
- Left = 1320
- TabIndex = 16
- Top = 5520
- Width = 375
- End
- Begin VB.CommandButton Command6
- Caption = "所有短信"
- Height = 375
- Left = 8160
- TabIndex = 15
- Top = 5640
- Width = 1215
- End
- Begin VB.CommandButton Command5
- Caption = "清 空"
- Height = 375
- Left = 7800
- TabIndex = 14
- Top = 960
- Width = 735
- End
- Begin VB.TextBox Text6
- Height = 285
- Left = 3120
- TabIndex = 13
- Top = 2880
- Visible = 0 'False
- Width = 855
- End
- Begin VB.TextBox Text5
- Height = 975
- Left = 120
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 12
- Top = 2280
- Visible = 0 'False
- Width = 3975
- End
- Begin VB.CommandButton Command4
- Caption = "接收未读短信"
- Height = 375
- Left = 4320
- TabIndex = 11
- Top = 5640
- Width = 1215
- End
- Begin VB.CommandButton Command3
- Caption = "退 出"
- Height = 375
- Left = 8640
- TabIndex = 10
- Top = 960
- Width = 735
- End
- Begin VB.TextBox Text4
- Height = 4095
- Left = 4320
- Locked = -1 'True
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 8
- Text = "Form1.frx":030A
- Top = 1440
- Width = 5055
- End
- Begin MSCommLib.MSComm MSComm1
- Left = 1680
- Top = 2280
- _ExtentX = 1005
- _ExtentY = 1005
- _Version = 393216
- DTREnable = -1 'True
- InBufferSize = 30240
- BaudRate = 57600
- InputMode = 1
- End
- Begin VB.CommandButton Command2
- Caption = "PDU发送"
- Height = 375
- Left = 3000
- TabIndex = 7
- Top = 5040
- Width = 1095
- End
- Begin VB.CommandButton Command1
- Caption = "test发送"
- Height = 375
- Left = 120
- TabIndex = 6
- Top = 5040
- Width = 1095
- End
- Begin VB.TextBox Text3
- Height = 3495
- Left = 120
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 5
- Top = 1440
- Width = 3975
- End
- Begin VB.TextBox Text2
- Height = 375
- Left = 120
- TabIndex = 3
- Text = "8613850039334"
- Top = 480
- Width = 3975
- End
- Begin VB.TextBox Text1
- Height = 375
- Left = 4320
- TabIndex = 1
- Text = "+8613800592500"
- Top = 480
- Width = 2175
- End
- Begin VB.Label Label7
- Caption = "选择串口:"
- Height = 255
- Left = 6840
- TabIndex = 29
- Top = 120
- Width = 975
- End
- Begin VB.Line Line1
- X1 = 0
- X2 = 9360
- Y1 = 900
- Y2 = 900
- End
- Begin VB.Label Label6
- Caption = "选择波特率:"
- Height = 255
- Left = 8160
- TabIndex = 24
- Top = 120
- Width = 1095
- End
- Begin VB.Label Label5
- Caption = "(删除前请查 看短信位置)"
- Height = 375
- Left = 1680
- TabIndex = 18
- Top = 5520
- Width = 1215
- End
- Begin VB.Label Label4
- Caption = "接收内容:"
- Height = 255
- Left = 4320
- TabIndex = 9
- Top = 1080
- Width = 1095
- End
- Begin VB.Label Label3
- Caption = "发送内容:"
- Height = 255
- Left = 120
- TabIndex = 4
- Top = 1080
- Width = 1215
- End
- Begin VB.Label Label2
- Caption = "被叫手机号码(若群发,请用"",""分隔开):"
- Height = 255
- Left = 120
- TabIndex = 2
- Top = 120
- Width = 4095
- End
- Begin VB.Label Label1
- Caption = "短信中心号码(此项可选):"
- Height = 255
- Left = 4320
- TabIndex = 0
- Top = 120
- Width = 2175
- End
- End
- Attribute VB_Name = "q"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Public inData As String '串口中断时读入的字符串
- Dim P As String, D As String, T As String, TXT As String, E As Integer
- Private Sub Check1_Click()
- Dim ttstring As String
- CloseOnComm
- If Check1.Value Then
- Check1.Enabled = False
- MSComm1.Output = "at+csms=1" & Chr(13) & Chr(10)
- Sleep (600)
- MSComm1.Output = "at+cnmi=2,2,0,0,1" & Chr(13) & Chr(10)
- Sleep (600)
- MSComm1.Output = "at&w" & Chr(13) & Chr(10)
- Check1.Enabled = True
- Sleep (500)
- ttstring = MSComm1.Input
- Else
- Check1.Enabled = False
- MSComm1.Output = "at+cnmi=1,1,0,0,1" & Chr(13) & Chr(10)
- Sleep (600)
- Check1.Enabled = True
- ttstring = MSComm1.Input
- End If
- OpenOnComm
- End Sub
- Private Sub Combo1_Click()
- If MSComm1.PortOpen = 1 Then
- MSComm1.PortOpen = 0
- MSComm1.Settings = Combo1.Text + ",n,8,1"
- 'If Combo1.Text = "1200" Then MSComm1.Settings = "1200,,,"
- MSComm1.PortOpen = 1
- Else
- MSComm1.Settings = Combo1.Text + ",n,8,1"
- 'If Combo1.Text = "1200" Then MSComm1.Settings = "1200,,,"
- End If
- End Sub
- Private Sub combo1_dropdown()
- Combo1.Clear
- Combo1.AddItem "1200", 0
- Combo1.AddItem "2400", 1
- Combo1.AddItem "4800", 2
- Combo1.AddItem "9600", 3
- Combo1.AddItem "19200", 4
- Combo1.AddItem "38400", 5
- Combo1.AddItem "57600", 6
- Combo1.AddItem "115200", 7
- End Sub
- Private Sub combo2_click()
- 'On Error Resume Next
- On Error GoTo errorhander
- If MSComm1.PortOpen Then MSComm1.PortOpen = False
- Command8.Caption = "打开串口"
- Dim SComm As Integer
- SComm = Val(Mid(Combo2.Text, 4, 1))
- MSComm1.CommPort = SComm
- MSComm1.PortOpen = True
- If MSComm1.PortOpen Then Command8.Caption = "关闭串口"
- Exit Sub
- errorhander:
- MsgBox "当前串口被占用或其他错误,请检查!", vbOKOnly, "串口?"
- Resume Next
- End Sub
- Private Sub Command10_Click()
- CloseOnComm
- Dim TxString As String
- Dim i As Integer
- MSComm1.Output = "at+cmgf=0" & vbCrLf
- Sleep (600)
- MSComm1.Output = "at+cmgl=3" & Chr(13) & Chr(10)
- Sleep (1600)
- TxString = MSComm1.Input
- Dim atext() As String
- 'Text8.SelText = TxString
- atext = Split(TxString, Chr(13) & Chr(10))
- 'Text8.Text = atext(4)
- If Len(atext(4)) < 15 Then
- Text4.SelText = "无已发送信息,请检查!" & vbCrLf
- Else
- For i = 2 To (UBound(atext) - 1) / 2 - 1
- Sleep (100)
- Text8.Text = atext(i * 2)
- SuperSMS1.ConPDU Text8.Text, P, D, T, TXT, 1, E
- 'Text4.Text = smsalltext
- '获得解析后的数据
- Text4.SelText = "电话号码:" & P & vbCrLf _
- & "日期:" & D & vbCrLf _
- & "时间:" & T & vbCrLf _
- & "内容:" & TXT & vbCrLf _
- & "错误代码:" & E & vbCrLf
- 'Text4.SelText = TxString
- Next i
- End If
- OpenOnComm
- End Sub
- Private Sub Command11_Click()
- CloseOnComm
- Dim TxString As String
- MSComm1.Output = "at+cmgf=0" & vbCrLf
- Sleep (600)
- MSComm1.Output = "at+cmgl=4" & Chr(13) & Chr(10)
- Sleep (600)
- TxString = MSComm1.Input
- Text4.SelText = TxString
- OpenOnComm
- End Sub
- Private Sub Command2_Click()
- On Local Error Resume Next
- Command1.Enabled = False
- Command2.Enabled = False
- Command7.Enabled = False
- Command11.Enabled = False
- Command4.Enabled = False
- Command9.Enabled = False
- Command6.Enabled = False
- Command10.Enabled = False
- CloseOnComm
- Dim SInput As String
- Dim a As String
- Dim atext() As String
- Dim i As Integer
- atext = Split(Text2.Text, ",")
- 'Dim s
- If Text1.Text <> "" Then
- MSComm1.Output = "at+csca=""" & Text1.Text & """" & Chr(13) & Chr(10)
- Sleep (800)
- SInput = MSComm1.Input
- If InStr(SInput, "OK") = 0 Then
- MsgBox "短信中心设置失败,请重新设置!", vbOKOnly, "发送结果"
- OpenOnComm
- Exit Sub
- End If
- End If
- 'Delay 1
- MSComm1.Output = "at+cmgf=0" & Chr(13) & Chr(10)
- Sleep (800)
- 'If MSComm1.Input = Chr(13) & Chr(13) & Chr(10) & Chr(79) & Chr(75) & Chr(13) & Chr(10) Then
- a = MSComm1.Input
- If InStr(a, "OK") <> 0 Then
- For i = 0 To UBound(atext)
- Text9.Text = atext(i)
- Conv
- MSComm1.Output = "at+cmgs=" & Text6.Text & Chr(13) & Chr(10)
- Delay 3
- MSComm1.Output = Text5.Text & Chr(26)
- Delay 4
- Dim SInputT
- SInputT = MSComm1.Input
- If InStr(SInputT, "+CMGS") <> 0 Then
- Text4.SelText = "发送给" & atext(i) & "成功!" & vbCrLf
- Else
- Text4.SelText = "发送给" & atext(i) & "失败,请检查!" & vbCrLf
- End If
- Sleep (100)
- Next i
- Text4.SelText = "发送完毕!" & vbCrLf
- Else
- MsgBox "短信模式配置错误,请重新配置!", vbOKOnly, "发送结果"
- End If
- OpenOnComm
- Command1.Enabled = True
- Command2.Enabled = True
- Command7.Enabled = True
- Command11.Enabled = True
- Command4.Enabled = True
- Command9.Enabled = True
- Command6.Enabled = True
- Command10.Enabled = True
- End Sub
- Private Sub Command3_Click()
- Unload Me
- End Sub
- Private Sub Command4_Click()
- 'Dim TxInput(1 To 65534) As Byte
- CloseOnComm
- Dim TxString As String
- Dim i As Integer
- MSComm1.Output = "at+cmgf=0" & vbCrLf
- Sleep (600)
- MSComm1.Output = "at+cmgl=0" & Chr(13) & Chr(10)
- Sleep (1600)
- TxString = MSComm1.Input
- Dim atext() As String
- 'Text8.SelText = TxString
- atext = Split(TxString, Chr(13) & Chr(10))
- 'Text8.Text = atext(4)
- If Len(atext(4)) < 15 Then
- Text4.SelText = "无未读新信息,请等待!" & vbCrLf
- Else
- For i = 2 To (UBound(atext) - 1) / 2 - 1
- Sleep (100)
- Text8.Text = atext(i * 2)
- SuperSMS1.ConPDU Text8.Text, P, D, T, TXT, 1, E
- 'Text4.Text = smsalltext
- '获得解析后的数据
- Text4.SelText = "电话号码:" & P & vbCrLf _
- & "日期:" & D & vbCrLf _
- & "时间:" & T & vbCrLf _
- & "内容:" & TXT & vbCrLf _
- & "错误代码:" & E & vbCrLf
- 'Text4.SelText = TxString
- Next i
- End If
- OpenOnComm
- End Sub
- Private Sub Command6_Click()
- CloseOnComm
- MSComm1.Output = "at+cmgf=0" & Chr(13) & Chr(10)
- Sleep (600)
- MSComm1.Output = "at+cmgl=4" & Chr(13) & Chr(10)
- Sleep (3800)
- Dim smsalltext As String
- smsalltext = MSComm1.Input
- Dim atext() As String
- Dim i As Integer
- atext = Split(smsalltext, Chr(13) & Chr(10))
- Dim j As Integer
- If Len(atext(4)) < 15 Then
- Text4.SelText = "内存为空,无短信" & vbCrLf
- Else
- For j = 2 To (UBound(atext) - 1) / 2 - 1
- Sleep (100)
- Text8.Text = atext(j * 2)
- SuperSMS1.ConPDU Text8.Text, P, D, T, TXT, 1, E
- 'Text4.Text = smsalltext
- '获得解析后的数据
- Text4.SelText = "电话号码:" & P & vbCrLf _
- & "日期:" & D & vbCrLf _
- & "时间:" & T & vbCrLf _
- & "内容:" & TXT & vbCrLf _
- & "错误代码:" & E & vbCrLf
- Next j
- End If
- OpenOnComm
- End Sub
- Sub Conv()
- SuperSMS1.SMS_Phone = Text9.Text
- SuperSMS1.SMS_CSCA = Text1.Text
- SuperSMS1.SMS_STXT = Text3.Text
- Text5.Text = SuperSMS1.SMS_SMain
- 'Text8.Text = SuperSMS1.ANSIText(Text7.Text)
- Text6.Text = SuperSMS1.SMS_SLen
- End Sub
- Private Sub Command5_Click()
- Text4.Text = ""
- End Sub
- Private Sub Command7_Click()
- CloseOnComm
- MSComm1.Output = "at+cmgd=" & Text7.Text & vbCrLf
- Dim deltext As String
- Delay 1
- deltext = MSComm1.Input
- If InStr(deltext, "OK") <> 0 Then
- Text4.SelText = "删除短信" & Text7.Text & "成功" & vbCrLf
- deltext = ""
- Else
- Text4.SelText = "删除短信" & Text7.Text & "失败,请重新检查" & vbCrLf
- deltext = ""
- End If
- OpenOnComm
- End Sub
- Private Sub combo2_dropdown()
- Dim SCom As Integer
- Dim hKey As Long, ret As Long, lenData As Long, typeData As Long
- Dim Name As String, lenName As Long
- Dim idx As Integer, j As Integer
- Dim SSCom(0 To 50) As String
- ret = RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWAREDEVICEMAPSERIALCOMM", hKey)
- ' If ret <> 0 Then Exit Sub
- ' SCom = ret
- ret = 0
- idx = 0
- Dim s As String
- Dim SArr() As String
- While ret = 0
- lenName = 256
- Name = String(256, Chr(0))
- ret = RegEnumValueAsAny(hKey, idx, Name, lenName, ByVal 0, typeData, _
- ByVal vbNullString, lenData)
- If ret <> 0 Then
- RegCloseKey hKey
- ' Exit Sub
- End If
- lenName = Len(Name)
- s = String(lenData, Chr(0))
- RegEnumValueAsAny hKey, idx, Name, lenName, ByVal 0, typeData, ByVal s, lenData
- s = Left(s, InStr(s, Chr(0)) - 1)
- 'Debug.Print s
- ' Text1.SelText = s
- SSCom(idx) = s
- DoEvents
- idx = idx + 1
- SCom = idx
- Wend
- RegCloseKey hKey
- Combo2.Clear
- Dim i As Integer
- For i = 0 To SCom - 2
- Combo2.AddItem SSCom(i), i
- 'Combo7.AddItem "com2", 1
- Next
- End Sub
- Private Sub Command8_Click()
- 'On Error Resume Next
- CloseOnComm
- If InStr(Command8.Caption, "关闭串口") <> 0 Then
- MSComm1.PortOpen = False
- Command8.Caption = "打开串口"
- Command7.Enabled = False
- Command6.Enabled = False
- Command4.Enabled = False
- Command1.Enabled = False
- Command9.Enabled = False
- Command10.Enabled = False
- Command2.Enabled = False
- Command11.Enabled = False
- Label5.Enabled = False
- Else
- MSComm1.PortOpen = 1
- Command8.Caption = "关闭串口"
- ' If flag2 = True Then
- MSComm1.Output = "at" & vbCrLf
- Dim attext
- Sleep (800)
- attext = MSComm1.Input
- If InStr(attext, "OK") <> 0 Then
- Command2.Enabled = True
- Command7.Enabled = True
- Command6.Enabled = True
- Command4.Enabled = True
- Command1.Enabled = True
- Command9.Enabled = True
- Command10.Enabled = True
- Command11.Enabled = True
- Label5.Enabled = True
- Text4.SelText = "设备已经连接!" & vbCrLf
- Else
- Text4.SelText = "串口无反应,请检查!" & vbCrLf
- End If
- End If
- OpenOnComm
- End Sub
- Private Sub Command9_Click()
- CloseOnComm
- Dim TxString As String
- Dim i As Integer
- MSComm1.Output = "at+cmgf=0" & vbCrLf
- Sleep (600)
- MSComm1.Output = "at+cmgl=1" & Chr(13) & Chr(10)
- Sleep (3600)
- TxString = MSComm1.Input
- Dim atext() As String
- 'Text8.SelText = TxString
- atext = Split(TxString, Chr(13) & Chr(10))
- 'Text8.Text = atext(4)
- If Len(atext(4)) < 15 Then
- Text4.SelText = "无已读信息,请检查!" & vbCrLf
- Else
- For i = 2 To (UBound(atext) - 1) / 2 - 1
- Sleep (100)
- Text8.Text = atext(i * 2)
- SuperSMS1.ConPDU Text8.Text, P, D, T, TXT, 1, E
- 'Text4.Text = smsalltext
- '获得解析后的数据
- Text4.SelText = "电话号码:" & P & vbCrLf _
- & "日期:" & D & vbCrLf _
- & "时间:" & T & vbCrLf _
- & "内容:" & TXT & vbCrLf _
- & "错误代码:" & E & vbCrLf
- 'Text4.SelText = TxString
- Next i
- End If
- OpenOnComm
- End Sub
- Private Sub Text4_KeyPress(KeyAscii As Integer)
- On Error Resume Next
- MSComm1.Output = Chr(KeyAscii)
- End Sub
- Private Sub Form_Load()
- On Error Resume Next
- MSComm1.PortOpen = False
- MSComm1.CommPort = 1
- MSComm1.InputMode = comInputModeText
- MSComm1.Settings = "57600,N,8,1"
- 'MSComm1.InBufferCount = 1
- MSComm1.InBufferSize = 30240
- MSComm1.InputLen = 0 '设置每次从串口缓冲区取的字节为全部
- MSComm1.PortOpen = True '打开串口
- Command8.Caption = "关闭串口"
- 'Command8.Value = 0
- Combo1.Text = "57600"
- 'CloseOnComm
- MSComm1.Output = "at" & Chr(13) & Chr(10)
- Sleep (800)
- 'Text4.Text = StrConv (MSComm1.Input, vbUnicode)
- Dim aafirst As String
- aafirst = MSComm1.Input
- If InStr(aafirst, "OK") = 0 Then
- MsgBox ("AT不通,请检查mode是否连接成功!")
- 'Command8.Caption = "打开串口"
- Command1.Enabled = 0
- Command4.Enabled = 0
- Command6.Enabled = 0
- Command7.Enabled = 0
- Command9.Enabled = 0
- Command10.Enabled = 0
- Command2.Enabled = 0
- Command11.Enabled = 0
- Label5.Enabled = 0
- Else
- aafirst = ""
- Text4.SelText = "设备已经连接成功,请测试!" & vbCrLf
- ' Command8.Caption = "关闭串口"
- Command1.Enabled = 1
- Command4.Enabled = 1
- Command6.Enabled = 1
- Command7.Enabled = 1
- Command2.Enabled = 1
- Command9.Enabled = 1
- Command10.Enabled = 1
- Command11.Enabled = 1
- Label5.Enabled = 1
- MSComm1.Output = "at+cnmi=1,1,0,0,1" & vbCrLf
- End If
- Delay 1
- aafirst = MSComm1.Input
- 'inData = ""
- OpenOnComm
- Open "DataLink.txt" For Append As #1
- Close #1
- End Sub
- Private Sub Command1_Click()
- On Local Error Resume Next
- Command1.Enabled = False
- Command2.Enabled = False
- Command7.Enabled = False
- Command11.Enabled = False
- Command4.Enabled = False
- Command9.Enabled = False
- Command6.Enabled = False
- Command10.Enabled = False
- CloseOnComm
- Dim stt1 'As String
- Dim atext() As String
- Dim i As Integer
- atext = Split(Text2.Text, ",")
- 'For i = 0 To UBound(atext)
- If Text1.Text <> "" Then
- MSComm1.Output = "at+csca=""" & Text1.Text & """" & Chr(13)
- Delay 2
- stt1 = MSComm1.Input
- If InStr(stt1, "OK") = 0 Then
- MsgBox "短信中心号码设置不成功,请检查!", vbOKOnly, "发送结果"
- Exit Sub
- End If
- End If
- Delay 1
- MSComm1.Output = "at+cmgf=1" & Chr(13)
- Sleep (600) 'wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
- Dim att 'As String
- att = MSComm1.Input
- ' Text4.Text = StrConv(att, vbUnicode)
- If InStr(att, "OK") <> 0 Then
- For i = 0 To UBound(atext)
- MSComm1.Output = "at+cmgs=""" & atext(i) & """" & Chr(13)
- Delay 2
- MSComm1.Output = Text3.Text & Chr(26)
- Sleep (3200)
- Dim stt 'As String
- stt = MSComm1.Input
- If InStr(stt, "+CMGS") <> 0 Then
- Text4.SelText = "发送给" & atext(i) & "成功!" & vbCrLf
- Else
- Text4.SelText = "发送给" & atext(i) & "失败,请检查!" & vbCrLf
- End If
- Sleep (100)
- Next i
- Text4.SelText = "发送完毕!" & vbCrLf
- Else
- MsgBox "短信模式设置不成功,请检查!", vbOKOnly, "发送结果"
- End If
- Command1.Enabled = True
- Command2.Enabled = True
- Command7.Enabled = True
- Command11.Enabled = True
- Command4.Enabled = True
- Command9.Enabled = True
- Command6.Enabled = True
- Command10.Enabled = True
- OpenOnComm
- End Sub
- Public Sub CloseOnComm()
- MSComm1.RThreshold = 0
- MSComm1.InputMode = comInputModeText
- End Sub
- Public Sub OpenOnComm()
- MSComm1.RThreshold = 1
- MSComm1.InputMode = comInputModeBinary
- End Sub
- Public Sub Delay(HowLong As Date) '延时
- Dim temptime As Date
- temptime = DateAdd("s", HowLong, Now)
- While temptime > Now
- DoEvents '让 windows 去处理其他事
- Wend
- End Sub
- Private Sub Text1_Change()
- Conv
- End Sub
- Private Sub Text2_Change()
- Conv
- End Sub
- Private Sub Text3_Change()
- Conv
- End Sub
- Private Sub MSComm1_OnComm() '串口中断
- On Error Resume Next
- Static bFlag As Boolean
- Static Xbyte As Long
- Select Case MSComm1.CommEvent '选择事件
- Case comEvReceive '接收到字符
- Dim InByte() As Byte '定义一个二进制指针放接收到的数据
- InByte = MSComm1.Input '数据转移到指针
- Dim temp As Long
- Dim temp1 As Long
- Dim temp2 As Long
- Dim j As Long
- Dim counttrue As Integer
- counttrue = 1
- For j = 0 To UBound(InByte) '循环到指针上标
- '' If ifhex = 1 Then '16进制显示处理
- ' inData = inData & Hex(InByte(j)) & " " '取出一个字节换为16进制显示用
- ' Else:
- If InByte(j) < 128 And bFlag = 0 Then
- If InByte(j) = 13 Then
- inData = inData & vbCr 'Lf
- Else
- inData = inData & Chr(InByte(j)) 'ascii码显示处理
- End If
- Else '此时为一个中文的前半部
- If bFlag Then '上次收到半个中文没处理
- temp1 = Xbyte
- temp2 = InByte(j)
- temp = (temp1 * 256 + temp2) - 65536
- inData = inData & Chr(temp)
- bFlag = 0
- Else
- If j <> UBound(InByte) Then
- temp1 = InByte(j)
- temp2 = InByte(j + 1)
- temp = (temp1 * 256 + temp2) - 65536
- inData = inData & Chr(temp) ' & "(*" & temp & "*) "
- j = j + 1 '此次中断收到最后一个字节是前半个中文
- Else
- Xbyte = InByte(j) '保存该字节
- bFlag = 1 '置标志
- End If
- End If
- ' End If
- End If
- ' counttrue = 1
- Next j
- DoEvents
- ' Delay 1
- ' flag2 = False
- If InStr(inData, "+CMTI:") <> 0 And counttrue = 1 Then
- Text4.SelText = "新短信,请接收!" & vbCrLf
- ' Delay 1
- counttrue = counttrue + 1
- End If
- If Check1.Value And InStr(inData, "+CMT:") <> 0 Then
- CloseOnComm
- Delay 1
- inData = MSComm1.Input
- Dim atext() As String
- atext = Split(inData, Chr(13) & Chr(10))
- Text8.Text = atext(1)
- SuperSMS1.ConPDU Text8.Text, P, D, T, TXT, 1, E
- 'Text4.Text = smsalltext
- '获得解析后的数据
- Text4.SelText = "电话号码:" & P & vbCrLf _
- & "日期:" & D & vbCrLf _
- & "时间:" & T & vbCrLf _
- & "内容:" & TXT & vbCrLf _
- & "错误代码:" & E & vbCrLf
- '保存到TEXT文档
- Text8.Text = "电话号码:" & P & vbCrLf _
- & "日期:" & D & vbCrLf _
- & "时间:" & T & vbCrLf _
- & "内容:" & TXT & vbCrLf _
- & "错误代码:" & E & vbCrLf
- Open "DataLink.txt" For Append As #1
- Print #1, Text8.Text
- Close #1
- Sleep (400)
- MSComm1.Output = "at+cnma" & Chr(13) & Chr(10)
- Sleep (600)
- inData = MSComm1.Input
- If InStr(inData, "OK") = 0 Then
- MSComm1.Output = "at+cnma" & Chr(13) & Chr(10)
- Sleep (400)
- inData = MSComm1.Input
- End If
- OpenOnComm
- End If
- Text4.SelText = inData '将刚收到的字符串显示出来
- inData = ""
- Text4.SelStart = Len(Text4.Text) '光标置后
- Case comEventRxOver '接收缓冲区满的处理
- MsgBox "接收缓冲区满了!" '发出警告
- End Select
- End Sub