1
votes

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"

2
Since you have created a new (previously unknown) device name, you also need to create the kernel driver for that device.user3629249
Should I write it? Is the driver insufficient?user2362956
my device is here numato.com/16-channel-usb-gpio-moduleuser2362956
@user3629249 From the description given, the device is identifying itself as a USB CDC serial device. No additional driver is necessary.user149341
What do you mean by "didn't work"? What happens when you try it?user149341

2 Answers

0
votes

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.

2
votes

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