Method of Serial Communication Using python under windows

  • 2021-07-06 11:30:40
  • OfStack

Windows version of python does not have a built-in serial communication pyserial library, so you need to download their own. Referring to the online tutorial, there are many installation methods of pip, but it is useless to try several, so I think of downloading the library file with GitHub, and the steps are divided into:

1. Download the libraries for python-serial at Github

https://github.com/pyserial/pyserial

2. After downloading, unzip the compressed package, locate the serial folder, and locate the installation location of python (right-click IDLE, and then view the installation location of python). My address is: C:\ Users\ NI YINTANG\ AppData\ Local\ Programs\ Python\ Python36

3. Go to Python36\ Lib\ site-packages and copy the serial folder just now into site-packages.

4. Open IDLE and enter Import serial in Shell. If no error is reported, the installation is completed.

5. Test the port of connection below. Enter the following program in the program and run it to find the port of connection to the computer:


import serial
import serial.tools.list_ports
 
plist = list(serial.tools.list_ports.comports())
 
if len(plist) <= 0:
 print ("The Serial port can't find!")
else:
 plist_0 =list(plist[0])
 serialName = plist_0[0]
 serialFd = serial.Serial(serialName,9600,timeout = 60)
 print ("check which port was really used >",serialFd.name)

Related articles: