PDA

View Full Version : Serial Port Access Denied using open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);



morty346
02-10-2009, 10:43 AM
I am creating a program that opens a serial port for communication but it gets denied when I open it
I have installed a board that has two ports and have verified they are working by using the terminal:
dmesg | grep tty
console [tty0] enabled
0000:02:00.0: ttyS0 at I/O 0xdf00 (irq = 21) is a 16550A
0000:02:00.0: ttyS1 at I/O 0xde00 (irq = 21) is a 16550A

Code:


int open_port(void)
{
int fd; /* File descriptor for the port */


fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, 0);

return (fd);
}



open_port: Unable to open /dev/ttyS0 -: Permission denied
return code -1


Thank you
Greg

morty346
02-10-2009, 11:02 AM
Solved!

chmod o+rw /dev/ttyS0
chmod o+rw /dev/ttyS1

Thank you anyways!
Greg