forked from mba7/SerialPort-RealTime-Data-Plotter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsender_sim.py
More file actions
31 lines (20 loc) · 693 Bytes
/
sender_sim.py
File metadata and controls
31 lines (20 loc) · 693 Bytes
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
#!/usr/bin/env python
import random, time, math, os, serial
if os.name == 'nt':
port = "com1"
else:
port = "/dev/tty.com1"
ser = serial.Serial(port, 9600)
incycle = 0
while True:
a = int(random.randint(60, 80) * (1 + math.sin(incycle)))
b = int(random.randint(60, 80) * (1 + math.sin(incycle)))
c = int(random.randint(60, 80) * (1 + math.sin(incycle)))
# send a sequence of 6 bytes followed by space (end of frame marker)
data = chr(a) + " " + chr(0) + " " + chr(b) + " " + chr(1) + " " + chr(c)+ " " + chr(0)
x = ser.write(data+'\n')
time.sleep(0.02)
incycle += 0.01
if incycle >= 2 * math.pi:
incycle = 0
ser.close()