I have Python 3.6.1 and PySerial installed. I am able to get a list of COM ports connected. I want to send data to the COM port and receive responses:
import serial.tools.list_ports as port_list
ports = list(port_list.comports())
for p in ports:
print (p)
Output:
COM7 - Prolific USB-to-Serial Comm Port (COM7)
COM1 - Communications Port (COM1)
From PySerial documentation:
>>> import serial
>>> ser = serial.Serial('/dev/ttyUSB0') # open serial port
>>> print(ser.name) # check which port was really used
>>> ser.write(b'hello') # write a string
>>> ser.close() # close port
I get an error from ser = serial.Serial('/dev/ttyUSB0')
because '/dev/ttyUSB0' makes no sense in Windows. What can I do in Windows?