aboutsummaryrefslogtreecommitdiff
path: root/Tools/usb_serialload.py
blob: 5c864532f729ee45f0249b28d4cd2d0c53854574 (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import serial, time


port = serial.Serial('/dev/ttyACM0', baudrate=57600, timeout=2)

data = '01234567890123456789012345678901234567890123456789'
#data = 'hellohello'
outLine = 'echo %s\n' % data

port.write('\n\n\n')
port.write('free\n')
line = port.readline(80)
while line != '':
    print(line)
    line = port.readline(80)
    

i = 0
bytesOut = 0
bytesIn = 0

startTime = time.time()
lastPrint = startTime
while True:
    bytesOut += port.write(outLine)
    line = port.readline(80)
    bytesIn += len(line)
    # check command line echo
    if (data not in line):
        print('command error %d: %s' % (i,line))
        #break
    # read echo output
    line = port.readline(80)
    if (data not in line):
        print('echo output error %d: %s' % (i,line))
        #break
    bytesIn += len(line)
    #print('%d: %s' % (i,line))
    #print('%d: bytesOut: %d, bytesIn: %d' % (i, bytesOut, bytesIn))
    
    elapsedT = time.time() - lastPrint
    if (time.time() - lastPrint >= 5):
        outRate = bytesOut / elapsedT
        inRate = bytesIn / elapsedT
        usbRate = (bytesOut + bytesIn) / elapsedT
        lastPrint = time.time()
        print('elapsed time: %f' % (time.time() - startTime))
        print('data rates (bytes/sec): out: %f, in: %f, total: %f' % (outRate, inRate, usbRate))
        
        bytesOut = 0
        bytesIn = 0
        
    i += 1    
    #if (i > 2): break