Error reading serial port

Hello,

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.

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