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) # 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') def sendSerialCmd(cmd): # start = datetime.now() ser.write(bytes(cmd+'\r','ascii')) resp = ser.read_until(terminator=b'> ') resp = resp.decode('utf-8') # print(resp) # stop = datetime.now() # runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000 # print("Command: " + cmd + " runtime %s seconds." % (runTime) ) return resp sendSerialCmd("print(2+3)") line = ser.readline() print(line) start = datetime.now() # resp = sendSerialCmd("print(node.heap())") # resp = sendSerialCmd(""); # empty command resp = sendSerialCmd("muSb= tmr.now(); setFreq(6.834e9); muSe =tmr.now(); print(\"execution time: \" .. muSe-muSb .. \" muS\")") print(resp) stop = datetime.now() runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000 print("runtime %s seconds." % (runTime) ) ser.close()