In multithreading, the data received by the serial port is incorrect
-
I'm surprised, that your application work at all (it should not work) and not has been crashed. :)
PS: Don't use the threads if you not sure how to use it. Just use signals/slots from a main application thread (as advised before).
-
I'm surprised, that your application work at all (it should not work) and not has been crashed. :)
PS: Don't use the threads if you not sure how to use it. Just use signals/slots from a main application thread (as advised before).
-
Hi and welcome to devnet,
Why not use Qt's asynchronous nature rather that spinning a while loop without any really breaking conditions ?
-
@HermesSJC said in In multithreading, the data received by the serial port is incorrect:
@kuzulis But,these codes refer to the official example "Blocking Slave Example"
Please compare that "official examples" code to your provided code and find differences.
-
@HermesSJC said in In multithreading, the data received by the serial port is incorrect:
@kuzulis But,these codes refer to the official example "Blocking Slave Example"
Please compare that "official examples" code to your provided code and find differences.
wrote on 20 Jul 2018, 02:38 last edited by@kuzulis said in In multithreading, the data received by the serial port is incorrect:
@HermesSJC said in In multithreading, the data received by the serial port is incorrect:
@kuzulis But,these codes refer to the official example "Blocking Slave Example"
Please compare that "official examples" code to your provided code and find differences.
I know the differences between the "official examples" and the code I wrote. Maybe because my transmission speed and frequency are fast, when using the signal "readyRead", it will loss data when running about three minutes, so I try using child threading to read data from serial port.
-
@kuzulis said in In multithreading, the data received by the serial port is incorrect:
@HermesSJC said in In multithreading, the data received by the serial port is incorrect:
@kuzulis But,these codes refer to the official example "Blocking Slave Example"
Please compare that "official examples" code to your provided code and find differences.
I know the differences between the "official examples" and the code I wrote. Maybe because my transmission speed and frequency are fast, when using the signal "readyRead", it will loss data when running about three minutes, so I try using child threading to read data from serial port.
hi @HermesSJC,
can you please define "fast transmission speed"?
serial ports are rather slow, but as the data is buffered, you should not lose a byte when using readyRead.
also, which platform and Qt verson is this?
regards
-
wrote on 20 Jul 2018, 09:53 last edited by
Hi. I love to write multithreaded applications to manage ioT devices and others.
So there are devices that send data slowly (for example the IoT devices) but others could send data using serial port at 1 Mb/s and I have to manage them simultineously.
Each connection has got a thread and no one byte was missing.
You should review your code. -
hi @HermesSJC,
can you please define "fast transmission speed"?
serial ports are rather slow, but as the data is buffered, you should not lose a byte when using readyRead.
also, which platform and Qt verson is this?
regards
wrote on 20 Jul 2018, 14:22 last edited by@aha_1980 said in In multithreading, the data received by the serial port is incorrect:
hi @HermesSJC,
can you please define "fast transmission speed"?
serial ports are rather slow, but as the data is buffered, you should not lose a byte when using readyRead.
also, which platform and Qt verson is this?
regards
I 'm sorry that I do loss data when using the signal readyRead (Maybe my data processing isn't perfect)
my platform is based on win10 x64 and I use qt5.9.6 (msvc2015 x64) .
as the code shown in the stm32 , I send data about from 5Hz to 60Hz and the band rate is 115200.I have tried sending data about 2Hz,the problem of losing data will be gone.(sorry my mother language is not English, so maybe you will free strange when reading my words) -
Hi. I love to write multithreaded applications to manage ioT devices and others.
So there are devices that send data slowly (for example the IoT devices) but others could send data using serial port at 1 Mb/s and I have to manage them simultineously.
Each connection has got a thread and no one byte was missing.
You should review your code.wrote on 20 Jul 2018, 14:28 last edited by@mrdebug said in In multithreading, the data received by the serial port is incorrect:
Hi. I love to write multithreaded applications to manage ioT devices and others.
So there are devices that send data slowly (for example the IoT devices) but others could send data using serial port at 1 Mb/s and I have to manage them simultineously.
Each connection has got a thread and no one byte was missing.
You should review your code.I have shown the code on my slave computer at the beginning of the question which is based on STM32F407 and I ' sure that the configuration of register has no problem. I think I have no problem after reviewing it.
-
wrote on 20 Jul 2018, 14:46 last edited by mrdebug
Please try
while (true) { if (SerialPort.waitForReadyRead(100)) { while (SerialPort.canReadLine()) qDebug() << SerialPort.readLine(); } }
Now you can work on the already ready buffer obtained from "SerialPort.readLine();"
13/13