1. Error description
>>> t=serial.Serial("COM3",4800);
>>> n=t.write('00000200=0000020');
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
n=t.write('00000200=0000020');
File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialwin32.py", line 308, in write
data = to_bytes(data)
File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialutil.py", line 63, in to_bytes
raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: '00000200=0000020'
>>> n=t.write('hu');
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
n=t.write('hu');
File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialwin32.py", line 308, in write
data = to_bytes(data)
File "D:\Python\Python36\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialutil.py", line 63, in to_bytes
raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: 'hu'
>>>
2. Error reason
You need to add the transmitted string to the encode () method, and you need to encode the string
3. Solutions
>>> n=t.write (' 00000200=00000200 '. Encode ());
>>> print (T.PORTSTR);
COM3
>>> print (n);
>>> s=t.read (n);
print (s);