Il 26/05/2021 23:52, Johann Klammer ha scritto:
On 05/26/2021 01:53 PM, pozz wrote:
I used a simple driver for serial port in Linux with success in many projects, but recently I found an issue with it.
The scenario is an embedded Linux (running on iMX6) that runs a QT application (that creates a GUI on a touch display) and a C application that communicates over a serial port.
When QT application starts some complex graphics (I see its CPU load reaching 70-80%), the serial port application stops working correctly.
After some debugging, I noticed that the bytes really transmitted on the wire aren't correct. It seems one or two bytes are re-transmitted and one-two bytes aren't completely transmitted.
I suspect my serial port driver has some errors that are triggered only when the CPU is loaded by other processes, but I don't know how to fix them.
I use O_NONBLOCK flag when opening serial port, but write() always returns a positive number, so I think the byte is correctly moved to the low-level serial port driver and really transmitted... but it isn't always the case.
If I enable debugging messagin (with DEBUG_SERIAL macro), I always see correct data on stdout, but wrong data on the wire.
Any hint?
[I didn't read your code]
But here's what I used for transmitting.
static int
send_char (ser * d, char c)
{
if (d->fd == -1)
longjmp (d->env, 2);
ssize_t nbytes = TEMP_FAILURE_RETRY (write (d->fd, &c, 1));
return !(nbytes == 1);
}
I think the TEMP_FAILURE_RETRY may be important.
but there's about a zillion other flags and iocls wot could be at fault.
So I dont' really know if it helps.
I don't think TEMP_FAILURE_RETRY could help in my case. It simply retry
forever the write() while it returns -1 and errno==EINTR.
My function for writing is:
int
serial_putchar(SERIAL_HANDLE hSerial, unsigned char c)
{
int bytes_written;
bytes_written = write(hSerial, &c, 1);
if (bytes_written != 1) return -1;
return 0;
}
If write() returned -1, serial_putchar() would have returned -1 and the
caller would have detected this situation.
However in my case, when the problem arises, write() and read() never
return a negative number.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)