首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

串口号不能改变,该如何解决

2012-01-06 
串口号不能改变VB codePrivate Sub Command2_Click()Text3.Text Text1.SetFocusIf Combo1.ListIndex

串口号不能改变

VB code
Private Sub Command2_Click()Text3.Text = ""Text1.SetFocusIf Combo1.ListIndex = 0 ThenMsgBox "请选择端口", vbInformation, "提示"ElseIf Combo1.ListIndex > 0 And Len(Text1.Text) <> 15 ThenText3.Text = "IMEI位数不对"Text3.BackColor = &HFF&ElseText3.BackColor = &H8000000FDim portset As String  portset = Combo2.Text + ",n,8,1"On Error GoTo ER:Dim comm() As Stringcomm() = Split(Combo1.Text, "M")MSComm.CommPort = comm(1)MSComm.Settings = portsetMSComm.PortOpen = TrueText3.BackColor = &HFF00&Text3.Text = Combo1.Text + "初始化成功,连接手机中...!"[color=#FF0000]ER:  Select Case Err.Number[/color]      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


MSComm.CommPort = comm(1) 值不会跟着COMM(1)所取的值而变化,只有在没有点击按钮之前

COMM(1)取到的值是多少,再按几次按钮 MSComm.CommPort的值仍是第一次赋的值,。

请问是什么原因。 


[解决办法]
指定的串口在打开前要先关闭一下.

热点排行