Python 3 compatibility
Brought to you by:
cliechti
I found that using 2to3 is not enough for Pyserial works properly using python3 [#161]. I've found that write method in serialposix.py use d = to_bytes(data). That works for pyhton2 but not for python 3. I made this modification and now my application works fine.
original:
# Previous code ...
def write(self, data):
"""Output the given string over the serial port."""
if not self._isOpen: raise portNotOpenError
d = to_bytes(data)
Modified:
# Previous code ...
def write(self, data):
"""Output the given string over the serial port."""
if not self._isOpen: raise portNotOpenError
if sys.version_info < (3,0):
d = to_bytes(data)
else:
d = bytes(data,'ISO-8859-1')
pyserial expects bytes. any sort of encoding should be handler in the users code, not within the library.