Not able to open port in Jetson TX2

General discussion of using Roboclaw motor controllers
Post Reply
cdavila
Posts: 1
Joined: Tue Jul 21, 2020 1:33 pm

Not able to open port in Jetson TX2

Post by cdavila » Tue Jul 21, 2020 1:38 pm

Hi,

I'm developing this application where 4 MCP233 will controll 4 motors. My python code works fine in windows, although some times I need to switch from python 3 to 2, as the com port won't open.

Now in the Jetson TX2, I do see the comports /dev/ttyACM0 and /dev/ttyACM1 on the list, but the python code won't be able to open them. No other application is using the ports I believe. My code is this one:

import time
from roboclaw import Roboclaw

#Windows comport name
#rc = Roboclaw("COM5", 115200)
#Linux comport name
rc = Roboclaw("/dev/ttyACM1",115200)

rt=rc.Open()

print(rt)

while 1:
#Get version string
version = rc.ReadVersion(0x80)
if version[0]==False:
print("GETVERSION Failed")
else:
print(repr(version[1]))
time.sleep(1)

And the output is:

0
Traceback (most recent call last):
File "roboclaw_readversion.py", line 15, in <module>
version = rc.ReadVersion(0x80)
File "/home/sosl/PycharmProjects/TLA_Heliostat/GUI/roboclaw.py", line 708, in ReadVersion
self._port.flushInput()
AttributeError: Roboclaw instance has no attribute '_port'

The first 0 is the print rt, meaning the software was not able to open the port. Same when changin to port ttyACM0. Any ideas of how can I make it work?

User avatar
Basicmicro Support
Posts: 1404
Joined: Thu Feb 26, 2015 9:45 pm

Re: Not able to open port in Jetson TX2

Post by Basicmicro Support » Wed Jul 22, 2020 8:14 am

Unfortunately I cant help with this since I don't have a jetson but I've approved the post so maybe one of our other Jetson uses will post. We do have a few of them.

This is a Jetson setup problem which means I really don't have any usefull knowledge to help you with. About all I can think of is did you try running python with sudo? Maybe a permissions problem. You can also go into the roboclaw.py file and add print lines to the Open function to get the specific error code/message

James
Posts: 15
Joined: Thu Oct 24, 2019 3:38 am

Re: Not able to open port in Jetson TX2

Post by James » Thu Jul 30, 2020 6:53 am

Here's what's wrong:
Open() fails to open the port, because it returns 0.
If you open "roboclaw.py", and check Open() (lines 1030-1035 in my version), you'll see that Open() is supposed to return 1 on success, and 0 if the serial library raises an exception, which in your case it does.
You can try the following snippet:

Code: Select all

import serial
x = serial.Serial("/dev/ttyACM0")
If it raises a SerialException exception (something like "serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyS0: [Errno 13] Permission denied: ‘/dev/ttyACM0’"), you'll know that it's an access issue.

On the Raspberry Pi, If you run your code as an ordinary user (without sudo), you need to add the user to the "dialout" group, otherwise the serial ports are inaccessible to you. I don't know if TX2 follows a similar pattern...

Open() should be re-raising such exceptions imho, not devour them in an oblivious 0 result...
Go tell the Spartans, stranger passing by,
that here, obedient to their laws, we lie.

User avatar
Basicmicro Support
Posts: 1404
Joined: Thu Feb 26, 2015 9:45 pm

Re: Not able to open port in Jetson TX2

Post by Basicmicro Support » Fri Jul 31, 2020 8:38 am

Yes, my mistake. Forgot we just captured the exception and return 0 or not 0.

James is correct, we should pass on the exception. You can modify the roboclaw.py file to do just that if you prefer. Then you can catch the exception and print out the error message to get a bit more detail.

The roboclaw.py library was written to be as easy to use as possible but in doing so we hide a lot. The assumption is you have working serial ports which isn't necessarily true of course.

Post Reply