How does one check if a serial port is already open in Linux using Posix/C functions? I want to check the status of the serial port to check if the serial port is open or not.
I would like to know what methods work for:
Checking the file descriptor to see if the serial port is open and
Checking the serial port file name to see if the the serial port is open which in the example below is "/dev/ttyUSB0"
--
// This code is for example purposes only
int open_port()
{
int fd;
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0)
{
perror("open_port: Unable to open /dev/ttyf1 - ");
}
return fd;
}
I imagine there is a "standard" way of doing this, and that is what I am trying to get to.