ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to write a node that uses libusb?

asked 2014-07-13 23:05:30 -0500

ZiyangLI gravatar image

Hi all,

I need to write a node to listen to a usb port via libusb. I used to do that with a simple cpp program, but I had to use sudo to open the port. How can I rosrun such a program?

By the way, I am also interested in how rosserial pkg. does the trick. Because I think open a serial port also require root privilege.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-14 00:32:44 -0500

If you want to avoid the requirement of root privileges when accessing a USB device, you should grant appropriate permissions to your user.

For example, lets say that your USB device is located in: /dev/ttyUSB0 (I am assuming that you use Ubuntu)

If you execute "ls -la", you should get something like:

myuser@mycomputer:~$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 4, 64 Jul  8 08:49 /dev/ttyUSB0

This means that the root user and the dialout group will have read-write permission and the rest of the users will not have access. Then what you should do is to add "myuser" to the dialout group:

sudo adduser myuser dialout

This will give myuser enough privileges to read and write to the /dev/ttyUSB0 device (remember to restart your session after adding the user to the goup for the privileges to have effect)

From this point on you will not need to sudo any more to access your USB device.

This is just an example, your case might be different. But I hope it helps.

edit flag offensive delete link more


Thank you for your reply. It is clear and I believe it will work. I find another solution, which adds a rule to udev and it also works.

ZiyangLI gravatar image ZiyangLI  ( 2014-07-14 04:03:09 -0500 )edit

Question Tools

1 follower


Asked: 2014-07-13 23:05:30 -0500

Seen: 1,133 times

Last updated: Jul 14 '14