VB 选择串口端口 怎么没反应啊 还是提示没有打开端口
PrivateSubCombo1_Change()DimCOMAsIntegerCOM=Val(Combo1.Text)IfMSComm1.PortOpen=tureTh...
Private Sub Combo1_Change()
Dim COM As Integer
COM = Val(Combo1.Text)
If MSComm1.PortOpen = ture Then Msccomm1.PortOpen = False
MSComm1.CommPort = COM
MSComm1.PortOpen = True
End If
End Sub
端口设置没问题啊
MSComm1.InputMode = comInputModeText
MSComm1.InputLen = 0
MSComm1.Settings = "9600,n,8,1"
MSComm1.RThreshold = 1
MSComm1.CommPort = 5
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0 展开
Dim COM As Integer
COM = Val(Combo1.Text)
If MSComm1.PortOpen = ture Then Msccomm1.PortOpen = False
MSComm1.CommPort = COM
MSComm1.PortOpen = True
End If
End Sub
端口设置没问题啊
MSComm1.InputMode = comInputModeText
MSComm1.InputLen = 0
MSComm1.Settings = "9600,n,8,1"
MSComm1.RThreshold = 1
MSComm1.CommPort = 5
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0 展开
2个回答
推荐于2016-10-16 · 知道合伙人软件行家
关注
展开全部
代码拼写和ComboBox控件的事件使用有误。
Private Sub Combo1_Click()
Dim COM As Integer
COM = Val(Combo1.Text)
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = COM
MSComm1.PortOpen = True
End Sub
Private Sub Command1_Click()
Print MSComm1.CommPort
End Sub
追问
提示 无效的端口啊 怎么改啊?
追答
除非你机器无实际物理COM口。或者选择的COM口号码与机器实际COM口号不对。
Private Sub Combo1_Click()
Dim COM As Integer
COM = Val(Combo1.Text)
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = COM
MSComm1.PortOpen = True
End Sub
Private Sub Command1_Click()
Print MSComm1.CommPort
End Sub
Private Sub Form_Load()
Dim i As Long
For i = 1 To 16
Combo1.AddItem i
Next
End Sub
机器实际COM口号可从设备管理器获取。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询