pySerial write() won't take my string pySerial write() won't take my string python python

pySerial write() won't take my string


It turns out that the string needed to be turned into a bytearray and to do this I editted the code to

ser.write("%01#RDD0010000107**\r".encode())

This solved the problem


You have found the root cause. Alternately do like this:

ser.write(bytes(b'your_commands'))


I had the same "TypeError: an integer is required" error message when attempting to write.Thanks, the .encode() solved it for me.I'm running python 3.4 on a Dell D530 running 32 bit Windows XP Pro.

I'm omitting the com port settings here:

>>>import serial>>>ser = serial.Serial(5)>>>ser.close()>>>ser.open()>>>ser.write("1".encode())1>>>