import serial import io import time # For sleep, clock, time and perf_counter from datetime import datetime, timedelta # ser = serial.Serial('COM4', 115200, timeout=1) # ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1) ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) # sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser), line_buffering=True, newline='\r\n') # ser.write(b'dofile("bits_converging.lua")\r') # ser.write(b'dofile("microwire.lua")\r') # ser.write(b'dofile("lmx2487lib.lua")\r') # ser.write(b'dofile("Frequency_Settings.lua")\r') # ser.write(b'settings = initSettings()\r') # ser.write(b'settings = set_lmx2487_to_Frequency (startfreq, settings)\r') # ser.write(b'\rprint(2+2)\r') # ser.write(b'print(node.heap())\r') # s = ser.read(100) # print("1st reply") # print(s) # line = ser.readline() # print(line) # line = ser.readline() # print(line) # line = ser.readline() # print(line) # line = ser.readline() # print(line) def sendSerialCmd(cmd): start = datetime.now() ser.write(bytes(cmd+'\r','ascii')) # sio.write(cmd+'\r') line = ser.read_until(terminator=b'> ') print(line) stop = datetime.now() runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000 print("Command: " + cmd + " runtime %s seconds." % (runTime) ) sendSerialCmd("print(2+3)") line = ser.readline() print(line) start = datetime.now() for i in range(1,10): sendSerialCmd("print(node.heap())") stop = datetime.now() runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000 print("runtime %s seconds." % (runTime) ) ser.close()