Greetings!
I am using devc-ser8250 to communicate with my serial interfaced card. When sending the data to the card, everything works fine. I write an alert byte, wait for acknowledgement and then send the entire data packet.
But the problem occurs when the card wants to send the data.
According to the protocol, the card will send an alert byte and wait for acknowlegment (ack) from the host CPU only till 100 ms. If the card fails to receive the ack within 100 ms, it will again send the alert byte or send the data packet, if otherwise. This process of card sending the alert byte goes uptill 3 seconds.
So, in my scenario, I read the alert byte as
read (portHandle, readBuffer, 1);
tcflush (portHandle, TCIFLUSH);
and then write the ack as
write(portHandle, ack, 1);
tcdrain(fd);
and then wait for the data packet as
read(portHandle, dataBuffer, sizeof(dataBuffer);
Unfortunately, my dataBuffer contains countless of alert bytes with no data at all.
To tweak this out, I used another application to:
- write multiple acks after reading the first alert byte
- write multiple acks before and after reading the first alert byte
In the first case, the output still remained the same.
But in the last case, I got the data. It suggested that there is some synchronisation problem between writes and read.
The flags O_SYNC, O_DSYNC and O_RSYNC also don’t work, in the sense that the app don’t read/write any data then.
I also tried the O_NONBLOCK flag, but still faced the same problem.
Any suggestions on how to tackle this problem.