|
When to read from the serial port?
Hi all.
I am stuck porting a windows app to linux. In windows we have a waitforcommevent which keeps looking for RXCHAR event and I can use that condition to do a read on the serial port.
A similar approach in linux would be to use SIGIO interrupt and set a signal handler function to alter a global variable based on which I do a read port.
Is there a cleaner approach than this? The reason being that, I have blocked SIGIO when I am doing a "read", but while doing that I also do a IOCTL for FIONREAD, to get the number of chars in the comport. Probably this generates a SIGIO(which as told before I am blocking, till I complete "read". ), and I am getting wront character counts and my program crashes.
Well, you might say I could have blocked SIGIO after IOCTL and before 'read', but read is inside a big function and I don't want SIGIO happening when this function is going on.
Could any of you signal experts tell me what is the best approach to know that a character has arrived to be read in the serial port. I am requesting an approach very similar to what we have in windows.
Thanks
KD
|