PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
Imports System.Runtime.InteropServices
Imports System
Module PS2000
'Driver Function calls
Declare Function ps2000_open_unit Lib "ps2000.dll" () As Short
Declare Function ps2000_get_unit_info Lib "ps2000.dll" (ByVal handle As Short, ByVal info As String, ByVal stringLength As Short, ByVal line As Short) As Short
Declare Function ps2000_set_channel Lib "ps2000.dll" (ByVal handle As Short, ByVal channel As Short, ByVal enabled As Short, ByVal dc As Short, ByVal range As Short) As Short
Declare Function ps2000_set_trigger Lib "ps2000.dll" (ByVal handle As Short, ByVal source As Short, ByVal threshold As Short, ByVal direction As Short, ByVal delay As Short, ByVal auto_trigger_ms As Short) As Short
Declare Function ps2000_run_streaming_ns Lib "ps2000.dll" (ByVal handle As Short, ByVal sample_interval As UInteger, ByVal time_units As Integer, ByVal max_samples As UInteger, ByVal auto_stop As Short, ByVal noOfSamplesPerAggregate As UInteger, overview_buffer_size As UInteger) As Short
Declare Function ps2000_get_values Lib "ps2000.dll" (ByVal handle As Short, ByVal buffer_a As Short, ByVal buffer_b As Short, ByVal buffer_c As Short, ByVal buffer_d As Short, ByVal overflow As Short, ByVal no_of_samples As Long) As Short
Declare Function ps2000_get_streaming_last_values Lib "ps2000.dll" (ByVal handl As Short, ByVal lpGetOverviewBuffersMaxMin As my_get_overview_buffers) As Short
Declare Function ps2000_close_unit Lib "ps2000.dll" (ByVal handle As Short) As Short
'Creates callback delegate
Public Delegate Sub my_get_overview_buffers(ByRef Overviewbuffer As IntPtr, ByVal overflow As Short, ByVal triggeredAt As UInteger, ByVal triggered As Short, ByVal autoStop As Short, ByVal nValues As UInteger)
Public ps2000StreamingCallBack As my_get_overview_buffers
Public overviewbuffersize As UInteger = 50000
Public appBuffer(199999) As Short
Public _AutoStop As Boolean
Public _nValues As UInteger
Public _TotalNSamples As UInteger
Public overviewbuffersafe(overviewbuffersize) As Short
Sub Main()
Dim handle As Short
Dim status As Short
Dim file As IO.StreamWriter
handle = ps2000_open_unit 'Opens unit and gets handle to control unit
If handle = 0 Then 'if device is not openned then do not run the rest of the code
End
End If
status = ps2000_set_channel(handle, 0, 1, 1, 7) 'handle, channel(A), enable(1), voltage range(+/-2V)
status = ps2000_set_channel(handle, 1, 0, 1, 7) 'handle, channel(B), enable(0), voltage range(+/-2V) Channel B must be off
'status = ps2000_set_trigger(handle, 0, 8, 0, 0, 1) 'set trigger source = Chan A, threshold = 8bits, direction= rising, delay = 0, auto_trigger_ms = 1
_AutoStop = 0
_TotalNSamples = 0
ps2000StreamingCallBack = New my_get_overview_buffers(AddressOf StreamingCallBack) 'links function to callback of driver
status = ps2000_run_streaming_ns(handle, 1, 3, 100000, 1, 1, overviewbuffersize) ' Starts device streaming
While (Not _AutoStop)
ps2000_get_streaming_last_values(handle, ps2000StreamingCallBack) 'trys to pull data from device
End While
file = My.Computer.FileSystem.OpenTextFileWriter("stream.txt", False)
For i As Integer = 0 To _TotalNSamples - 1
file.WriteLine(appBuffer(i))
Next
file.Close()
Console.WriteLine()
ps2000_close_unit(handle)
End Sub
Public Sub StreamingCallBack(ByRef Overviewbuffer As IntPtr, ByVal overflow As Short, ByVal triggeredAt As UInteger, ByVal triggered As Short, ByVal autoStop As Short, ByVal nValues As UInteger)
Dim count As Integer = 0
_AutoStop = Convert.ToBoolean(autoStop)
_nValues = nValues
If Not nValues = 0 Then 'if no values are pulled from device return to main thread
Marshal.Copy(Overviewbuffer, overviewbuffersafe, 0, _nValues)
Try
Array.Copy(overviewbuffersafe, 0, appBuffer, _TotalNSamples, _nValues)
Catch ex As Exception
Console.WriteLine("AppBuffer overflowing please resize")
End Try
End If
_TotalNSamples += _nValues
End Sub
End Module