libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
rb_file.bas
Go to the documentation of this file.
1 
16 
17 
18 ' include libpruio
19 #INCLUDE ONCE "BBB/pruio.bi"
20 
21 CONST tSamp = 123401 _
22  , tmr = 20000 _
23  , NoStep = 3 _
24  , NoFile = 2 _
25  , NamFil = "output."
26 
27 VAR io = NEW PruIo()
28 
29 WITH *io
30  DO
31  IF .Errr THEN ?"NEW failed: " & *.Errr : EXIT DO
32 
33  IF .Adc->setStep( 9, 0, 0, 0, 0) THEN _
34  ?"step 9 configuration failed: " & *.Errr : EXIT DO
35  IF .Adc->setStep(10, 1, 0, 0, 0) THEN _
36  ?"step 10 configuration failed: " & *.Errr : EXIT DO
37  IF .Adc->setStep(11, 2, 0, 0, 0) THEN _
38  ?"step 11 configuration failed: " & *.Errr : EXIT DO
39 
40  VAR mask = &b111 SHL 9 _
41  , tInd = tSamp * NoStep _
42  , half = ((.ESize SHR 2) \ NoStep) * NoStep
43 
44  IF half > tInd THEN half = tInd ' adapt size for small files
45  VAR samp = (half SHL 1) \ NoStep
46 
47  IF .config(samp, mask, tmr, 0) THEN _ ' configure driver
48  ?"config failed: " & *.Errr : EXIT DO
49 
50  IF .rb_start() THEN _ ' start ring buffer mode
51  ?"rb_start failed: " & *.Errr : EXIT DO
52 
53  VAR p0 = .Adc->Value _
54  , p1 = p0 + half
55  FOR n AS INTEGER = 0 TO NoFile - 1
56  VAR fnam = NamFil & n _
57  , fnr = FREEFILE
58  IF OPEN(fnam FOR OUTPUT AS fnr) THEN
59  ?"Cannot open " & fnam
60  ELSE
61  ?"Creating file " & fnam
62  VAR i = 0
63  WHILE i < tInd
64  i += half
65  IF i > tInd THEN ' fetch the rest (maybe no complete chunk)
66  VAR rest = tInd + half - i _
67  , iEnd = IIF(p1 >= p0, rest, rest + half)
68  WHILE .DRam[0] < iEnd : SLEEP 1 : WEND
69  ?" writing samples " & (tInd - rest) & "-" & (tInd - 1)
70  PUT #fnr, , *p0, rest
71  SWAP p0, p1 : EXIT WHILE
72  END IF
73 
74  IF p1 > p0 THEN WHILE .DRam[0] < half : SLEEP 1 : WEND _
75  ELSE WHILE .DRam[0] > half : SLEEP 1 : WEND
76  ?" writing samples " & (i - half) & "-" & (i - 1)
77  PUT #fnr, , *p0, half
78  SWAP p0, p1
79  WEND
80  ?"Finished file " & fnam
81  CLOSE #fnr
82  END IF
83  NEXT
84  LOOP UNTIL 1
85  IF .Errr THEN SLEEP
86 END WITH
87 
88 DELETE(io)
89 
90 '' help Doxygen to document the main code
91 '&/** The main function. */
92 '&int main() {PruIo::PruIo(); AdcUddt::setStep(); PruIo::config(); PruIo::~PruIo();}
93