Re: write() only sends 16 chars to serial port?
- From: Grant Edwards <grante@xxxxxxxx>
- Date: Wed, 19 Sep 2007 14:50:35 -0000
On 2007-09-18, gus.reid@xxxxxxxxx <gus.reid@xxxxxxxxx> wrote:
Then the write method. It uses Qt strings, but their behaviour is as
expected. The toLatin1() method returns the string in standard 0
terminated C char* format :
void SerPort::SendMessage(QString message)
{
//Pause management
struct timespec delay, rem;
delay.tv_sec = 0;
delay.tv_nsec = 1000000; //1 ms (was 10ms)
fprintf(stderr, "Message Length = %d\n", message.length());
int retVal = write(fSerial, message.toLatin1(), message.length());
fprintf(stderr, "Wrote %d bytes\n", retVal );
tcflush( fSerial, TCOFLUSH );
}
Ah, I think I see the problem. When you call write(), the
serial driver fills the tx FIFO with 16 bytes and starts it
transmitting. You then almost immediately call tcflush(),
which discards whatever is waiting to be sent in the serial
driver's tx buffer (it should have discarded what was in the tx
FIFO also, but apparently it's a bit broken).
from "man termios"
tcflush() discards data written to the object referred
to by fd but not transmitted, or data received but not
read, depending on the value of queue_selector:
you probably want to call tcdrain()
tcdrain() waits until all output written to the object
referred to by fd has been transmitted.
Warning: tcdrain() may or may not wait until the tx FIFO is
completely empty. It's supposed to, but as we've seen handing
of the FIFO isn't quite right...
--
Grant Edwards grante Yow! ... the HIGHWAY is
at made out of LIME JELLO and
visi.com my HONDA is a barbequeued
OYSTER! Yum!
.
- Follow-Ups:
- Re: write() only sends 16 chars to serial port?
- From: gus . reid
- Re: write() only sends 16 chars to serial port?
- From: gus . reid
- Re: write() only sends 16 chars to serial port?
- Prev by Date: Re: Viewing multiple .png files simultaneously
- Next by Date: Re: priority queues (was: Configuration file parser)
- Previous by thread: Re: write() only sends 16 chars to serial port?
- Next by thread: Re: write() only sends 16 chars to serial port?
- Index(es):