Results 1 to 10 of 10

Thread: why bytesAvailable() returns '0' when there are answer data from serial port monitor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why bytesAvailable() returns '0' when there are answer data from serial port moni

    1.- Wait for X ms, depending of the data length. The serial port isn't so fast...
    2.- Don't use the serial monitor, because it can take the data from the buffer, cleaning it, and no leaving data in it.

    For example:
    Qt Code:
    1. bool threadDatos::RecibirTrama(char *trama, int num_bytes, datos *Datos)
    2. {
    3. msleep(12); // No queda de otra...esta cosa no tiene timeout ¬¬
    4. int i = PuertoSerial->bytesAvailable(); // Leer cuantos bytes hay
    5. if(i == num_bytes) // Si es igual al número de bytes requeridos
    6. {
    7. Datos->pBuffer->acquire(); // Pedir recurso en el buffer
    8. PuertoSerial->read(trama, num_bytes); // Leer el buffer de recepción
    9. Datos->cBuffer->release(); // Liberar recurso de dato valido
    10. mutex->unlock(); // Liberar puerto serial
    11. return TRUE; // Regresar con TRUE
    12. }
    13. else if(i == num_bytes + 5) // Si hay mas, debido a un NCK de SETP
    14. {
    15. Datos->pBuffer->acquire(); // Pedir recurso en el buffer
    16. PuertoSerial->read(trama, 5); // Leer el buffer de recepción
    17. PuertoSerial->read(trama, num_bytes); // Leer el buffer de recepción
    18. Datos->cBuffer->release(); // Liberar recurso de dato valido
    19. mutex->unlock(); // Liberar puerto serial
    20. return TRUE; // Regresar con TRUE
    21. }
    22. mutex->unlock(); // Liberar puerto serial
    23. return FALSE; // Error: devolver FALSE.
    24. }
    To copy to clipboard, switch view to plain text mode 

    PS: excuse for my english...

  2. The following user says thank you to zeratul for this useful post:

    to_guliang (4th June 2008)

  3. #2
    Join Date
    Apr 2008
    Posts
    44
    Thanks
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: why bytesAvailable() returns '0' when there are answer data from serial port moni

    thanks, i will try as you say.

Similar Threads

  1. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  2. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.