pyserial 2.7 documentation is wrong, python 3.4 TypeError: an integer is required

pyserial 2.7 documentation is wrong, python 3.4 TypeError: an integer is required

我正在尝试 运行 来自 its webpage 的最简单的 pyserial 2.7 示例 python shell:

>>> import serial
>>> ser = serial.Serial(0)  # open first serial port
>>> print ser.name          # check which port was really used
>>> ser.write("hello")      # write a string
>>> ser.close()             # close port 

但是,它不起作用:

>>> import serial
>>> ser = serial.Serial(0)
>>> print ser.name
SyntaxError: Missing parentheses in call to 'print'
>>> print (ser.name)
COM1
>>> ser.write("hello")
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    ser.write("hello")
  File "C:\Python34\lib\site-packages\serial\serialwin32.py", line 283, in write
    data = to_bytes(data)
  File "C:\Python34\lib\site-packages\serial\serialutil.py", line 76, in to_bytes
    b.append(item)  # this one handles int and str for our emulation and ints for Python 3.x
TypeError: an integer is required
ser.write("Hello".encode())

你能试试这个吗,它应该能解决你的问题。或者;

check.write(b"Hello")

我怀疑需要将其转换为字节数组