Anonymous avatar Anonymous committed 4060c08 Draft

start a client to test the maple's transfer speed

Comments (0)

Files changed (1)

upload_play/testclient.py

+# FTDI basic client
+# ser.getSupportedBaudrates()
+# Out[116]: 
+# [('50', 50),
+#  ('75', 75),
+#  ('110', 110),
+#  ('134', 134),
+#  ('150', 150),
+#  ('200', 200),
+#  ('300', 300),
+#  ('600', 600),
+#  ('1200', 1200),
+#  ('1800', 1800),
+#  ('2400', 2400),
+#  ('4800', 4800),
+#  ('9600', 9600),
+#  ('19200', 19200),
+#  ('38400', 38400),
+#  ('57600', 57600),
+#  ('115200', 115200),
+#  ('230400', 230400),
+#  ('460800', 460800),
+#  ('500000', 500000),
+#  ('576000', 576000),
+#  ('921600', 921600),
+#  ('1000000', 1000000),
+#  ('1152000', 1152000),
+#  ('1500000', 1500000),
+#  ('2000000', 2000000),
+#  ('2500000', 2500000),
+#  ('3000000', 3000000),
+#  ('3500000', 3500000),
+#  ('4000000', 4000000)]
+
+
+import serial
+import numpy as np
+
+# ls /dev/ttyUSB*  # to see what ports are available
+# ser = serial.Serial(r'/dev/ttyUSB2', 9600)   # safe, works
+# ser = serial.Serial(r'/dev/ttyUSB2', 921600) # works
+
+BAUDRATE =  2000000 # works
+ser = serial.Serial(r'/dev/ttyUSB2', BAUDRATE, timeout=10.0) 
+print "Number of char in receive buffer: ", ser.inWaiting()
+# can also flushInput() and flushOutput()
+
+def test1():
+    raw_input("press key to start")
+    ser.write('w')
+    resp = ser.readline()
+    print resp
+    raw_input("start download of 256 bytes")
+    ser.write('U')
+    return read_chars(256)
+
+def read_chars(n):
+    buf = []    
+    for ii in xrange(n):
+        c = ser.read()
+        buf.append(c)
+    return buf
+
+
+
+def test_download_256():
+    ser.flush()
+    ser.write('U')
+    resp = read_chars(256)
+    # now check for correct response
+    return resp
+
+def test_download_1024_uint16():
+    ser.write('d')
+    resp = ser.read(size=2048) # two bytes per uint16
+    return resp # returns bytes
+#def convert_char2uint8(lstarr):
+#    np.
+
+def assemble_uints(bytearray):
+    # probably there is a better way to do this ? see structure or array package
+    iarr = map(ord,bytearray)
+    return [ iarr[2*ii] + (iarr[2*ii+1] << 8) for ii in xrange(len(iarr)/2) ]
+        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.