blob: f88302bea163082cd9b0fc363e79fe0a1aa24804 (
plain)
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
|
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()
|