TERMINAL CON PYTHON
Publicado por CARLOS (19 intervenciones) el 05/10/2018 08:23:13
Buenos días, foreros:
Necesito añadir a mi proyecto la posibilidad de poder generar o editar un fichero de texto almacenado en una raspberry a través de su puerto serie.
Utilizando PySerial y un modulo bluetooth realizo la conexión y quisiera mostrar un pequeño formulario en un terminal y me enviar los datos introducidos a un fichero txt.
¿Alquien que me pueda echar una mano...?
Gracias
Necesito añadir a mi proyecto la posibilidad de poder generar o editar un fichero de texto almacenado en una raspberry a través de su puerto serie.
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
66
67
68
#!/usr/bin/python
# coding=utf-8
import serial
import time
# Hack to make code compatible with both Python 2 and 3 (since 3 moved
# raw_input from a builtin to a different function, ugh).
try:
input = raw_input
except NameError:
pass
ser = serial.Serial(
port='/dev/ttyAMA0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
class ModeloDeFormulario:
# Datos comerciales
title = "CONFIGURACION DEL DISPOSITIVO"
# Setear los datos del dispositivo
def set_device(self):
ser.write("\r\n")
time.sleep(1)
ser.write('Ip Address: ' + input_data + '\n')
ser.write('Type(1-20): \n')
ser.write('Server(True/False): \n')
# Metodo constructor
def __init__(self):
self.set_device()
os.system('clear')
ser.write('\n')
ser.write('-------------------------------------------------- \n')
ser.write(' <<< MENU DE LA APLICACION >>> \n')
ser.write('-------------------------------------------------- \n')
ser.write('Options: \n')
ser.write(' (1)Configuracion \n')
ser.write(' (0)Salir \n')
ser.write('Please select an option(1-0): \n')
x='si'
while x=='si':
tecla = ser.read(1)
if tecla != '0':
if tecla == '1':
ser.write('\n')
# Instanciar clase
formulario = ModeloDeFormulario()
else:
ser.write('\n')
ser.write('Aborted! \n')
ser.close()
sys.exit(0)
Utilizando PySerial y un modulo bluetooth realizo la conexión y quisiera mostrar un pequeño formulario en un terminal y me enviar los datos introducidos a un fichero txt.
¿Alquien que me pueda echar una mano...?
Gracias
Valora esta pregunta


0