vb中使用mscomm时出现错误8012,设备未打开,是什么原因,请教一下:
我的代码是:PrivateSubButton_SEND__Click()DimxAsStringIfText_SEND.Text=""Thenx=MsgBox("发送数据...
我的代码是:
Private Sub Button_SEND__Click()
Dim x As String
If Text_SEND.Text = "" Then
x = MsgBox("发送数据不能为空", 16)
End If
If Not MSComm.PortOpen = ture Then
MSComm.PortOpen = ture
End If
MSComm.Output = Text_SEND.Text + Chr$(13)
For i = 1 To 20000000
Next
End Sub
Private Sub Button_RECV_C_Click()
Text_RECV.Text = ""
Text_SEND.SetFocus
End Sub
Private Sub Button_SEND_C_Click()
Text_SEND.Text = ""
Text_SEND.SetFocus
End Sub
Private Sub Form_Load()
MSComm.CommPort = 4
MSComm.Settings = "9600,N,8,1"
MSComm.InputLen = 0
MSComm.InBufferSize = 1024
MSComm.OutBufferSize = 512
MSComm.PortOpen = ture
MSComm.SThreshold = 0
MSComm.RThreshold = 1
MSComm.InBufferCount = 0
MSComm.OutBufferCount = 0
Text_SEND.Text = ""
Text_RECV.Text = ""
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm.CommEvent
Case comEventOverrun
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEventRxOver
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEventTxFull
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEvReceive
Dim str As String
str = MSComm.Input
Text_RECV.Text = Text_RECV.Text + str
End Select
End Sub 展开
Private Sub Button_SEND__Click()
Dim x As String
If Text_SEND.Text = "" Then
x = MsgBox("发送数据不能为空", 16)
End If
If Not MSComm.PortOpen = ture Then
MSComm.PortOpen = ture
End If
MSComm.Output = Text_SEND.Text + Chr$(13)
For i = 1 To 20000000
Next
End Sub
Private Sub Button_RECV_C_Click()
Text_RECV.Text = ""
Text_SEND.SetFocus
End Sub
Private Sub Button_SEND_C_Click()
Text_SEND.Text = ""
Text_SEND.SetFocus
End Sub
Private Sub Form_Load()
MSComm.CommPort = 4
MSComm.Settings = "9600,N,8,1"
MSComm.InputLen = 0
MSComm.InBufferSize = 1024
MSComm.OutBufferSize = 512
MSComm.PortOpen = ture
MSComm.SThreshold = 0
MSComm.RThreshold = 1
MSComm.InBufferCount = 0
MSComm.OutBufferCount = 0
Text_SEND.Text = ""
Text_RECV.Text = ""
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm.CommEvent
Case comEventOverrun
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEventRxOver
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEventTxFull
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEvReceive
Dim str As String
str = MSComm.Input
Text_RECV.Text = Text_RECV.Text + str
End Select
End Sub 展开
3个回答
展开全部
If Not MSComm.PortOpen = ture Then
MSComm.PortOpen = ture
End If
com口反应没有这么快的,得加入延时等待。
另外,你定义的是 MSComm.CommPort = 4
你需要看看是否有这个物理端口。其编号通常是0开始的。
MSComm.PortOpen = ture
End If
com口反应没有这么快的,得加入延时等待。
另外,你定义的是 MSComm.CommPort = 4
你需要看看是否有这个物理端口。其编号通常是0开始的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-22
展开全部
comNoOpen 8012 设备没有打开
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-24
展开全部
看看设备管理器,确定是否有com4?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询