PDA

Click to See Complete Forum and Search --> : Pausing/ Continuing COM data in VBA


FAM
Nov 29th, 2002, 04:16 AM
I have the code below which reads data from the COM port into Excel which I use the cmdRecord button, I also have a stop and clear buttons but what Im really to struggling to write is a Pause/Continue button either on the same button or seperate.
Anyone got any ideas?

Thanks in Advance
---------------------------------------
Private blnExitLoop As Boolean
Dim value As Long
Dim ok As Boolean
Dim I As Integer
Dim port As Integer

Private Sub cmdRecord_Click()
Worksheets("Sheet1").Range("A17:B10000,I4:I5").Clear
blnExitLoop = True

port = 1 ' You have to specify port for this to work correctly
Cells(4, "I").value = "Opening ADC on COM" & port

ok = adc16_open_unit(port)
If ok Then
Cells(4, "I").value = "ADC opened"
Cells(5, "I").value = port
' Specify 16-bit resolution for channels 1 and 2
ok = adc16_set_channel(port, 1, 10, True, 10)
ok = adc16_set_channel(port, 2, 10, True, 10)

' Get 50 readings from these channels

For I = 1 To 50

ticks = GetTickCount()
While GetTickCount() < ticks + 1000
' Let Excel carry on doing things

DoEvents

' Excel doesn't let timer ticks thru to adc16 driver...
' Must call the poll routine to keep data flowing
adc16_poll
Wend
If blnExitLoop = True Then
ok = adc16_get_value(value, port, 1)
If ok Then
Cells(I + 17, "A").value = value * 2500 / 65535
Else
Cells(I + 17, "A").value = "****"
End If

ok = adc16_get_value(value, port, 2)
If ok Then
Cells(I + 17, "B").value = value * 2500 / 65535
Else
Cells(I + 17, "B").value = "****"
End If
Else
Exit For
End If
Next I

' Close the driver
Call adc16_close_unit(port)
Else
Cells(4, "I").value = "Unable to open ADC"
End If
End Sub