我在用mscomm控件编pc机与数采卡的串口通信,数采卡说明书上,通讯协议:被动查询。pc机发送ASCII字母“@00R”,数采卡就会返回数值。我编了以下程序,可是数采卡没反应,大家能帮我看下问题在哪里吗?谢谢!
Private Sub Command1_Click()
Dim instring As String
Dim a As Variant
MSComm1.PortOpen = True
a = "@00R"
MSComm1.Output = a
10  DoEvents
If MSComm1.OutBufferCount >= 64 Then
instring = MSComm1.Input
Text1.Text = instring
End If
GoTo 10
End Sub
在mscomm属性上已经设定了commport和settings

解决方案 »

  1.   

    有没有尝试修改handshaking设置
      

  2.   

    If MSComm1.OutBufferCount >= 64 Then
    instring = MSComm1.Input
    Text1.Text = instring
    End If
    ----------------
    这怎么能行呢?一般来说处理接收事务是在mscomm的oncomm()里进行处理的!
    Private Sub Form_Load()    ClearText    With MSC        .CommPort = 1  '设置Com1为通信端口        .Settings = "9600,E,7,2"  '设置通信端口参数 9600赫兹、偶校验、7个数据位、1个停止位.(这里需要进一步说明的是:.Setting=”BBBB,P,D,S”。含义是:B:Baud Rate(波特率);P:Parity(奇偶);D:Data Bit;S:Stop Bit)        .InBufferSize = 40  '设置缓冲区接收数据为40字节        .InputLen = 1  '设置Input一次从接收缓冲读取字节数为1        .RThreshold = 1  '设置接收一个字节就产生OnComm事件    End With
    Private Sub MSC_OnComm()    DelayTime   ‘用来延续时间    ClearText    With MSC        Select Case .CommEvent  '判断通信事件            Case comEvReceive:  '收到Rthreshold个字节产生的接收事件                SwichVar 1                If Out(1) = 2 Then  '判断是否为数据的开始标志                    .RThreshold = 0   '关闭OnComm事件接收                End If                Do                    DoEvents                Loop Until .InBufferCount >= 3  '循环等待接收缓冲区>=3个字节'                nRece = nRece + 1                For i = 2 To 12                    SwichVar i                    Text1.Text = Text1.Text & Chr(Out(i))                Next                Text1.Text = LTrim(Text1.Text)                Text2.Text = Text2.Text & CStr(nRece)                .RThreshold = 1  '打开MSComm事件接收            Case Else'                .PortOpen = False        End Select    End WithEnd Sub也就是接收到结束字符后触发ONCOMM事件,进行数据处理代码!