This is not my code and I am fairly new to Python. I did not know how
much it would take to convert pyserial to 3.0. Someone more
knowledgeable than me could do it better and faster. I just want to
see if I could help get it to work.
I was wrong, it seems that if type(port) in (str, bytes): or isinstance
(port, str) works just fine for setting the ports.
The issue now is reading and writing the data.
I got the read() to kind of work with:
bytes(buf[:n]) replacing str(buf[:n])
but with readline() it seems to be missing the '\n' because it just
runs indefinitely( I can see the \n if I read enough bytes with read()
write seems to be related to a win32 issue. win32file.WriteFile does
not like anything I convert it to:
str gives the buffer error
bytes gives a "string argument without an encoding" error
Sorry for the confusion, I just want to be able to use all Py3k on
this project that I am working on and pyserial has not been converted
so I just started messing around with it.
Thanks for the help.
Seth
Seth said:
I tried all three ways you guys listed nothing seems to convert the
string to bytes.
It may have to do with the makeDeviceName function, but I can't find
where that is defined.
Here is the whole block of code:
if type(port) in (str, bytes): #strings are taken directly
Originally: if type(port) in [type(''), type(u'')]
self.portstr = port
else:
self.portstr = self.makeDeviceName(port)
str and bytes are two totally unrelated things in Python 3.0. You can no
longer treat them equally like str and unicode in Python 2.x. Your could
should not work under Python 3.0 anyway. u'' is invalid in 3.x.
Also please don't use ugly type checks like type(something) == type('').
Starting with Python 2.2 you should use isinstance, for example
isinstance(number, (int, long)).
Christian