How to gather data via RS 232 and import it to Excel using VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krazyjoe
    New Member
    • Oct 2006
    • 2

    How to gather data via RS 232 and import it to Excel using VBA

    I have a Fluke 45 series multimeter. I would like to gather data from it through MS Excel and VBA. I have no trouble sending commands to the multimeter but I cannot figure out how to read data from the output buffer. I am going to go learn about MSCOMM32.OCX and see if it will be helpful. Any other suggestions would be great. Thanks in advance.

    Joe
  • albertw
    Contributor
    • Oct 2006
    • 267

    #2
    Originally posted by krazyjoe
    I have a Fluke 45 series multimeter. I would like to gather data from it through MS Excel and VBA. I have no trouble sending commands to the multimeter but I cannot figure out how to read data from the output buffer. I am going to go learn about MSCOMM32.OCX and see if it will be helpful. Any other suggestions would be great. Thanks in advance.

    Joe
    hi
    an example of how to save incoming data from rs232
    you may have to change settings and/or options because i don't know the specific format in which your device is sending data.

    Code:
    Private Sub Form_Load()
    ' chose correct settings for your device
    Settings = "9600,n,8,1"
    MSComm1.Settings = Settings
    MSComm1.Commport = 1
    
    With MSComm1
    ' receive chr by chr
        .InputLen = 1
        .RThreshold = 0
        .SThreshold = 0
        .InBufferSize = 10240       '10kb
        .InputMode = comInputModeText
        .Handshaking = 0            'None
    End With
    End Sub
    
    Private Sub Receive()
    FileName = App.Path & "\RS232.dat"
    Open FileName For Output As #1
        Do
        DoEvents
        RxTxt = MSComm1.Input
    ' start capture if you get some input
    ' you may also wait for some other specific character
        Loop Until RxTxt > vbNullString
        inbuff = vbNullString
       
        Do
        DoEvents
        RxTxt = MSComm1.Input
    ' data is supposed to be separated by Chr(10)
    ' chose another separationmark if neccesary
            If RxTxt = Chr(10) And Len(inbuff) > 0 Then
                If Left(inbuff, 1) = Chr(10) Then inbuff = Right(inbuff, Len(inbuff) - 1)
                Print #1, inbuff
                inbuff = vbNullString
            Else
                If Len(RxTxt) > 0 Then
                inbuff = inbuff + RxTxt
                End If
            End If
    ' data is supposed to end with Chr(3)
    ' chose another endmark if neccesary
        Loop Until RxTxt = Chr(3)
    Close
    End Sub

    Comment

    • krazyjoe
      New Member
      • Oct 2006
      • 2

      #3
      Thanks... very helpful

      Comment

      • tqm1
        New Member
        • Jun 2007
        • 1

        #4
        Dear Sir,

        Your codes save mscomm data to the following file.
        FileName = App.Path & "\RS232.dat "

        But I want to show the data into listbox

        Please help

        Comment

        Working...