Error reading serial port


I am developing an application in C for my Beagle Bone Black, this application needs to send and receive bytes through a door “/dev/ttyO4”, however when running the command read the application locks and remains locked until it is stopped.

I know it’s a simple thing but I’ve tried with several examples of the internet and the problem persists.

char buf[1];
int res = read(fd, &buf, 1);