Using block mode with 3425

Post general discussions on using our drivers to write your own software here
Post Reply
gbgb
Newbie
Posts: 0
Joined: Thu Jan 19, 2012 11:29 am

Using block mode with 3425

Post by gbgb »

I am in the process of writing an application (RealBasic) as follows:
Scope is 3425 working with two channels - per specs this allocates 256K per channel internal buffer.
Required sampling rate - 10uS (100kS/sec)
The collection is a random triggered event, after which I would like to collect about 5 seconds of data - about twice the internal buffer capacity.
Can I perform this task using the ps3000_run_block function? Specifically:
1. Can the no_of_samples be any number I select, larger than the internal buffer? (Obviously the application will allocate enough space for the ps3000_get_values function)
2. Timebase - I want to make sure I understand this value correctly - per specs the max sample rate @ two channels is 10MS/sec - so setting the value to 6 will give a sample rate of 156kS/sec?

I know RealStudio/RealBasic is not a very common development tool - but if you have pointers to code written in RealBasic for your scopes I will be happy to know about them - I could not find such.

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Using block mode with 3425

Post by Martyn »

Run block will collect a block of data to the internal memory of the scope and is therefore limited to the size of this. Once collected the block of data is transferred to the PC at which point the application can restart another block capture. There will be gaps in the data using this approach.

However looking at your settings you should be using Fast Streaming Mode which can stream data to the PC at speeds of a million samples per second or more, dependant on the PC, and does not use the internal memory of the scope.

Unfortunately we do not have any RealStudio/RealBasic sample code.
Martyn
Technical Support Manager

gbgb
Newbie
Posts: 0
Joined: Thu Jan 19, 2012 11:29 am

Re: Using block mode with 3425

Post by gbgb »

I will try working both with block and streaming.

In fast streaming the function prototype in the documentation says that the interval passed is in PS300_TIME_UNITS.
The C++ example shows that this is an enumeration, however I am not using C or C++.
What is the data type that the dll expects (a byte? a short?).

Is there a VB example for fast streaming? It is much closer in syntax to what I am using.

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Using block mode with 3425

Post by Martyn »

Here is an Excel example that should help

GetData

Code: Select all

'
' Macro1 Macro
' Macro recorded 07/08/03 by MAS
'
'
Declare Function ps3000_open_unit Lib "ps3000.dll" () As Integer
Declare Function ps3000_set_unit Lib "ps3000.dll" (ByVal handle As Integer) As Integer
Declare Function ps3000_flash_led Lib "ps3000.dll" (ByVal handle As Integer) As Integer
Declare Sub ps3000_close_unit Lib "ps3000.dll" (ByVal handle As Integer)

Declare Function ps3000_get_unit_info Lib "ps3000.dll" (ByVal handle As Integer, ByVal str As String, ByVal lth As Integer, ByVal line_no As Integer) As Integer

Declare Function ps3000_set_siggen Lib "ps3000.dll" (ByVal handle As Integer, ByVal wave_type As Integer, ByVal start As Long, ByVal stop_freq As Long, ByVal increment As Integer, ByVal dwell As Integer, ByVal repeat As Integer, ByVal dual As Integer) As Long

Declare Function ps3000_set_channel Lib "ps3000.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 ps3000_set_trigger Lib "ps3000.dll" (ByVal handle As Integer, ByVal source As Integer, ByVal threshold As Integer, ByVal direction As Integer, ByVal delay As Integer, ByVal auto_trigger_ms As Integer) As Integer
Declare Function ps3000_get_timebase Lib "ps3000.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 ps3000_run_block Lib "ps3000.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 ps3000_run_streaming Lib "ps3000.dll" (ByVal handle As Integer, ByVal time_interval As Long, ByVal max_samples As Long, ByVal windowed As Integer) As Integer
Declare Function ps3000_ready Lib "ps3000.dll" (ByVal handle As Integer) As Integer
Declare Function ps3000_get_values Lib "ps3000.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 ps3000_get_times_and_values Lib "ps3000.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_samples As Long) As Long
Declare Function ps3000_stop Lib "ps3000.dll" (ByVal handle As Integer) As Integer

Declare Function ps3000_set_ets Lib "ps3000.dll" (ByVal handle As Integer, ByVal mode As Integer, ByVal ets_cycles As Integer, ByVal ets_interleave As Integer) As Long


Dim timebase As Integer
Dim no_of_samples As Long
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 ps3000_handle As Integer
Dim mv As Integer

Sub GetData()

ReDim values_a(100) As Integer
ReDim values_b(100) As Integer
ReDim values_c(100) As Integer
ReDim values_d(100) As Integer
ReDim times(100) As Long
Dim overflow As Integer
Dim max_samples As Long

  ps3000_handle = ps3000_open_unit()
  
  If ps3000_handle = 0 Then
     MsgBox "Unit not opened", vbOKOnly, "Error Message"
     Exit Sub
  End If
  
  
  For i = 0 To 5 Step 1
    j = ps3000_get_unit_info(ps3000_handle, S, 255, i)
    Cells(18 + i, "E").Value = S
  Next i
  
  Call ps3000_set_ets(ps3000_handle, 0, 0, 0)
  Call ps3000_set_channel(ps3000_handle, 0, 1, 0, 10)
  Call ps3000_set_channel(ps3000_handle, 1, 1, 0, 10)
  
  Cells(17, "E").Value = "PS3000 opened"
  
    
  'Trigger disabled
  
  Call ps3000_set_trigger(ps3000_handle, 5, 0, 0, 0, 0)

  'find the maximum number of samples, the time interval (in time_units),
  'the most suitable time units, and the maximum oversample at the current timebase
  timebase = 13
  no_of_samples = 100
  ok = ps3000_get_timebase(ps3000_handle, _
                           timebase, _
                           no_of_samples, _
                           time_interval, _
                           time_units, _
                           oversample, _
                           max_samples)
  
  ' Start it collecting,
  ' then wait for completion
  Call ps3000_run_block(ps3000_handle, no_of_samples, timebase, oversample, time_indisposed_ms)
    
  While ps3000_ready(ps3000_handle) = 0
  Wend
  
  ps3000_stop (ps3000_handle)

  'Should be done now...
  'get the times (in nanoseconds)
  'and the values (in ADC counts)
   Call ps3000_get_times_and_values(ps3000_handle, times(0), values_a(0), values_b(0), values_c(0), values_d(0), overflow, time_units, no_of_samples)

    For i = 0 To 99
      Cells(i + 4, "A").Value = times(i)
      Cells(i + 4, "B").Value = values_b(i)
      Cells(i + 4, "C").Value = (values_b(i) / 32767) * 20000
    Next i
    
    Call ps3000_close_unit(ps3000_handle)
    
End Sub

Sub StreamingData()
ReDim values_a(100) As Integer
ReDim values_b(100) As Integer
ReDim values_c(100) As Integer
ReDim values_d(100) As Integer
ReDim times(100) As Long
Dim no As Long
Dim overflow As Integer
Dim counter As Integer

ps3000_handle = ps3000_open_unit(1)
  
If ps3000_handle = 0 Then
   MsgBox "Unit not opened", vbOKOnly, "Error Message"
   Exit Sub
End If
  
Call ps3000_set_ets(ps3000_handle, 0, 0, 0)
Call ps3000_set_channel(ps3000_handle, 0, 0, 0, 10)
Call ps3000_set_channel(ps3000_handle, 1, 1, 0, 10)
  
Cells(17, "E").Value = "PS3000 opened"
  
'Trigger disabled
Call ps3000_set_trigger(ps3000_handle, 5, 0, 0, 0, 0)

'find the maximum number of samples, the time interval (in time_units),
'the most suitable time units, and the maximum oversample at the current timebase
'timebase = 13
no_of_samples = 100

ok = ps3000_run_streaming(ps3000_handle, 10, no_of_samples, 0)

counter = 0

'the values (in ADC counts)
no = ps3000_get_values(ps3000_handle, values_a(0), values_b(0), values_c(0), values_d(0), overflow, no_of_samples)

For i = 0 To (no - 1)
   Cells(counter + i + 4, "B").Value = values_b(i)
   Cells(counter + i + 4, "C").Value = (values_b(i) / 32767) * 20000
Next i
    
If counter > 1000 Then
  counter = 0
Else
  counter = counter + i
End If

Call ps3000_close_unit(ps3000_handle)
  
End Sub

StreamingData

Code: Select all

'
' Macro1 Macro
' Macro recorded 07/08/03 by MAS
'
'
Declare Function ps3000_open_unit Lib "ps3000.dll" () As Integer
Declare Function ps3000_set_unit Lib "ps3000.dll" (ByVal handle As Integer) As Integer
Declare Function ps3000_flash_led Lib "ps3000.dll" (ByVal handle As Integer) As Integer
Declare Sub ps3000_close_unit Lib "ps3000.dll" (ByVal handle As Integer)

Declare Function ps3000_get_unit_info Lib "ps3000.dll" (ByVal handle As Integer, ByVal str As String, ByVal lth As Integer, ByVal line_no As Integer) As Integer

Declare Function ps3000_set_siggen Lib "ps3000.dll" (ByVal handle As Integer, ByVal wave_type As Integer, ByVal start As Long, ByVal stop_freq As Long, ByVal increment As Integer, ByVal dwell As Integer, ByVal repeat As Integer, ByVal dual As Integer) As Long

Declare Function ps3000_set_channel Lib "ps3000.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 ps3000_set_trigger Lib "ps3000.dll" (ByVal handle As Integer, ByVal source As Integer, ByVal threshold As Integer, ByVal direction As Integer, ByVal delay As Integer, ByVal auto_trigger_ms As Integer) As Integer
Declare Function ps3000_get_timebase Lib "ps3000.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 ps3000_run_block Lib "ps3000.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 ps3000_run_streaming Lib "ps3000.dll" (ByVal handle As Integer, ByVal time_interval As Long, ByVal max_samples As Long, ByVal windowed As Integer) As Integer
Declare Function ps3000_ready Lib "ps3000.dll" (ByVal handle As Integer) As Integer
Declare Function ps3000_get_values Lib "ps3000.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 ps3000_get_times_and_values Lib "ps3000.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_samples As Long) As Long
Declare Function ps3000_stop Lib "ps3000.dll" (ByVal handle As Integer) As Integer

Declare Function ps3000_set_ets Lib "ps3000.dll" (ByVal handle As Integer, ByVal mode As Integer, ByVal ets_cycles As Integer, ByVal ets_interleave As Integer) As Long


Dim timebase As Integer
Dim no_of_samples As Long
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 ps3000_handle As Integer
Dim mv As Integer

Sub GetData()

ReDim values_a(100) As Integer
ReDim values_b(100) As Integer
ReDim values_c(100) As Integer
ReDim values_d(100) As Integer
ReDim times(100) As Long
Dim overflow As Integer
Dim max_samples As Long

  ps3000_handle = ps3000_open_unit()
  
  If ps3000_handle = 0 Then
     MsgBox "Unit not opened", vbOKOnly, "Error Message"
     Exit Sub
  End If
  
  
  For i = 0 To 5 Step 1
    j = ps3000_get_unit_info(ps3000_handle, S, 255, i)
    Cells(18 + i, "E").Value = S
  Next i
  
  Call ps3000_set_ets(ps3000_handle, 0, 0, 0)
  Call ps3000_set_channel(ps3000_handle, 0, 1, 0, 10)
  Call ps3000_set_channel(ps3000_handle, 1, 1, 0, 10)
  
  Cells(17, "E").Value = "PS3000 opened"
  
    
  'Trigger disabled
  
  Call ps3000_set_trigger(ps3000_handle, 5, 0, 0, 0, 0)

  'find the maximum number of samples, the time interval (in time_units),
  'the most suitable time units, and the maximum oversample at the current timebase
  timebase = 13
  no_of_samples = 100
  ok = ps3000_get_timebase(ps3000_handle, _
                           timebase, _
                           no_of_samples, _
                           time_interval, _
                           time_units, _
                           oversample, _
                           max_samples)
  
  ' Start it collecting,
  ' then wait for completion
  Call ps3000_run_block(ps3000_handle, no_of_samples, timebase, oversample, time_indisposed_ms)
    
  While ps3000_ready(ps3000_handle) = 0
  Wend
  
  ps3000_stop (ps3000_handle)

  'Should be done now...
  'get the times (in nanoseconds)
  'and the values (in ADC counts)
   Call ps3000_get_times_and_values(ps3000_handle, times(0), values_a(0), values_b(0), values_c(0), values_d(0), overflow, time_units, no_of_samples)

    For i = 0 To 99
      Cells(i + 4, "A").Value = times(i)
      Cells(i + 4, "B").Value = values_b(i)
      Cells(i + 4, "C").Value = (values_b(i) / 32767) * 20000
    Next i
    
    Call ps3000_close_unit(ps3000_handle)
    
End Sub

Sub StreamingData()
ReDim values_a(100) As Integer
ReDim values_b(100) As Integer
ReDim values_c(100) As Integer
ReDim values_d(100) As Integer
ReDim times(100) As Long
Dim no As Long
Dim overflow As Integer
Dim counter As Integer

ps3000_handle = ps3000_open_unit(1)
  
If ps3000_handle = 0 Then
   MsgBox "Unit not opened", vbOKOnly, "Error Message"
   Exit Sub
End If
  
Call ps3000_set_ets(ps3000_handle, 0, 0, 0)
Call ps3000_set_channel(ps3000_handle, 0, 0, 0, 10)
Call ps3000_set_channel(ps3000_handle, 1, 1, 0, 10)
  
Cells(17, "E").Value = "PS3000 opened"
  
'Trigger disabled
Call ps3000_set_trigger(ps3000_handle, 5, 0, 0, 0, 0)

'find the maximum number of samples, the time interval (in time_units),
'the most suitable time units, and the maximum oversample at the current timebase
'timebase = 13
no_of_samples = 100

ok = ps3000_run_streaming(ps3000_handle, 10, no_of_samples, 0)

counter = 0

'the values (in ADC counts)
no = ps3000_get_values(ps3000_handle, values_a(0), values_b(0), values_c(0), values_d(0), overflow, no_of_samples)

For i = 0 To (no - 1)
   Cells(counter + i + 4, "B").Value = values_b(i)
   Cells(counter + i + 4, "C").Value = (values_b(i) / 32767) * 20000
Next i
    
If counter > 1000 Then
  counter = 0
Else
  counter = counter + i
End If

Call ps3000_close_unit(ps3000_handle)
  
End Sub
Martyn
Technical Support Manager

gbgb
Newbie
Posts: 0
Joined: Thu Jan 19, 2012 11:29 am

Re: Using block mode with 3425

Post by gbgb »

Thanks,

Is there a VB/VBA example of fast streaming?

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Using block mode with 3425

Post by Martyn »

No, you would need to adapt the streaming code from above using the the details in the manual.
Martyn
Technical Support Manager

Post Reply