I have some Devices connected to my Notebook via a RS485 to USB Converter and want to detect them in a python programm.
I'm running this Code with PyCharm Community Edition on a Windows 7 Notebook, I've installed pyserial with pip.
import serial
x = list(serial.tools.list_ports.comports())
print(x)
And got this error:
Traceback (most recent call last): File "C:/Users/rzzrgx/.PyCharmCE2018.3/config/scratches/scratch_1.py", line 3, in x = list(serial.tools.list_ports.comports()) AttributeError: module 'serial' has no attribute 'tools'
To check that it is installed, start Pyzo and at the command prompt type in: import serial If it just gives you another >>> prompt, all is good. Checking that it is really working.
PySerial is a library which provides support for serial connections ("RS-232") over a variety of different devices: old-style serial ports, Bluetooth dongles, infra-red ports, and so on. It also supports remote serial ports via RFC 2217 (since V2. 5).
Install PySerialIf you are using windows you need to uncompress this into a folder. Unfortunately, it is not a normal zip file, so you may need to download a tool such as 7-zip (http://www.7-zip.org/). If you are using a Mac or Linux computer, then open a Terminal session, 'cd' to wherever you downloaded pyserial-2.6.
Wrong way to import , correct it like below:
from serial.tools import list_ports
x = list(list_ports.comports())
print(x)
or
import serial.tools.list_ports
plist = list(serial.tools.list_ports.comports())
print(plist)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With