I wrote a program to log data from a pic into excel. The program works fine but uses a lot of cpu power (50%) on small pc's when looping for new data.
what can I change to use less cpu power when waiting for data from the com port?
Code: Select all
Private Sub CommandButton3_Click()
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long
Dim strData As String
Dim out_of_time As Boolean
Dim time As Single
Dim buffer As String
Dim i As Integer
For i = 1 To 20
buffer = ""
time = Timer()
intPortID = 1
Do
lngStatus = CommRead(intPortID, strData, 1)
Loop Until strData = "#" 'Read port until start bit is found.
Do
lngStatus = CommRead(intPortID, strData, 16)
buffer = buffer & strData
out_of_time = Timer() > time + 10
Loop Until strData = Chr(13) Or out_of_time Loop until end character is found.
If out_of_time <> False Then
buffer = "Out Of Time"
End If
Sheet1.Cells(i, 1) = buffer
Next i ' take 20 readings from com port and plot data into excel sheet.
Sheet1.Cells(22, 1) = "Test Complete" 'Write test complete in A22
End Sub