I am developing an application that reads data from a serial port (on Ubuntu), and below is the relevant code used.
When I put this inside my main, it works just fine. However, if I put the exact same code inside a method, it will output weird data. I have no idea why that's so, if anyone has any guidance it would be greatly appreciated.
int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd, F_SETFL, 0);
read(fd, value, 2);
printf("%x %x", value, value;