-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdemo_script_08_log_to_file.py
82 lines (58 loc) · 2.77 KB
/
demo_script_08_log_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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pylint: disable=wildcard-import
#pylint: disable=unused-wildcard-import
#pylint: disable=unused-import
#pylint: disable=duplicate-code
"""
test file for testing writing the log messages to a file
"""
import logging
try:
from src.TMC_2209.TMC_2209_StepperDriver import *
from src.TMC_2209._TMC_2209_GPIO_board import Board
except ModuleNotFoundError:
from TMC_2209.TMC_2209_StepperDriver import *
from TMC_2209._TMC_2209_GPIO_board import Board
print("---")
print("SCRIPT START")
print("---")
#-----------------------------------------------------------------------
# initiate the log level, handler, and formatter
#-----------------------------------------------------------------------
loglevel = Loglevel.ALL
logging_handler = logging.FileHandler("tmc2209_log_file.log")
logformatter = logging.Formatter('%(name)s %(asctime)s - %(levelname)s - %(message)s',
'%Y%m%d %H:%M:%S')
#-----------------------------------------------------------------------
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
if BOARD == Board.RASPBERRY_PI:
tmc = TMC_2209(21, 16, 20, skip_uart_init=True,
loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter)
elif BOARD == Board.RASPBERRY_PI5:
tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0", skip_uart_init=True,
loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter)
elif BOARD == Board.NVIDIA_JETSON:
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True,
loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter)
else:
# just in case
tmc = TMC_2209(21, 16, 20, skip_uart_init=True,
loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter)
#-----------------------------------------------------------------------
# Log custom messages
#-----------------------------------------------------------------------
tmc.tmc_logger.log("========================", Loglevel.ALL)
tmc.tmc_logger.log("Hello World!", Loglevel.DEBUG)
tmc.tmc_logger.log("Wow, you can even log your own messages!", Loglevel.ERROR)
tmc.tmc_logger.log("If you like this library, please give us a star on GitHub!", Loglevel.INFO)
tmc.tmc_logger.log("The cake is a lie", Loglevel.WARNING)
tmc.tmc_logger.log("I like to move it, move it", Loglevel.MOVEMENT)
tmc.tmc_logger.log("========================", Loglevel.ALL)
#-----------------------------------------------------------------------
# deinitiate the TMC_2209 class
#-----------------------------------------------------------------------
del tmc
print("---")
print("SCRIPT FINISHED")
print("---")