示例#1
0
    rrd = ser.readline()
    print rrd
    if (rrd.find("READY") != -1):
        ready = 1
        # parse result
        bytes_str = rrd[17:]
        rx_cnt = int(bytes_str, 10)
        break

    if (rrd.find("BUSY") != -1):
        continue

    break
if (rx_cnt != 0):
    #get data
    (status, data_out) = get_buffer(ser, rx_cnt)

    print "get_buffer return status: %r" % status

    #save to file
    print "Save results"
    root = Tkinter.Tk()
    root.withdraw()

    file_opt = options = {}
    options['defaultextension'] = '*.*'
    options['filetypes'] = [('all files', '*.*')]
    options['title'] = 'Save results'

    file_path = tkFileDialog.asksaveasfilename(**file_opt)
    if (not file_path):
#wait for finish
done = 0
rrd = str()
while (done == 0):
    rrd = ser.readline()
    if (rrd != ''):
        print(rrd)
        done = 1
    else:
        print('.')
#verify result
if (rrd.find("OK.", 0, 3) != -1):
    #parse for received bytes count
    bytes_str = rrd[3:]
    rx_cnt = int(bytes_str, 10)

    if (rx_cnt > 0):
        #read bytes with get_buffer command
        (status, rx_data) = get_buffer(ser, rx_cnt)

        print "get_buffer return status: %r" % status
        rx_buffer = bytearray(rx_cnt)
        rx_buffer[0:rx_cnt] = rx_data

        #convert to tuples
        (status, rx_messages) = deserialize_messages(rx_buffer)
        if (status == 1):
            for messa in rx_messages:
                print messa
raw_input("Press Enter to exit ...")
    print "COM port OK"
except:
    print "Error COM port"
    sys.exit(0)

print("Requesting data...")

wro = ser.write("i2s readbuf 1, " + str(samples_cnt * 2) + "\r\n")
time.sleep(0.1)
rrd = ser.readline()
#if (rrd != 'OK\r\n'):
print(rrd)
#	sys.exit(0)

# get buffer
(status, data_out) = get_buffer(ser, samples_cnt * 8)

print "get_buffer return status: %r" % status
#print data_out.encode("hex")

data = bytearray(8 * samples_cnt)
data[0:8 * samples_cnt] = data_out

sampleR = [0] * samples_cnt
sampleL = [0] * samples_cnt

for i in range(0, samples_cnt):
    sampleR[i] = data[i * 8] | (data[i * 8 + 1] << 8) | (
        data[i * 8 + 2] << 16) | (data[i * 8 + 3] << 24)
    sampleR[i] ^= 0x80000000
    sampleL[i] = data[i * 8 + 4] | (data[i * 8 + 5] << 8) | (
from getbuffer import get_buffer

COM_PORT_ENG                = 'COM17'

#---- Application ---------------------------------------------------------
print "===================================="
print "* Get buffer tester"
print "===================================="

local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG

# Open serial port
print "Open serial port " + local_com_port
try:
    ser = serial.Serial(local_com_port, 115200, timeout=3)
    print "COM port OK" 
except:
    print "Error COM port" 
    sys.exit(0)

(status, data_out) = get_buffer(ser, 128)

print "get_buffer return status: %r" % status
print data_out.encode("hex")


# Close serial port
ser.close()
print "API test done" 

print("Starting...")
usb2io_sendcmd(ser, "i2s wreadbuf 1, " + str(data_cnt) + "\r\n")
print("Busy...")
done = 0
while (done == 0):
    rrd = ser.readline()
    if (rrd != ''):
        print(rrd)
    else:
        print('.')
    if (rrd == 'OK\r\n'):
        done = 1

# get buffer
print("Reading...")
(status, data_out) = get_buffer(ser, data_cnt * 4)

print "get_buffer return status: %r" % status
#print data_out.encode("hex")

rx_data = bytearray(4 * data_cnt)
rx_data[0:4 * data_cnt] = data_out

sampleR = [0] * (data_cnt >> 1)
sampleL = [0] * (data_cnt >> 1)

for i in range(0, data_cnt >> 1):
    sampleR[i] = rx_data[i * 8] | (rx_data[i * 8 + 1] << 8) | (
        rx_data[i * 8 + 2] << 16) | (rx_data[i * 8 + 3] << 24)
    sampleR[i] ^= 0x80000000
    #sampleR[i] = int(0x80000000 + 0x80000000 * math.sin(2 * 3.14 * i/samples_cnt))
示例#6
0
print "* UART1 config"
print "* pin connection:"
print "* GPIO10  - UART1 Rx"
print "* GPIO11  - UART1 Tx"
print "* GPIO12  - UART1 RTS"
print "* GPIO13  - UART1 CTS"
print "===================================="

local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG

# Open serial port
print "Open serial port " + local_com_port
try:
    ser = serial.Serial(local_com_port, 115200, timeout=30)
    print "COM port OK"
except:
    print "Error COM port"
    sys.exit(0)

print("Reading...")
data_count = 12
# format: uart readbuffer channel, data_count, timeout\r\n
if (usb2io_sendcmd(ser, "uart readbuffer 1, " + str(data_count) + ", 1000\r\n")
        != "OK\r\n"):
    sys.exit(0)

(status, data_out) = get_buffer(ser, data_count)
print "get_buffer return status: %r" % status
print data_out.encode("hex")

raw_input("Press Enter to exit ...")