补充一下,用串口调试工具可以实现上述的仪器数据上传,可以用我自己编程的就不行,我觉得应该是编程有问题,可能是数据转换或者是没有读出,是不是必须要有commevent才行呢?

解决方案 »

  1.   

    你没有设置 MSComm1的 停止位,奇偶检验,波特率,数据位
    而且你传出的是字符串类型,你试试把 'MSComm1.Output = Text1.Text' 改成 MSComm1.Output = Cbyte(Text1.Text)
      

  2.   

    推荐使用portmon软件辅助调试串口通信程序。
      

  3.   

    Dim nBytes As Long
    nBytes=10
    redim Bytes(nBytes-1)
    ...
    nBytes=20
    redim Bytes(nBytes-1)
    ...
      

  4.   

    仅供参考:
    Private Sub tcpCAS_DataArrival(ByVal bytesTotal As Long)
    Dim i As Long
    Dim Total_Length As Long
    Dim iBuf() As Byte
    Dim lnx As String
        On Error Resume Next
    '   收当前流
        ReDim iBuf(bytesTotal - 1)
        tcpCAS.GetData iBuf
        'log每个收到的字节
        i = 0
        lnx = "cas-->BYTE:" + Right("0000000" + Hex(i), 8) + "-"
        For i = 0 To bytesTotal - 1
            lnx = lnx + " " + Right("0" + Hex(iBuf(i)), 2)
            If i Mod 16 = 15 Then
                logtofile lnx
                lnx = "cas-->BYTE:" + Right("0000000" + Hex(i + 1), 8) + "-"
            End If
        Next
        i = bytesTotal - 1
        If i Mod 16 <> 15 Then
            logtofile lnx
        End If
    End Sub
    Private Sub logtofile(s As String)
    Dim f As Integer
    On Error Resume Next
        log s
        f = FreeFile()
        Open App.Path + "\VBS1.LOG" For Append As #f
        Print #f, Format(Now, "YYYY-MM-DD hh:mm:ss") + " " + s
        Close #f
        If FileLen(App.Path + "\VBS1.LOG") > MAXLOGFILESIZE Then
            Kill App.Path + "\VBS2.LOG"
            Name App.Path + "\VBS1.LOG" As App.Path + "\VBS2.LOG"
        End If
    End Sub