-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog_Data_From_Lactometer.py
55 lines (45 loc) · 1.6 KB
/
Log_Data_From_Lactometer.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
""" This is logging Data from a Lactometer """
import sys
import glob
import serial
def serial_ports():
buffer1 = []
result = []
myfile = open("Lactometer1.csv","a+")
print("Pointer for File:\t",myfile.tell())
if sys.platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
# this excludes your current terminal "/dev/tty"
ports = glob.glob('/dev/tty[A-Za-z]*')
elif sys.platform.startswith('darwin'):
ports = glob.glob('/dev/tty.*')
else:
raise EnvironmentError('Unsupported platform')
for port in ports:
try:
s = serial.Serial(port=port,\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS)
result.append(port)
print("-----------------------------")
for x in range(258):
ans=ascii(s.read())
print("Data:\t",ans[2:3])
myfile.write(ans[2:3])
myfile.write("\n")
print("Pointer from FOR:\t",myfile.tell())
print("-----------------------------")
s.close()
myfile.close()
except (OSError, serial.SerialException):
pass #Is this even worth to write a pass here?
return result
print(serial_ports()) #This will run the Actual Data
#for m in range(0,9):
# ans=ascii(s.read())
# buffer1.append(ans[2:3])
#myfile.write("\nThis is writing")
#myfile.write(str(buffer1))