'Python Serial write function not working
I am very new to python and trying to write data using serial and python 3. Please help with the error below.
>>> import serial
>>> check=serial.Serial(1)
>>> print(check.name)
COM2
>>> check.write("test")
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
check.write("test")
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
Solution 1:[1]
You can also us data.encode('utf-8').
One of the problems of course is that the utf-8 codec is limited to a max value of 127 (7-bits) instead of the full 256 (8-bits) byte....
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ouflak |
