-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyusb_fx3_sourcesink_python3.py
84 lines (64 loc) · 1.84 KB
/
cyusb_fx3_sourcesink_python3.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
### quick mod from https://github.com/danielkucera/cyusb3014-breakout/blob/master/software/loopback-test.py
import usb.core
import usb.util
import time
import _thread
# find our device
dev = usb.core.find(idVendor=0x04b4, idProduct=0x00f1 )
# was it found?
if dev is None:
raise ValueError('Device not found')
# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()
# get an endpoint instance
cfg = dev.get_active_configuration()
#intf = cfg[(0,1)]
#dev.set_interface_altsetting(interface = 0, alternate_setting = 0)
intf = cfg[(0,0)]
#print intf
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
e.bEndpointAddress == 0x01)
ep2 = usb.util.find_descriptor(
intf,
# match the first IN endpoint
custom_match = \
lambda e: \
e.bEndpointAddress == 0x81)
assert ep is not None
assert ep2 is not None
print ('ep:',ep)
print ('ep2:',ep2)
chunkr = 2**16
chunkw = 2**16
print ("Starting CYUSB3014 python bulk sourcesink test")
def read_loop():
start = time.time()
trans = 0
while True:
data = dev.read(0x81, chunkr, 1000)
trans = trans + len(data)
if time.time() > start + 1:
bps = trans/(time.time() - start)
print ("Read: transfered %d kB/s" % (bps/(1024)) )
trans = 0
start = time.time()
def write_loop():
start1 = time.time()
trans1 = 0
dat = "A"*chunkw
while True:
ep.write(dat)
trans1 = trans1 + len(dat)
if time.time() > start1 + 1:
bps1 = trans1/(time.time() - start1)
print ("Write: transfered %d kB/s" % (bps1/(1024)) )
trans1 = 0
start1 = time.time()
_thread.start_new_thread( write_loop, () )
read_loop()