user2362956
user2362956

Reputation:

Send data to USB GPIO device on Ubuntu

I use a USB GPIO device. When it was connected to PC, it created a file that was named "/dev/ttyACM0". I want to send data using termios.
I run

int fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);

in C code, but it didn't work.
What should it be?

UPDATE

After USB device was connected to PC, I run dmesg command on terminal. It showed device information such as product, manufacturer, idVendor, idProduct etc.

UPDATE 2 My error was "no file or directory". So I tried this method for solution. I run sudo stty crtscts -F /dev/ttyACM0.I rewrite open port via int fd = open("/dev/tty1", O_RDONLY | O_NOCTTY | O_NDELAY); I recompiled and run my code. New runtime error is "/dev/tty1 : Permission denied"

Upvotes: 1

Views: 1253

Answers (2)

Manolis Ragkousis
Manolis Ragkousis

Reputation: 665

You just don't have permission to write to that device, that's why it worked with sudo.
You just have to add your user account to the appropriate group, which probably is tty for /dev/ttyACMx (this depends on the distro though).

Or you could change the permissions of that device with sudo chmod 644 /dev/ttyACM0.

You may find this link helpful.

Upvotes: 0

user2362956
user2362956

Reputation:

For "permission denied" error, you should run $ sudo ./exe. I did, it worked fine!

Upvotes: 2

Related Questions