0
$\begingroup$

Rosanswers logo

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.

Original

Modified

I hope with this anyone can help me. Best regards.


Originally posted by Alessandro Melino on ROS Answers with karma: 113 on 2020-09-11

Post score: 0


Original comments

Comment by billy on 2020-09-13:
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=python+cast+byte+to+string&oq=python+cast+byte+to+string&aqs=chrome..69i57.8663j0j7&sourceid=chrome&ie=UTF-8

Comment by Alessandro Melino on 2020-09-15:
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.

Comment by billy on 2020-09-15:
RPi4 with Ubuntu 18 and ROS Melodic seem to work fine. Melodic runs Python 2. https://answers.ros.org/question/359358/ros-kinetic-on-raspberry-pi-4/?comment=359485#post-id-359485

Comment by Alessandro Melino on 2020-09-15:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Solved creating a script from scratch.


Originally posted by Alessandro Melino with karma: 113 on 2021-05-26

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.