Environment : WIN-7 64Bit
Python Ver : V3.3.2Pyserial Ver : V2.7
1. import the lib
import serial
2. List the available portsimport serial
for i in range(50):
try:
ser = serial.Serial(i)
print("COM"+str(i+1))
ser.close()
except serial.SerialException:
pass
3. Send a byte
ser.write(0xAA)
4. Send a string Greet = bytearray("Hello World", 'ascii')
ser.write(Greet)
5. Send a byte array command = [0xAA, 0x04, 0x12, 0x44]
ser.write(command)
6. Get the received data count dataLen = ser.inWaiting()
7. Read the received data
ser.read(dataLen)