串口号不能改变
本帖最后由 disk0 于 2011-06-13 17:44:29 编辑
Private Sub Command2_Click()
Text3.Text = ""
Text1.SetFocus
If Combo1.ListIndex = 0 Then
MsgBox "请选择端口", vbInformation, "提示"
ElseIf Combo1.ListIndex > 0 And Len(Text1.Text) <> 15 Then
Text3.Text = "IMEI位数不对"
Text3.BackColor = &HFF&
Else
Text3.BackColor = &H8000000F
Dim portset As String
portset = Combo2.Text + ",n,8,1"
On Error GoTo ER:
Dim comm() As String
comm() = Split(Combo1.Text, "M")
MSComm.CommPort = comm(1)
MSComm.Settings = portset
MSComm.PortOpen = True
Text3.BackColor = &HFF00&
Text3.Text = Combo1.Text + "初始化成功,连接手机中...!"
ER: Select Case Err.Number Case Is = 8002
Text3.Text = Text3.Text + "初始化失败:串口无效"
Text3.BackColor = &HFF&
Case Is = 8015
Text3.Text = Text3.Text + "初始化失败:波特率无效"
Text3.BackColor = &HFF&
Case Is = 380
Text3.Text = Text3.Text + "初始化失败:波特率无效"
Text3.BackColor = &HFF&
End Select
On Error Resume Next
MSComm.Output = "AT+ESLP=0" + Chr(13)
Sleep 100
MSComm.Output = "AT+ESLP=0" + Chr(13)
Sleep 100
MSComm.OutBufferCount = 0
MSComm.Output = "AT+ESLP=0" + Chr(13)
Sleep 100
MSComm.OutBufferCount = 0
MSComm.Output = "AT+ESLP=0" + Chr(13)
Sleep 100
info = MSComm.Input
compa = info Like "*OK*"
If compa = True Then
Text3.Text = Combo1.Text + "与手机连接成功"
Text3.Refresh
Call Write_IMEI