Serial port locked by application?
Issue
- User has an issue on a server using the serial port. The application receives data on the serial port, formats it and sends it to a MySQL database.
- It observed from time to time that when try to use cat
/dev/ttyS0to see whats happening on the port the command exits immediately. When this issue occur the application can't read the serial port either. To fix this, need to reboot the server. - This issue occurs after an unexpected exit of the application.
- Is there some way to
unlockthe serial port? See if the serial port is locked??
Attaching the code that initializes the port:
DEV_TTY=/dev/ttyS0
void init_tty()
{
fa=open(DEV_TTY,O_NDELAY | O_RDWR);
if(tcgetattr(fa,&io_port) < 0) printf("Error in tc get attr\n");
else printf("Ok in tc get attr at : %s\n",C_dev_tty);
io_port.c_iflag |= IXANY;
io_port.c_iflag &= ~(INPCK | ISTRIP | IXOFF);
io_port.c_oflag &= ~(OPOST);
io_port.c_cflag &= ~(CSTOPB | PARENB | PARODD);
io_port.c_cflag |= B9600 | CLOCAL | CREAD | CS8;
io_port.c_lflag |= NOFLSH;
io_port.c_lflag &= ~(ICANON | ECHO | ISIG |ECHONL | ECHOK);
io_port.c_cc[VMIN]=0;
io_port.c_cc[VTIME]=0;
if(tcsetattr(fa,TCSANOW,&io_port) < 0) printf("Error in tc set attr\n");
else printf("Ok in tc set attr at : %s\n",C_dev_tty);
cfgetospeed(&io_port);
cfsetospeed(&io_port,B9600);
cfgetispeed(&io_port);
cfsetispeed(&io_port,B9600);
fdopen(fa,"r");
}
Then user read information from the port with this code:
test=read(fa,buff_1,1);
Environment
- Red Hat Enterprise Linux 6.4
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
