Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pynxc/tutorial_samples/12_ReadStr.py
blob: 5e45145299cad98b5bba78074cf3ff3f32eff75f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
DEFINE FILE_LINES=10

def sub_CreateRandomFile(fname=String(), lines=Integer()):
    handle=Byte()
    s=String()
    n=bytesWritten=Integer()
    DeleteFile(fname)
    fsize=Integer()
    fsize = lines*5
    # create file with random data
    if (CreateFile(fname, fsize, handle) == NO_ERR):
        for repeat in range(FILE_LINES):
            n = Random(0xFF)
            s = NumToStr(n)
            WriteLnString(handle,s,bytesWritten)
      
        CloseFile(handle)


def main():
    handle=Byte()
    buf=String()
    fsize=Integer()
    blah = Integer(0)
    
    

    sub_CreateRandomFile("rand.txt",FILE_LINES)
    if (OpenFileRead("rand.txt", fsize, handle) == NO_ERR):
        TextOut(10,LCD_LINE2,"Filesize:")
        NumOut(65,LCD_LINE2,fsize)
        Wait(600)
        while (not eof): # read the text file till the end
            pass 
        if (ReadLnString(handle,buf) != NO_ERR):
            eof = true
        TextOut(20,LCD_LINE3,buf)
        Wait(500)
    CloseFile(handle)