Live data from Comm1 via VB to Excel
Hello
First of all I’m a beginner in visual basic. I have to find a solution for my problem and I’m hoping some of you will help me.
I try to read data from external device.
‘Private Sub Command_Click()
‘
‘’time = Now()
Debug.Print time + delay
Do While Now() < time + delay
Do
DoEvents
buffer = buffer & MSComm1.Input
Loop Until InStr(buffer, vbCrLf)
Text2.Text = buffer
plot = CDbl(buffer)
buffer = ""
Loop
“””
‘
‘
‘’
‘
####Code Excel####
oSheet.cells(i, 2) = plot
####code######
End
The Problem is I just get a last value when the time is over. What I want is to refresh (plot Variable) in Excel with every input change.
Thanks in advance
Re: Live data from Comm1 via VB to Excel
Don't use a timer to time serial input. Use the OnComm event to check the buffer for vbCrLf. When you have it, the buffer will be filled with your data.
CDbl(buffer) will only work if buffer (which has to be defined as String) contains a string that equates to a number. Check it and remove any non-numeric characters before converting it. If there's a vbCrLf in the middle of the string in the buffer, CDbl will throw an error.
Re: Live data from Comm1 via VB to Excel