Sorry, but I am not a very sophisticated user of VBA, and need more explicit guidance.
For the PCS500, I am using this script, which came from the Help file:
Sub ReadAll()
Dim i As Long
ReadCh1 DataBuffer1(0)
ReadCh2 DataBuffer2(0)
With ActiveSheet
For i = 5 To 4100
.Cells(i + 1, 6) = DataBuffer1(i)
.Cells(i + 1, 7) = DataBuffer2(i)
Next i
End With
End Sub
The time-step comes from the timing setting in PC Lab 2000se (slowest button is 100ms/division, which accordingly to the output file produces readings at 1250 Hz, or 0.8 ms per step.
I inserted a call to this sub within the Start sub:
Sub Start()
Dim i As Long
Range(“B7:E4000”).Select
Selection.ClearContents
Range(“B6”).Select
For i = 1 To 4
ActiveSheet.Cells(10, i) = “CH” + CStr(i)
Next i
StartDevice
StartTimer
Row = 7
ReadAll
End Sub
And I modified the Read_Data (for the PCS10) to read exactly 4100 times (instead of waiting for Stop), like this:
Sub Read_Data()
Dim i As Long
ReadData DataBuffer(0)
With ActiveSheet
For Row = 7 To 4107
For i = 2 To 5
.Cells(Row, i - 1) = DataBuffer(i)
Next i
Next Row
End With
End Sub
But it still seems to keep looping until I hit Stop.
If that is too confusing, the whole module looks like this. Any help would be greatly appreciated:
Option Explicit
Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
'GENERAL PROCEDURES
Private Declare Sub StartDevice Lib “k8047d.dll” ()
Private Declare Sub StopDevice Lib “k8047d.dll” ()
'INPUT PROCEDURE
Private Declare Sub ReadData Lib “k8047d.dll” (Array_Pointer As Long)
'OUTPUT PROCEDURE
Private Declare Sub SetGain Lib “k8047d.dll” (ByVal Channel_no As Long, ByVal Gain As Long)
Private Declare Sub LEDon Lib “k8047d.dll” ()
Private Declare Sub LEDoff Lib “k8047d.dll” ()
'Declare variables
Dim DataBuffer(0 To 7) As Long
Dim Row As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Sub StartTimer()
TimerSeconds = 0.01 ’ .01 sec interval.
TimerID = SetTimer(0&, 0&, TimerSeconds!, AddressOf TimerProc)
End Sub
Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
End Sub
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
’
’ The procedure is called by Windows. Put your
’ timer-related code here.
’
Read_Data
’
End Sub
Sub Start()
Dim i As Long
Range(“B7:E4000”).Select
Selection.ClearContents
Range(“B6”).Select
For i = 1 To 4
ActiveSheet.Cells(10, i) = “CH” + CStr(i)
Next i
StartDevice
StartTimer
Row = 7
ReadAll
End Sub
Sub Quit()
EndTimer
StopDevice
End Sub
Sub Settings()
SetGain 1, 1
SetGain 2, 2
SetGain 3, 5
SetGain 4, 10
End Sub
Sub Read_Data()
Dim i As Long
ReadData DataBuffer(0)
With ActiveSheet
For Row = 7 To 4107
For i = 2 To 5
.Cells(Row, i - 1) = DataBuffer(i)
Next i
Next Row
End With
End Sub