I can't open serial port to start communication in linux ubuntu. I've tried this:
int OpenPort(void) {
int fd;
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if(fd == -1)
{
printf("Failed to open port.\n");
}
else
{
fcntl(fd, F_SETFL, 0);
printf("Opened!\n");
}
return(fd);
}
int main()
{
int x = OpenPort();
printf("%i\n", x);
exit(0);
}
I'm new in linux and found this code online, but it doesn't work for me.