@@ -76,7 +76,7 @@ public void Initialise(bool initSigGens)
7676 thunderScope . Configure ( hardwareConfig ) ;
7777 // Start to keep the device hot
7878 thunderScope . Start ( ) ;
79- memoryRegion = new ThunderscopeMemoryRegion ( 1 ) ;
79+ memoryRegion = new ThunderscopeMemoryRegion ( 2 ) ;
8080
8181 // Sig gen 1 (SDG2042X)
8282 if ( Variables . Instance . SigGen1Ip != null && initSigGens )
@@ -350,8 +350,6 @@ public void GetThunderscopeStats(int channelIndex, out double average, out doubl
350350 var memory = memoryRegion ! . GetSegment ( 0 ) ;
351351 // To do: allow for multi-channel reading
352352 var config = thunderScope ! . GetConfiguration ( ) ;
353- if ( config . EnabledChannelsCount ( ) != 1 )
354- throw new NotImplementedException ( ) ;
355353 // Stop/start then flush out the buffers an arbitary amount. Exact amount of flushing required TBD.
356354 thunderScope ! . Stop ( ) ;
357355 thunderScope ! . Start ( ) ;
@@ -360,17 +358,46 @@ public void GetThunderscopeStats(int channelIndex, out double average, out doubl
360358
361359 var samples = memory . DataSpanI8 ;
362360
361+ Span < sbyte > channel ;
362+ switch ( config . EnabledChannelsCount ( ) )
363+ {
364+ case 1 :
365+ channel = samples ;
366+ break ;
367+ case 2 :
368+ {
369+ Span < sbyte > twoChannels = memoryRegion ! . GetSegment ( 1 ) . DataSpanI8 ;
370+ ShuffleI8 . TwoChannels ( samples , twoChannels ) ;
371+ var index = config . GetCaptureBufferIndexForTriggerChannel ( ( TriggerChannel ) ( channelIndex + 1 ) ) ;
372+ var length = samples . Length / 2 ;
373+ channel = twoChannels . Slice ( index * length , length ) ;
374+ break ;
375+ }
376+ case 3 :
377+ case 4 :
378+ {
379+ Span < sbyte > fourChannels = memoryRegion ! . GetSegment ( 1 ) . DataSpanI8 ;
380+ ShuffleI8 . FourChannels ( samples , fourChannels ) ;
381+ var index = config . GetCaptureBufferIndexForTriggerChannel ( ( TriggerChannel ) ( channelIndex + 1 ) ) ;
382+ var length = samples . Length / 4 ;
383+ channel = fourChannels . Slice ( index * length , length ) ;
384+ break ;
385+ }
386+ default :
387+ throw new NotImplementedException ( ) ;
388+ }
389+
363390 average = 0 ;
364391 min = int . MaxValue ;
365392 max = int . MinValue ;
366393 int sum = 0 ;
367- foreach ( var point in samples )
394+ foreach ( var point in channel )
368395 {
369396 sum += point ;
370397 if ( point < min ) min = point ;
371398 if ( point > max ) max = point ;
372399 }
373- average = ( double ) sum / samples . Length ;
400+ average = ( double ) sum / channel . Length ;
374401 }
375402
376403 public void SetSdgChannel ( int channelIndex )
0 commit comments