Last active
December 21, 2015 17:15
-
-
Save NickSablukov/0e39b6fbfec79dd01efe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import serial | |
import os, sys | |
import signal | |
import datetime | |
TRANSFER_RATE = '9600' | |
MOUNT_BASE_DIR = '/dev/ttyACM' | |
PATH_TO_LOGS = 'monitoring_logs' | |
def _config(): | |
# Создаем папку с логами, если таковая отсутствует | |
try: | |
os.mkdir(PATH_TO_LOGS) | |
print 'Не было найдено папки с логами, создаю ... ' | |
except OSError: | |
print 'Папка с логами найдена ...' | |
# Определяем примантированную директорию | |
path = MOUNT_BASE_DIR | |
path += '1' if os.path.exists(path + '1') else '0' | |
# Создаем объект порта, который мониторим | |
port = serial.Serial(path, TRANSFER_RATE) | |
return port | |
def main(port): | |
back_data = None | |
file_name = 'Запуск от %s.txt' % datetime.datetime.now() | |
with open(os.path.join(PATH_TO_LOGS, file_name), 'w') as file_: | |
while True: | |
items = port.readline().split(',') | |
items[1] = items[1].replace('-', '') | |
# Если данные не изменились , то и не выводим | |
if back_data and back_data != items: | |
output_line = 'Дальность : {:<10}Скорость : {:<10}'.format( | |
items[0], items[1] | |
) | |
print output_line | |
file_.write(output_line + '\n') | |
back_data = items | |
if __name__ == '__main__': | |
port = _config() | |
main(port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment