Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30

Thread: QSerialPort High Speed Serial Reading from board and Logging Issue

  1. #21
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    OK. Create an else for if in line 13
    Qt Code:
    1. if(one_packet[0] == 's') // 's' buldur kodu yaz dene!
    2. {
    3. }
    4. else
    5. {
    6. qDebug() << one_packet;
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #22
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by Lesiok View Post
    OK. Create an else for if in line 13
    Qt Code:
    1. if(one_packet[0] == 's') // 's' buldur kodu yaz dene!
    2. {
    3. }
    4. else
    5. {
    6. qDebug() << one_packet;
    7. }
    To copy to clipboard, switch view to plain text mode 
    Code never fall into there because i always handling with that error with this code.

    Qt Code:
    1. indexOfType = ArrayBuffer.indexOf('s');
    2.  
    3. if(indexOfType >= 1)
    4. {
    5. ArrayBuffer.remove(0,indexOfType);
    6. }
    To copy to clipboard, switch view to plain text mode 

    If any errorful package comes starting without 's' it will be removed from package and my loss will be just 1 number. But i'm losing 3000-4000 numbers.

  3. #23
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    After ArrayBuffer.remove(0,indexOfType); ArrayBuffer can be shorter than ExpectedPacketLength.
    P.S.
    If data in frame are binary then every byte in frame can be 's'.
    Last edited by Lesiok; 23rd January 2017 at 13:09.

  4. #24
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Actually it is not a problem because when ArrayBuffer.size below the expected packet length its leaving the slot and waiting for readyRead signal and i debugged it and see that:

    Last 6 bytes to be processed e.g : {value,value,'s',value,value,value}. first two value is removed. and became {'s',value,value,value}. Then readyRead is emitted by the QT and data is appending to buffer again and these 4 bytes of ArrayBuffer which inherited by the last process is appended with the other {value,'s',value, bla bla... } data. And i checked their CRC and values. Everything is ok. But sometimes this buffer gets wrong number. Lets say we counted 1 to 150 without error and our buffer stayed like i exampled. Then its not 151 it became 500 or 1000 directly.

    Really hard to explain. I'm trying my best. Thanks for trying to help.

  5. #25
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    It is a problem because after remove You have in buffer only 4 bytes not 5. Try this code :
    Qt Code:
    1. if(indexOfType >= 1)
    2. {
    3. ArrayBuffer.remove(0,indexOfType);
    4. if( ArrayBuffer.size() < ExpectedPacketLength )
    5. break;//We exit the loop
    6. }
    To copy to clipboard, switch view to plain text mode 

  6. #26
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    I added this but nothing changed. I will struggle more about this. If i can find the bug will post it to here.

    Thanks for all your helps really.

  7. #27
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Hi again to everyone.

    I figure out the problem it's about while loop when readyread signal is emitted in the parsing state. Now if i remove the loops and just emit the readyread signal and directly parse , it became correct but really slow because everytime when data is received parsing will be done.

    Have i got any option to receive data and parse it simultaneously. How can i use serial thread and my object simultaneously ? Just need a documentation or an idea. I searched documentation but couldn't understand fully. Thanks a lot.

  8. #28
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    About which loop you speak ? Basically, you do not need an additional thread to handle serial port.

  9. #29
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    Quote Originally Posted by Lesiok View Post
    About which loop you speak ? Basically, you do not need an additional thread to handle serial port.
    Qt Code:
    1. while(ArrayBuffer.size() >= ExpectedPacketLength)
    To copy to clipboard, switch view to plain text mode 

    here this is the loop i mention about. When parsing is going on readAll can't get the data while loop was going on. I'm thinking creating another thread and when run it arraybuffer will be parsed simultaneously while reading data from serial port is going on.

    Am i thinking wrong ?

    Thanks.

  10. #30
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialPort High Speed Serial Reading from board and Logging Issue

    What are You doing in "parsing" ?
    If signal emiter and receiver are both in this same thread sending signal is like normal function calling. So that a new signal is issued only after the previous service.

Similar Threads

  1. Replies: 1
    Last Post: 22nd June 2016, 00:32
  2. QSerialPort - speed and performance
    By Wer_Bn in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2015, 18:12
  3. qserialport and reading bytes
    By gab74 in forum Newbie
    Replies: 3
    Last Post: 14th February 2014, 21:11
  4. QSerialPort :: read - Serial Comms noob.
    By llaregyb in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2014, 13:18

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.