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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
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=.2)
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser), line_buffering=True)
# 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 = sio.readline()
while line:
line = line.rstrip()
print(line)
if line == '>':
break
line = sio.readline()
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()
|