PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
Option Explicit
Declare Function ps2000_open_unit Lib "ps2000" () As Integer
Declare Function ps2000_set_unit Lib "ps2000.dll" (ByVal handle As Integer) As Integer
Declare Function ps2000_flash_led Lib "ps2000.dll" (ByVal handle As Integer) As Integer
Declare Sub ps2000_close_unit Lib "ps2000.dll" (ByVal handle As Integer)
Declare Function ps2000_get_unit_info Lib "ps2000.dll" (ByVal handle As Integer, ByVal Str As String, ByVal lth As Integer, ByVal line_no As Integer) As Integer
Declare Function ps2000_set_channel Lib "ps2000.dll" (ByVal handle As Integer, ByVal channel As Integer, ByVal enabled As Integer, ByVal dc As Integer, ByVal range As Integer) As Integer
Declare Function ps2000_set_trigger2 Lib "ps2000.dll" (ByVal handle As Integer, ByVal source As Integer, ByVal threshold As Long, ByVal direction As Integer, ByVal delay As Integer, ByVal auto_trigger_ms As Integer) As Integer
Declare Function ps2000_get_timebase Lib "ps2000.dll" (ByVal handle As Integer, ByVal timebase As Integer, ByVal no_of_samples As Long, time_interval As Long, time_units As Integer, ByVal oversample As Integer, max_samples As Long) As Integer
Declare Function ps2000_run_block Lib "ps2000.dll" (ByVal handle As Integer, ByVal no_of_values As Long, ByVal timebase As Integer, ByVal oversample As Integer, time_indisposed_ms As Long) As Integer
Declare Function ps2000_ready Lib "ps2000.dll" (ByVal handle As Integer) As Integer
Declare Function ps2000_run_streaming Lib "ps2000.dll" (ByVal handle As Integer, ByVal time_interval As Long, ByVal max_samples As Long, ByVal windowed As Integer) As Integer
Declare Function ps2000_get_values Lib "ps2000.dll" (ByVal handle As Integer, buffer_a As Integer, buffer_b As Integer, buffer_c As Integer, buffer_d As Integer, overflow As Integer, ByVal no_of_values As Long) As Long
Declare Function ps2000_get_times_and_values Lib "ps2000.dll" (ByVal handle As Integer, times As Long, buffer_a As Integer, buffer_b As Integer, buffer_c As Integer, buffer_d As Integer, overflow As Integer, ByVal time_units As Integer, ByVal no_of_values As Long) As Long
Declare Function ps2000_stop Lib "ps2000.dll" (ByVal handle As Integer) As Integer
Declare Function ps2000_run_streaming_ns Lib "ps2000.dll" (ByVal handle As Integer, ByVal sample_interval As Long, ByVal time_units As Integer, ByVal max_samples As Long, ByVal auto_stop As Integer, ByVal noOfSamplesPerAggregate As Long, ByVal overview_buffer_size As Long) As Integer
Declare Function ps2000_get_streaming_values_no_aggregation Lib "ps2000.dll" (ByVal handle As Integer, ByRef start_time As Double, ByRef pBuffer_a As Integer, ByRef pBuffer_b As Integer, ByRef pBuffer_c As Integer, ByRef pBuffer_d As Integer, ByRef overflow As Integer, ByRef triggerAt As Long, ByRef trigger As Integer, ByVal values As Long) As Long
Declare Function ps2000_set_ets Lib "ps2000.dll" (ByVal handle As Integer, ByVal mode As Integer, ByVal ets_cycles As Integer, ByVal ets_interleave As Integer) As Long
Declare Function ps2000_set_sig_gen_built_in Lib "ps2000.dll" (ByVal handle As Integer, ByVal offsetVoltage As Long, ByVal pkToPk As Long, ByVal waveType As Integer, ByVal startFrequency As Single, ByVal stopFrequency As Single, ByVal incriment As Single, ByVal dwellTime As Single, ByVal sweepType As Integer, ByVal sweeps As Long) As Integer
' Wrapper Functions
Declare Function PollFastStreaming Lib "ps2000Wrap.dll" (ByVal handle As Integer) As Integer
Declare Function FastStreamingReady Lib "ps2000Wrap.dll" (ByVal handle As Integer) As Integer
Declare Function GetFastStreamingDetails Lib "ps2000Wrap.dll" (ByVal handle As Integer, ByRef overflow As Integer, ByRef triggeredAt As Long, ByRef triggered As Integer, ByRef auto_stop As Integer, ByRef appBufferFull As Integer, ByRef startIndex As Long) As Long
Declare Sub clearFastStreamingParameters Lib "ps2000Wrap.dll" (ByVal handle As Integer)
Declare Sub SetBuffer Lib "ps2000Wrap.dll" (ByVal handle As Integer, ByVal channel As Integer, ByRef buffer As Integer, ByVal bufferSize As Long) ' , ByVal buffersize As Long)
Declare Sub Sleep Lib "kernel32.dll" (ByVal Time As Long)
Dim ps2000_handle As Integer
Dim i As Integer
Dim j As Integer
Dim S As String * 255
Dim no_of_samples As Long
Dim ok As Integer
Dim outputFilePath As String
Dim timebase As Integer
Dim time_interval As Long
Dim time_units As Integer
Dim oversample As Integer
Dim time_indisposed_ms As Long
Dim Channel_num As String
Dim channel As Integer
Dim Alpha As Integer
Dim use_trigger As Boolean
Dim no_of_values As Long
Dim buffer_a(100) As Integer
Dim buffer_b(100) As Integer'
Dim buffer_c(100) As Integer
Dim buffer_d(100) As Integer
Dim times(100) As Long
Sub Main
' Global variables
'Dim timebase As Integer
'Dim time_interval As Long
'Dim time_units As Integer
'Dim oversample As Integer
Dim time_indisposed_ms As Long
Dim S As String * 255
'Dim ps2000_handle As Integer
Dim mv As Integer
Dim i As Integer
Dim j As Integer
'Dim S As String * 255
'Dim no_of_samples As Long
Dim ok As Integer
'Dim outputFilePath As String
'Dim Channel_num As String
use_trigger=False
If ps2000_handle=0 Then
ps2000_handle = ps2000_open_unit()
End If
If ps2000_handle = 0 Then
MsgBox "Unit not opened", vbOkOnly, "Error Message"
Call ps2000_close_unit(ps2000_handle)
Exit Sub
Else
MsgBox("PS2000 successfully opened")
End If
Begin Dialog UserDialog 930,413 ' %GRID:10,7,1,1
PushButton 80,84,140,42,"Block Mode",.PushButton1
PushButton 80,210,140,42,"Streaming Data",.PushButton2
PushButton 80,329,140,42,"Signal Generator",.PushButton3
Text 290,77,580,63,"In block mode, you will prompt the oscilloscope to collect a block of data and store it inside the buffer. When the oscilloscope has collected the whole block it then transfers the whole block to computer and; subsequently, the user's defined data file. This method provides the highest sampling rates but is limmited in the number of data points; determined by the oscilliscopes internal memory capacity. ",.Text1
Text 290,210,600,63,"At all but the highest sampling rates, this mode allows accurately timed data to be transferred back to the computer without gaps. The oscilloscope thentransfers data back to the computer without storing it in its own memory, so the size of the data set is limited only by the size of the computer's memory. Sampling intervals from less than one microsecond to 60 seconds are possible.",.Text2
Text 290,329,600,35,"Signal Gerator Only!This option allows you to use the oscillioscope as a function generator. Note: This option limits you to only using this as a function generator. If you would like to collect data while using a channel to generate a signal, please select one of the above options. ",.Text3
Text 400,14,140,21,"Please Select A Mode",.Text4
End Dialog
Dim dlg As UserDialog
Dim button As Integer
button=Dialog(dlg)
Select Case button
Case 1 'first button
MsgBox "trying to call get data sub"
Call BlockMode()
Case 2 'second button
MsgBox "trying to call streaming data sub"
Call StreamingData()
Exit Sub
Case 3 'thrid button
MsgBox "trying to call Signal gen sub"
Alpha=1
Call SigGen(Alpha)
Exit Sub
End Select
End Sub
Sub BlockMode()
On Error GoTo UserWindow
'ReDim buffer_a(100) As Integer
'ReDim buffer_b(100) As Integer'
'ReDim buffer_c(100) As Integer
'ReDim buffer_d(100) As Integer
'ReDim times(100) As Long
Dim overflow As Integer
Dim max_samples As Long
Dim ok As Integer
Dim timebase As Integer
MsgBox("Select/Create your output file")
outputFilePath = GetFilePath(,"dat",,"Select or create your output file",1)
If outputFilePath="" Then
MsgBox("User canceled: Exiting")
Call ps2000_close_unit(ps2000_handle)
Exit Sub
End If
UserWindow:
If Err.Number <> 0 Then
MsgBox("Error: " + Err.Description)
If Err.Description = "User pressed cancel" Then
Call ps2000_close_unit(ps2000_handle)
Exit All
End If
Debug.Print(Err.Description)
Debug.Clear
Call ps2000_close_unit(ps2000_handle)
ps2000_handle=0
Exit All
End If
Begin Dialog UserDialog 400,203 ' %GRID:10,7,1,1
OKButton 40,147,140,35
CancelButton 210,147,140,35
CheckBox 100,28,150,28,"Channel ""A""",.CheckBox1
CheckBox 100,63,150,28,"Channel ""B""",.CheckBox2
CheckBox 100,98,150,21,"Signal Generator",.CheckBox3
Text 100,7,170,21,"Select Which Channels Will Be Used",.Text1
End Dialog
Dim dlg As UserDialog
Dialog dlg
If dlg.CheckBox1 = 1 Then ' User chose Channel A
Channel_num="A"
Call Channel_Use(Channel_num)
End If
If dlg.CheckBox2 = 1 Then ' User chose Channel B
Channel_num="B"
Call Channel_Use(Channel_num)
End If
If dlg.CheckBox3 = 1 Then ' User chose Channel C
Alpha=2
Call SigGen(Alpha)
End If
If dlg.CheckBox1=0 And dlg.CheckBox2=0 And dlg.Checkbox3=0 Then
MsgBox"No Channels Were Selected: Exiting"
Exit All
End If
If use_trigger=False Then
Call ps2000_set_trigger2(ps2000_handle,5,0,0,0,0)
End If
Begin Dialog UserDialog 400,203 ' %GRID:10,7,1,1
Text 110,14,190,35,"Please Set The Time Base, Number Of Samples, And The OverSample",.Text1
Text 30,63,70,14,"Time Base",.Text2
Text 140,63,130,14,"Number Of Samples",.Text3
TextBox 20,91,90,21,.TextBox1
TextBox 160,91,90,21,.TextBox2
OKButton 50,147,120,35
CancelButton 220,147,120,35
Text 290,63,90,14,"Oversample",.Text4
TextBox 290,91,90,21,.TextBox3
End Dialog
Dim dlg1 As UserDialog
Dialog dlg1
Call ps2000_get_timebase(ps2000_handle,13,100,time_interval,2, oversample ,max_samples)
Call ps2000_run_block(ps2000_handle, 100, 13, oversample, time_indisposed_ms)
While ps2000_ready(ps2000_handle) = 0
MsgBox("Waiting for Trigger Even Or Collecting Data in the Buffer.")
Wend
Call ps2000_stop(ps2000_handle)
Dim stuff As Integer
stuff = ps2000_get_times_and_values(ps2000_handle, times(0), values_a(0), values_b(0), values_c(0), values_d(0), 1, 2, no_of_values)
stuff = ps2000_get_values(ps2000_handle, buffer_a(0), buffer_b(0), buffer_c(0), buffer_d(0), 0, no_of_values)
MsgBox (" is get values working " + CStr(stuff) + "0 means no ")
Open outputFilePath For Output As #2
For i = 0 To 99
If i = 0 Then
Print #2, "time";",";"Channel A";",";"Channel B"
Else
Print #2, 0; ","; (buffer_a(i)/32767)*20000;",";(buffer_b(i)/32767)*20000
End If
Next i
Close #2
Call ps2000_close_unit(ps2000_handle)
End Sub
Sub Channel_Use(Channel_num)
On Error GoTo Operation
Operation:
If Err.Number <> 0 Then
MsgBox("Error: " + Err.Description)
If Err.Description = "User pressed cancel" Then
Debug.Print(Err.Description)
Debug.Clear
Exit Sub
End If
Debug.Print(Err.Description)
Debug.Clear
Exit All
End If
Begin Dialog UserDialog 470,182 ' %GRID:10,7,1,1
PushButton 70,77,120,42,"Measurement",.PushButton1
PushButton 260,77,120,42,"Trigger",.PushButton2
Text 70,7,270,21,"What Will Channel " + Channel_num + " Be Used For",.Text1
End Dialog
Dim dlg As UserDialog
Dim Channel_A_Property As Integer
Channel_A_Property=Dialog(dlg)
Select Case Channel_A_Property
Case 1 'User selected Measurement
Call Channel_Measurement (Channel_num)
Case 2 'User selected Trigger
use_trigger=True
Call Channel_Trigger(Channel_num)
End Select
End Sub
Sub Channel_Measurement(Channel_num)
On Error GoTo MeasureSetUp
MeasureSetUp:
If Err.Number <> 0 Then
MsgBox("Error: " + Err.Description)
If Err.Description = "User pressed cancel" Then
Call ps2000_close_unit(ps2000_handle)
Exit Sub
End If
Debug.Print(Err.Description)
Debug.Clear
Call ps2000_close_unit(ps2000_handle)
Exit All
End If
Begin Dialog UserDialog 400,490 ' %GRID:10,7,1,1
GroupBox 210,175,160,126,"Select Coupling",.GroupBox1
OptionGroup .Group1
OptionButton 220,266,150,21,"AC Coupling",.OptionButton1
OptionButton 220,217,140,21,"DC Coupling",.OptionButton2
GroupBox 40,77,150,308,"Select Voltage Range",.GroupBox2
OptionGroup .Group2
OptionButton 50,105,100,21,"+/- 20 mV",.OptionButton3
OptionButton 50,133,100,21,"+/- 50 mV",.OptionButton4
OptionButton 50,161,100,21,"+/- 100 mV",.OptionButton5
OptionButton 50,189,100,21,"+/- 200 mV",.OptionButton6
OptionButton 50,217,100,21,"+/- 500 mV",.OptionButton7
OptionButton 50,245,100,21,"+/- 1 V",.OptionButton8
OptionButton 50,273,100,21,"+/- 2 V",.OptionButton9
OptionButton 50,301,100,21,"+/- 5 V",.OptionButton10
OptionButton 50,329,100,21,"+/- 10 V",.OptionButton11
OptionButton 50,357,100,21,"+/- 20 V",.OptionButton12
Text 120,21,150,28,"Set-up Channel " + Channel_num + " Measurements",.Text1
OKButton 40,434,140,35
CancelButton 220,434,140,35
End Dialog
Dim dlg As UserDialog
Dialog dlg
If Channel_num = "A" Then
channel=0
ElseIf Channel_num = "B" Then
channel=1
End If
Call ps2000_set_ets(ps2000_handle, 0, 0, 0)
Call ps2000_set_channel(ps2000_handle, CInt(channel), 1, CInt(dlg.Group1),CInt(dlg.Group2)+1)
End Sub