Hallo,
ich verwende Qt 4.7.1, Qserialdevice 0.3 und Windows XP.
Folgendes möchte ich machen:
TX und RX sind gekoppelt (was ich sende kann ich zurücklesen)
1. 3 Bytes senden
2. die gleichen 3 Bytes empfangen und vergleichen
3. entsprechend dem 3ten byte entweder weiter senden oder die daten eines anderen empfangen.
Jetzt habe ich das Problem mit dem zurücklesen:
daten = m_port->readAll(); // geht fuer TX
daten = m_port->read(3); // geht fuer RX
Benutze ich readAll(), dann habe ich noch alte Daten, die ich an andere Stelle mit read() schon ausgelesen habe in "daten". Die Doku ist für mich nicht verständlich? Was macht readAll()? Werden alle Daten gelesen und der UART Puffer geleert oder nicht? Was macht read() im gegensatz anders?
Unter Linux verhält es sich anders.
Eine ne Idee?
Bronko
Qserialdevice unter Windows Probleme
1. Verwenden Sie keine 0.3.0. Verwenden eine Version von Git (Master-Knoten)
http://gitorious.org/qserialdevice/qser ... all/master
2. Wenn Sie gehen zu dem Master-Knoten, dann readAll() ist in unterschiedlicher Weise (2 Möglichkeiten) durchgeführt verwenden:
- Wenn Sie den Hafen mit dem Puffer zu öffnen ( Verwenden Sie keine QIODevice::Unbuffered) - die Methode readAll () liest alle Bytes, die einen internen Puffer Klasse AbstractSerial haben. Dh in diesem Puffer-Modus-Klasse übernimmt automatisch Daten und speichert sie in seinem internen Puffer.
In diesem Fall, leert den Puffer UART (!!!) automatisch, wenn die Klasse liest die Daten (nicht readAll(), nicht read()).
- Wenn Sie den Anschluss ohne einen Puffer zu öffnen (Verwenden Sie QIODevice::Unbuffered) - dann die Klasse nicht automatisch die Daten gespeichert werden. Es nur machen Sie darüber, wie die Daten gelesen werden können. Und in diesem Fall readAll () liest Daten aus dem Port (UART) direkt. In diesem Fall sind die Timeouts Lesung sind wichtig. Methode readAll() gibt die gelesenen Daten nur, wenn keine neuen Daten und dem Zeitpunkt gingen sie (Timeout).
In diesem Fall wird der Puffer UART (!!!) Lesung readAll() oder read().
Wenn die UART-Puffer von 10 Byte, und Sie können read(3) zu lesen - dann die UART wird in den Puffer 7 Bytes bleiben. Wenn readAll() - Methode liest alle (in den Puffer 0 Byte sein) + Methode wartet während einer Zeitverzögerung von neuen bytes.
PS: Wenn ich Sie richtig verstanden. Entschuldigung für die Übersetzer.
http://gitorious.org/qserialdevice/qser ... all/master
2. Wenn Sie gehen zu dem Master-Knoten, dann readAll() ist in unterschiedlicher Weise (2 Möglichkeiten) durchgeführt verwenden:
- Wenn Sie den Hafen mit dem Puffer zu öffnen ( Verwenden Sie keine QIODevice::Unbuffered) - die Methode readAll () liest alle Bytes, die einen internen Puffer Klasse AbstractSerial haben. Dh in diesem Puffer-Modus-Klasse übernimmt automatisch Daten und speichert sie in seinem internen Puffer.
In diesem Fall, leert den Puffer UART (!!!) automatisch, wenn die Klasse liest die Daten (nicht readAll(), nicht read()).
- Wenn Sie den Anschluss ohne einen Puffer zu öffnen (Verwenden Sie QIODevice::Unbuffered) - dann die Klasse nicht automatisch die Daten gespeichert werden. Es nur machen Sie darüber, wie die Daten gelesen werden können. Und in diesem Fall readAll () liest Daten aus dem Port (UART) direkt. In diesem Fall sind die Timeouts Lesung sind wichtig. Methode readAll() gibt die gelesenen Daten nur, wenn keine neuen Daten und dem Zeitpunkt gingen sie (Timeout).
In diesem Fall wird der Puffer UART (!!!) Lesung readAll() oder read().
Wenn die UART-Puffer von 10 Byte, und Sie können read(3) zu lesen - dann die UART wird in den Puffer 7 Bytes bleiben. Wenn readAll() - Methode liest alle (in den Puffer 0 Byte sein) + Methode wartet während einer Zeitverzögerung von neuen bytes.
PS: Wenn ich Sie richtig verstanden. Entschuldigung für die Übersetzer.
Thanks for your answer kuzulis
think you can write in English here ...I think everybody who is using Qt is understanding English language
)
I have not understood everything so please confirm...
1. QSerialdevice from GIT supports QIODevice::Unbuffered, my 0.3 installation not? How do I use it? Is it an argument of the AbstractSerial constructor?
2. I have to read <10byte but very frequently (~10ms), so your suggestion is to use QIODevice::Unbuffered? So when I now use readAll() or read(x) I will get all bytes which are in the UART at this moment (and all the bytes will disappear once I have read them out)?
Is the UART buffer that one I can adjust in Windows?
3. What happens exacty when I call flush() when using unbuffered mode?
4. Is it possible to get a notification when the UART detects a frame error?
Thx for your help
I have not understood everything so please confirm...
1. QSerialdevice from GIT supports QIODevice::Unbuffered, my 0.3 installation not? How do I use it? Is it an argument of the AbstractSerial constructor?
2. I have to read <10byte but very frequently (~10ms), so your suggestion is to use QIODevice::Unbuffered? So when I now use readAll() or read(x) I will get all bytes which are in the UART at this moment (and all the bytes will disappear once I have read them out)?
Is the UART buffer that one I can adjust in Windows?
3. What happens exacty when I call flush() when using unbuffered mode?
4. Is it possible to get a notification when the UART detects a frame error?
Thx for your help
- QSerialdevice v0.3.0 from GIT supports QIODevice::Unbuffered only,1. QSerialdevice from GIT supports QIODevice::Unbuffered, my 0.3 installation not?
this version is old.
- QSerialdevice master (future 0.4.0 ) from GIT supports any mode!
Use library from master tree (not 0.3.0)!
Below I will give recommendations for master tree!
See documentation (you itself generate Doxygen ) and/or /example, and/or /test applications.How do I use it?
No, this argument in method: open()! By default open() - uses buffered mode. And the behavior of a class similarly QAbstractSocket!Is it an argument of the AbstractSerial constructor?
No, better not to use the flag QIODevice::Unbuffered.2. I have to read <10byte but very frequently (~10ms), so your suggestion is to use QIODevice::Unbuffered?
In this case, the data from the UART will automatically take a class in its internal buffer. And, of course, UART will automatically be cleared, but the data will be stored in the buffer class.
Know how many bytes in the buffer at the moment, you can call: bytesAvailable().
Next, you can now call methods: read(bytes count) or readAll().
If you are calling readAll() - then he'll return all the data from the internal buffer of class and class buffer cleared.
If you are calling read(3) - it will return you to 3 bytes of internal buffer class and the buffer is reduced by 3 bytes!
No, You do not need to configure UART buffer!Is the UART buffer that one I can adjust in Windows?
[guote]
3. What happens exacty when I call flush() when using unbuffered mode?
[/quote]
In any mode Flush method to force sends the tx-data (if they have to transfer).
I do not know. Probably not. Although - you check yourself. I'm not interested in this question (it was not necessary).4. Is it possible to get a notification when the UART detects a frame error?
Hello,
I have now used version 0.4.0. The behaviour has changed a lot.
I use your library in a separate thread, where I read/write inside the run() method. With Version 0.4.0 it is now possible to send every 10ms a 10byte message, in 0.3.0 it was 30ms?! That is very nice.
But the big problem is that if I click the botton on the GUI window, the event loop switches from 10ms to 30ms and my communication does not run anymore. Unfortunately I don't know PC programming(threading) so good, that I could explain why. My PC has a i7 CPU.
Do you have any idea?
Bronko
I have now used version 0.4.0. The behaviour has changed a lot.
I use your library in a separate thread, where I read/write inside the run() method. With Version 0.4.0 it is now possible to send every 10ms a 10byte message, in 0.3.0 it was 30ms?! That is very nice.
But the big problem is that if I click the botton on the GUI window, the event loop switches from 10ms to 30ms and my communication does not run anymore. Unfortunately I don't know PC programming(threading) so good, that I could explain why. My PC has a i7 CPU.
Do you have any idea?
Bronko