-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConexion.py
40 lines (33 loc) · 1.2 KB
/
Conexion.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
#!/usr/bin/python
import time
from time import sleep
import serial
import random
class Conexion:
puerto_serie = None
def __init__(self):
return None
#self.conectar()
def conectar(self):
self.puerto_serie = serial.Serial('/dev/ttyACM0',
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=1,
xonxoff=0,
rtscts=0
)
def close(self):
self.puerto_serie.close()
def lectura(self):
self.puerto_serie.setDTR(True) # indica que el canal esta listo para comunicarse
sleep(5)
lectura = self.puerto_serie.readline().strip()
lectura.decode("utf-8")
print("esta es: ")
print(lectura)
print(time.strftime("%c"))
lectura = float(lectura.replace(',', '.'))
return lectura
return round(random.uniform(27, 28), 2)