-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial01.py
More file actions
29 lines (24 loc) · 795 Bytes
/
serial01.py
File metadata and controls
29 lines (24 loc) · 795 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
import serial
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# create a file handler
handler = logging.FileHandler('trace.log')
handler.setLevel(logging.INFO)
# create a logging format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(handler)
logger.info('Imposto la seriale...')
ser = serial.Serial('/dev/serial0', 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, xonxoff=True)
print(ser.name)
logger.info('Scrivo sulla seriale...')
ser.write(b'Hello World!')
logger.info('Svuoto il buffer...')
ser.flush()
#letto = ser.read(8)
#print(letto)
logger.info('Chiudo la seriale...')
ser.close()
logger.info('Termino...')