-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpts2_to_file.py
executable file
·38 lines (30 loc) · 1021 Bytes
/
pts2_to_file.py
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
#!/usr/bin/python
from __future__ import print_function
import serial, time, io, datetime, pika
#from serial import Serial
addr = "/dev/pts/2" ## serial port to read data from
baud = 9600 ## baud rate for instrument
filename = "/var/tmp/usb0.out"
ser = serial.Serial(
port = addr,\
baudrate = baud,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
rtscts=True,dsrdtr=True, ## This line is needed for serial port emulation \
timeout=0)
datafile=open(filename, 'a', 0)
## this will store each line of data
seq = []
count = 1 ## row index
while True:
for i in ser.read():
seq.append(i) ## convert from ACSII?
joined_seq = ''.join(str(v) for v in seq) ## Make a string from array
if i == '\n':
datafile.write(str(count) + "," + str(datetime.datetime.now()) + "," + joined_seq) ## append a timestamp to each row of data
seq = []
count += 1
break
datafile.close()
ser.close()