@@ -525,98 +525,10 @@ def capture(self, address, location, sample_length, total_samples, tg, *args):
525
525
:return: Arrays X(timestamps),Y1,Y2 ...
526
526
527
527
"""
528
- if tg < 20 :
529
- tg = 20
530
- total_bytes = total_samples * sample_length
531
- print ('total bytes calculated : ' , total_bytes )
532
- if (total_bytes > CP .MAX_SAMPLES * 2 ):
533
- print ('Sample limit exceeded. 10,000 int / 20000 bytes total' )
534
- total_samples = CP .MAX_SAMPLES * 2 / sample_length # 2* because sample array is in Integers, and we're using it to store bytes
535
- total_bytes = CP .MAX_SAMPLES * 2
536
-
537
- if ('int' in args ):
538
- total_chans = sample_length / 2
539
- channel_length = total_bytes / sample_length / 2
540
- else :
541
- total_chans = sample_length
542
- channel_length = total_bytes / sample_length
543
-
544
- print ('total channels calculated : ' , total_chans )
545
- print ('length of each channel : ' , channel_length )
546
- try :
547
- self .H .__sendByte__ (CP .I2C_HEADER )
548
- self .H .__sendByte__ (CP .I2C_START_SCOPE )
549
- self .H .__sendByte__ (address )
550
- self .H .__sendByte__ (location )
551
- self .H .__sendByte__ (sample_length )
552
- self .H .__sendInt__ (total_samples ) # total number of samples to record
553
- self .H .__sendInt__ (tg ) # Timegap between samples. 1MHz timer clock
554
- self .H .__get_ack__ ()
555
- print ('done' , total_chans , channel_length )
556
-
557
- print ('sleeping for : ' , 1e-6 * total_samples * tg + .01 )
558
-
559
- time .sleep (1e-6 * total_samples * tg + 0.5 )
560
- data = b''
561
- total_int_samples = total_bytes / 2
562
-
563
- print ('fetchin samples : ' , total_int_samples , ' split' , CP .DATA_SPLITTING )
564
-
565
- data = b''
566
- for i in range (int (total_int_samples / CP .DATA_SPLITTING )):
567
- self .H .__sendByte__ (CP .ADC )
568
- self .H .__sendByte__ (CP .GET_CAPTURE_CHANNEL )
569
- self .H .__sendByte__ (0 ) # starts with A0 on PIC
570
- self .H .__sendInt__ (CP .DATA_SPLITTING )
571
- self .H .__sendInt__ (i * CP .DATA_SPLITTING )
572
- rem = CP .DATA_SPLITTING * 2 + 1
573
- for a in range (200 ):
574
- partial = self .H .fd .read (
575
- rem ) # reading int by int sometimes causes a communication error. this works better.
576
- rem -= len (partial )
577
- data += partial
578
- # print ('partial: ',len(partial), end=",")
579
- if rem <= 0 :
580
- break
581
- data = data [:- 1 ]
582
- # print ('Pass : len=',len(data), ' i = ',i)
583
-
584
- if total_int_samples % CP .DATA_SPLITTING :
585
- self .H .__sendByte__ (CP .ADC )
586
- self .H .__sendByte__ (CP .GET_CAPTURE_CHANNEL )
587
- self .H .__sendByte__ (0 ) # starts with A0 on PIC
588
- self .H .__sendInt__ (total_int_samples % CP .DATA_SPLITTING )
589
- self .H .__sendInt__ (total_int_samples - total_int_samples % CP .DATA_SPLITTING )
590
- rem = 2 * (total_int_samples % CP .DATA_SPLITTING ) + 1
591
- for a in range (200 ):
592
- partial = self .H .fd .read (
593
- rem ) # reading int by int sometimes causes a communication error. this works better.
594
- rem -= len (partial )
595
- data += partial
596
- # print ('partial: ',len(partial), end="")
597
- if rem <= 0 :
598
- break
599
- data = data [:- 1 ]
600
- # print ('Final Pass : len=',len(data))
601
- except Exception as ex :
602
- self .raiseException (ex , "Communication Error , Function : " + inspect .currentframe ().f_code .co_name )
603
-
604
- try :
605
- data = [ord (a ) for a in data ]
606
- if ('int' in args ):
607
- for a in range (total_chans * channel_length ): self .buff [a ] = np .int16 (
608
- (data [a * 2 ] << 8 ) | data [a * 2 + 1 ])
609
- else :
610
- for a in range (total_chans * channel_length ): self .buff [a ] = data [a ]
611
-
612
- # print (self.buff, 'geer')
613
-
614
- yield np .linspace (0 , tg * (channel_length - 1 ), channel_length )
615
- for a in range (int (total_chans )):
616
- yield self .buff [a :channel_length * total_chans ][::total_chans ]
617
- except Exception as ex :
618
- msg = "Incorrect number of bytes received"
619
- raise RuntimeError (msg )
528
+ t = self .__captureStart__ (address ,location ,sample_length ,total_samples ,tg )
529
+ time .sleep (t )
530
+ data = self .__retrievebuffer__ ()
531
+ return self .__dataProcessor__ (data ,* args )
620
532
621
533
622
534
class SPI ():
0 commit comments