TypeError: can only concatenate str (not "bytes") to str
Hello.
I am trying to use the canusb package on ROS Noetic (installed on Raspberry PI OS x64) but the problem is this package is written on python2 but Noetic uses python3 so there are some incompatibilities.
When I am trying to run the package the following error appears:
Traceback (most recent call last):
File "/home/pi/catkin_ws/src/canusb/script/canusb.py", line 191, in <module>
can.init()
File "/home/pi/catkin_ws/src/canusb/script/canusb.py", line 57, in init
line = self.readline()
File "/home/pi/catkin_ws/src/canusb/script/canusb.py", line 51, in readline
ret += c
TypeError: can only concatenate str (not "bytes") to str
The code lines on the package are:
def readline(self):
"""
Overrides io.RawIOBase.readline which cannot handle with '\r' delimiters
"""
ret = ''
while True:
c = self.read(1)
if c == '':
return ret
elif c == '\r':
if ret == 'z' or ret == 'Z':
self.status = 0
return ret + c
elif c == chr(7):
self.status = -1
return c
else:
ret += c
What can I change to fix the problem up?
Thnaks in advance.
Best regards. Alessandro
EDIT
Appear the following errors:[ERROR][]: Disable timestamp: Failed!
and [ERROR][]: Disable baudrate: Failed!
.
I post the links of the original and the modified code below.
I hope with this anyone can help me. Best regards.
As you've found Python 3 treats this differently than Python 2 and 3.25 minutes with google gave me a full background on the issue and several ways to solve your particular question. But given what I just found on google, I suspect any changes you make on this bit of code may propagate throughout the node and lead you down a path of self destruction. If you need to use nodes written in Python 2 and you're not a Python programmer, probably want to consider using earlier version of ROS that uses Python2.
https://www.google.com/search?q=pytho...
Effectively I am not a python programmer so I am a bit lost. I try changing code googling and porting code from python2 to 3 as you said, and now I have some big problems (see the edit in question). The problem of use other version od ROS is that in RPI4 with debian almost nothing doesnt work.
RPi4 with Ubuntu 18 and ROS Melodic seem to work fine. Melodic runs Python 2. https://answers.ros.org/question/3593...
I have alredy tried Ubuntu 18 (Server) on RPI4 and it was so slow. I don't know the reason but it was very difficult to use.