PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
Declare Function ps4000RunStreaming Lib "ps4000.dll" (ByVal handle As Short, ByRef sampleInterval As UInteger, ByVal sampleIntervalTimeUnits As Integer, ByVal maxPreTriggerSamples As UInteger, ByVal maxPostTriggerSamples As UInteger, ByVal autoStop As Short, ByVal downSampleRatio As UInteger, ByVal overviewBufferSize As UInteger) As Integer
Declare Function ps4000GetStreamingLatestValues Lib "ps4000.dll" (ByVal handle As Short, ByVal lpPs4000Ready As myDelCallback, ByRef pParameter As IntPtr) As Integer
' This is the callback for the picoscope when streaming has occurred and data is ready.
Public Delegate Sub myDelCallback(ByVal handle As Short, ByVal noOfSamples As Integer, ByVal startIndex As UInteger, ByVal overflow As Short, ByVal triggerAt As UInteger, ByVal triggered As Short, ByVal autoStop As Short)
' This is the delegate method to update UI
Public Delegate Sub setScopeInvoker(ByVal textValue As String)
' *****************************************************
' User clicks this button on UI to initiate the streaming process
' *****************************************************
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
CollectStream(UnitModel, TrigSettings)
Dim tparam As New Thread(DirectCast(Sub() BackgroundProcess_getOscilloscopeData(UnitModel, "TEMP_STRING"),
ThreadStart))
If tparam IsNot Nothing AndAlso tparam.IsAlive() Then
tparam.Abort()
End If
tparam.Start()
End Sub
' ******************************************************************
' This function begins calls the streaming code for picoscope
' ******************************************************************
Private Sub BackgroundProcess_getOscilloscopeData(ByRef UnitModel As UNIT_MODEL, ByVal textCommand As String)
StreamDataHandler(UnitModel)
End Sub
' *****************************************************************
' Perform the actual code here
' *****************************************************************
Sub StreamDataHandler(ByRef UnitModel As UNIT_MODEL)
Dim status As Short
Dim buffers(99) As Short ' Using different buffer lengths to see if I could fix the problem
Dim no_of_samples As Integer ' Only using a single channel, thus not using a 2D array
Dim i As Integer = 0
Dim max_samples As Integer
Dim time_interval As Integer
Dim timebase As Integer
no_of_samples = 100
status = ps4000SetDataBuffer(UnitModel.handle, chan, buffers(0), no_of_samples)
g_autoStop = False
'OBTAIN AN APPROPRIATE TIME BASE
timebase = 0 'try the fastest sample rate first, and increase timebase value until the call succeeds
While (ps4000GetTimebase(UnitModel.handle, timebase, no_of_samples, time_interval, 1, max_samples, 0) <>
PICO_OK)
timebase = timebase + 1
End While
Dim p As New IntPtr
' BEGIN STREAMING FROM SCOPE, IS MY SAMPLEINTERVAL APPROPRIATE FOR A 60HZ SIGNAL?
sampleInterval = 1
status = ps4000RunStreaming(UnitModel.handle, sampleInterval, TimeUnits.PS4000_MS, 0, no_of_samples, False, 1,
no_of_samples)
While g_autoStop = 0
System.Threading.Thread.Sleep(100)
g_ready = False
status = ps4000GetStreamingLatestValues(UnitModel.handle, AddressOf sayHello, p)
If g_ready And g_sampleCount > 0 Then ' Can be ready and have no data, if autostop has fired
totalSamples += g_sampleCount
' OUTPUT WHATEVER WAS GRABBED FROM EACH SUCCESSFUL CALL TO GETSTREAMINGLATEST..
For k As Integer = 0 To g_sampleCount - 1
test = adc_to_mv(buffers(k), UnitModel.channelSettings(chan).range)
[b]showScopeValue(test.ToString) ' DELEGATE FUNCTION TO UPDATE UI
' NOTE: This is where the problem occurs.. after totalsamples > 1000, i get the fatalerror.
' This occurs when runstreaming and getstreaminglatestvalues are both successful.
' I suspect it has to do with the no_of_samples, or the sampleInterval I am passing in as parameters to
' the runstreaming function[/b]
Next
End if
End While
Call ps4000Stop(UnitModel.handle)
End Sub
' *************************************************************************
' This procedure is called to update the main UI safely
' *************************************************************************
Public Sub showScopeValue(ByVal textValue As String)
If Me.lb_scopeValue.InvokeRequired Then
Dim del As New setScopeInvoker(AddressOf showScopeValue)
Me.lb_scopeValue.Invoke(del, textValue)
Else
Me.lb_scopeValue.Text = textValue.ToString
End If
End Sub
Code: Select all
Declare Function GetStreamingLatestValues Lib "ps4000wrap.dll" (ByVal handle As Integer) As Integer
Declare Function AvailableData Lib "ps4000wrap.dll" (ByVal handle As Integer, ByRef startIndex As Long) As Long
Declare Function AutoStopped Lib "ps4000wrap.dll" (ByVal handle As Integer) As Integer
Declare Function IsReady Lib "ps4000wrap.dll" (ByVal handle As Integer) As Integer