程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

1317_Use pyserial to read the serial port data display through python and record the log file at the same time

編輯:Python

All learning summary: GreyZhang/g_serial: Some serial learning notes which may be usefull in embedded system debugging. (github.com)

Before, the reading and display of serial port information has been realized with the help of pyserial.In fact, adding a log file record is also very simple.If you just add the most primitive log information, you can record it directly in a file.Here, I implemented a simple attempt.

In the design, I did not try to write all after opening the file once, but used the method of continuously opening the file and appending.Because, when using other serial port tools, I also have some attempts to view the log file. I think it is also very good if the log file can be continuously refreshed and new data can be seen continuously.

In this way, while recording continuously, we can view the recorded content with the help of editors such as VS Code that load and refresh quickly.

I used Arduino's serial port monitoring tools a lot before, on the one hand, because the serial port monitoring tools I have come into contact with may not be many, on the other hand, Arduino's serial port monitoring tools have completely satisfied my personal needs.need.That way, I have no other drive to find and use more tools.The important thing about my use of Arduino's serial monitoring tool is that it supports the display of timestamp information, so it is very helpful for me to understand the timing interval of the actions executed by the software.If, the log file has such information, then this is also very good.

I have also used putty, an open source software, for a long time.It is also used to record the log, which is more convenient.But what I am not very satisfied with using this tool is that it is inconvenient to add timestamp information in the log file.I read the instructions on the Internet, explaining that such a function is not easy to do.However, another solution is given on the website.I didn't study why it's not good to do it, maybe in some scenarios, such implementation is challenging.But for me, the amount of data I need is not large, maybe not very fast, and it is very useful to simply read the system time as a reference.

For this reason, the above design is made.

Of course, this is just a casual handwriting, and the design is not very good.The main problem is that there is a lot of repetitive code. In fact, the processing of timestamps can be isolated into a special function.However, simple testing or temporary use, in the case of such a simple code, is also possible.Here, I not only added a write, but also added a print process.In fact, it is very simple. I want to see the effect of the Arduino serial port monitoring tool in the process of printing.

In this way, the effect of printing and displaying is available.

Looking at the log information again, it basically meets my expectations.If such a function is integrated into my development workflow later, it will still be of some help to my work efficiency and quality.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved