Mr-Ntic / qextserialport

Automatically exported from code.google.com/p/qextserialport
Other
0 stars 0 forks source link

Blocking read function #29

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What new feature(s) would you like to see included?
I would much appreciate a function that blocks execution until a new char 
is received.

the idea is:

read thread::
for(;;){
...
do {
  qextserialport->read(&charBuffer);
  myBuffer[index] = charBuffer;
  index++;
} while (charBuffer != '\n');
send(myBuffer);
...
}

this would send a string finished with a '\n'

Original issue reported on code.google.com by j.peguer...@gmail.com on 16 Dec 2009 at 10:35

GoogleCodeExporter commented 8 years ago
If you use Windows and if you setup  the Timeout "ReadIntervalTimeout" with 0, 
the
getchar should block, till one byte is read. If you do not setup the timeout at 
all
yet, and it still does not work(the blocking read) than the question is: what 
are the
default values for timeouts? Are there deafult values in qextserialport at all 
or the
OS has his default values?

About the comport timeouts in windows:
http://msdn.microsoft.com/en-us/library/aa363190%28VS.85%29.aspx
"A value of zero indicates that interval time-outs are not used. "
Here is Win_QextSerialPort::setTimeout(ulong sec, ulong millisec): 
00865     LOCK_MUTEX();
00866     Settings.Timeout_Sec=sec;
00867     Settings.Timeout_Millisec=millisec;
00868     if(isOpen()) {
00869         Win_CommTimeouts.ReadIntervalTimeout = sec*1000+millisec;
00870         Win_CommTimeouts.ReadTotalTimeoutMultiplier = sec*1000+millisec;
00871         Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
00872         Win_CommTimeouts.WriteTotalTimeoutMultiplier = sec*1000+millisec;
00873         Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
00874         SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
00875     }
00876     UNLOCK_MUTEX();
So for setting ReadIntervalTimeout to zero you have call this function: 
setTimeout(0,0);
could you post pls whether this solve your problem.
Juergen.

Original comment by henningjuergen@gmail.com on 20 Dec 2009 at 2:22

GoogleCodeExporter commented 8 years ago
Yes, I'm using windows.

But no luck at all.

this is my initialization code:

init(){
...
    extSerialPort.setPortName( serial_port );

    extSerialPort.setBaudRate(BAUD38400);

    extSerialPort.setDataBits(DATA_8);

    extSerialPort.setTimeout(0);

    stateIsOpen = extSerialPort.open(QIODevice::ReadOnly);
...
}

I keep getting the same character repeated 'n' times.

I use this "hack" as a workaround:

ReadThread:
...
while ( extSerialPort.bytesAvailable() < 100 )
   this->msleep(1);
...

Original comment by j.peguer...@gmail.com on 20 Dec 2009 at 3:37

GoogleCodeExporter commented 8 years ago
Same results with:

...
    extSerialPort.setPortName( serial_port );

    extSerialPort.setBaudRate(BAUD38400);

    extSerialPort.setDataBits(DATA_8);

    stateIsOpen = extSerialPort.open(QIODevice::ReadOnly);

    extSerialPort.setTimeout(0);
...
}

Original comment by j.peguer...@gmail.com on 20 Dec 2009 at 3:42

GoogleCodeExporter commented 8 years ago
What you really want is waitForReadyRead() but this is not implemented yet.  In 
the 
meantime, I would suggest using it in EventDriven mode so you don't have to 
block at 
all.

Original comment by lst...@gmail.com on 28 Jan 2010 at 11:21