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

1316_Use python to read serial port data and display it

編輯:Python

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

Now, the basic environment of the serial port has been set up.Preliminary tests have also been carried out in the simulated environment, and then we have to enter the actual combat link.I use the serial port, and one of the functions I need now is to support me in the embedded software to print the software status or information I want to know through printf.Next, I can try to implement such a function first, and then directly integrate this function into my own development environment to optimize my own workflow.

In the preliminary function debugging, I want to realize the reading and display of a serial port data first.Debugging is actually very simple. I have an Arduino in my hand, which can easily provide such information simulation.Next, I will try to use the Arduino to continuously output a line of "hello python serial world!" to see if I can read it through pyserial.

Next, the Arduino code is implemented as follows:

At this point, I still feel that Arduino has a high level of convenience.If you want to do some simple controls and tests quickly, this is really a good work.In fact, tossing the serial port is often influenced by Arduino.I really hope that my own development and debugging environment can be as convenient as Arduino.

This is the printed information seen by the Arduino's serial monitor tool. If my debugging goes well later, I should get a similar effect.

This is a python code implementation. I designed an infinite loop to continuously read the information from the serial port. If it can be read, it will be printed out intact.In order to achieve the same line-by-line display effect, the default newline ending is removed when printing.

The results were very pleasing and I got the desired display.If you have such information, you can actually throw away the serial port tool later.Not only does it show that I can do this, I can also log the received results directly to the log file, or add some information such as timestamps.Using python, which is a PC-based environment, there is still a lot of content that can be added.Later, I will try to make such a function to experience it.


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