2 zxc7273218 zxc7273218 于 2014.12.14 10:45 提问

关于MSComm1_OnComm事件中Case comEvReceive问题

大家好,
MSComm1_OnComm事件中Case comEvReceive时,非要在comEvReceive后面加个数字才能收到串口发过来的字符,比如Case comEvReceive1或Case comEvReceive22,不加数字就收不到,我的是WIN7系统,奇怪了,请问怎么回事?程序如下(简单测试的):

 Private Sub Command1_Click()
    MSComm1.Output = Text1.Text
End Sub

Private Sub Command2_Click()
    MSComm2.Output = Text2.Text
End Sub

Private Sub Form_Load()
    With MSComm1
        .Settings = "19200,n,8,1"
        .CommPort = 5
        .InputMode = comInputModeText
        .InputLen = 0
        .SThreshold = 1
        .RThreshold = 1
        .OutBufferCount = 0
        .InBufferCount = 0
        If Not .PortOpen Then .PortOpen = True
    End With

    With MSComm2
        .Settings = "19200,n,8,1"
        .CommPort = 6
        .InputMode = comInputModeText
        .InputLen = 0
        .SThreshold = 1
        .RThreshold = 1
        .OutBufferCount = 0
        .InBufferCount = 0
        If Not .PortOpen Then .PortOpen = True
    End With
End Sub

Private Sub MSComm1_OnComm()
    Select Case CommEvent
        Case comEvReceive111
            Text1 = Text1 + MSComm1.Input
    End Select
End Sub

Private Sub MSComm2_OnComm()
    Select Case CommEvent
        Case comEvReceive111
            Text2 = Text2 + MSComm2.Input
    End Select
End Sub

我好像没有悬赏分了,不知道有没有人帮我解答,5555555~~~

3个回答

danielinbiti
danielinbiti   Ds   Rxr 2014.12.17 14:03
已采纳

窗体最上方加上

 Option Explicit

同时
Select Case CommEvent 改成Select Case MSComm2.CommEvent

devmiao
devmiao   Ds   Rxr 2014.12.15 15:45

Case 0
可以收到么?
估计CommEvent返回的是0,comEvReceive111相当于定义了一个新变量,所以相当于0

lzp_lrp
lzp_lrp   Ds   Rxr 2014.12.18 11:52

我一般用

if comEvReceive = 2 then
end if

这么来处理

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!