ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While Loop is very slow for serial reading

Solved!
Go to solution

Hello

I try to read serial data (UART @ 57600baud) with a while loop. Therefore the while loop is triggered each time when receiving a char ">" to take a timestamp. The timestamp is written to an array.

vi.png

Interestingly I see a pattern which somehow indicates that the loop or windows interrupts the reading. 

 

Question:

- How can I improve or speed up the serial reading to get more constant timestamp?

 

thanks

The char ">" comes in 10Hz +/-2% (verified) but when plotting the timestamp array I see following:

plot.png

 

0 Kudos
Message 1 of 26
(3,012 Views)

@Norick17 wrote:

 

Question:

- How can I improve or speed up the serial reading to get more constant timestamp?

 

 


What problem are you trying to solve?

 

Serial communication is designed for communication, not for time-keeping. Also, you will probably want to avoid "Bytes At Port". Check out https://labviewwiki.org/wiki/VIWeek_2020/Proper_way_to_communicate_over_serial

Message 2 of 26
(3,005 Views)

Take a look at Proper way to communicate over serial 

 

"Do not use Bytes at port!!!!" is  the first thing he says.

 

Certified LabVIEW Architect
Message 3 of 26
(2,993 Views)

And instead of Bytes at port, use Termination character and set it to '>' (62). 

thols_0-1654865462752.png

 

Certified LabVIEW Architect
Message 4 of 26
(2,987 Views)

I try to solve the problem that the lower values (every 4th) should be much higher. vi_soll.png

 

I measured with a scope the reading and all readings are around 10.4-10.5Hz without any values below 10 Hz like I measure it in LV with the while loop. Now I try to solve it with a different vi in order to have a more accurate reading.

0 Kudos
Message 5 of 26
(2,958 Views)

@Norick17 wrote:

I try to solve the problem that the lower values (every 4th) should be much higher. 

 

Yes. That is why I asked. I suspect that there is an https://en.wikipedia.org/wiki/XY_problem here. There are more problems to that approach you are on than just Bytes at Port. I strongly believe that you will be more satisfied with the feedback once you tell us why you are trying to get 10Hz readings from your serial port.

0 Kudos
Message 6 of 26
(2,947 Views)

Serial reading is not appropriate for precise timing. Remark however that the average frequency is about 10.05 as expected.

Thus not only the lower values are wrong, but the higher are (less) wrong too.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 7 of 26
(2,939 Views)

@thols wrote:

Take a look at Proper way to communicate over serial 

 

"Do not use Bytes at port!!!!" is  the first thing he says.

 


ok - and leave the number of bytes open?

read.png

0 Kudos
Message 8 of 26
(2,931 Views)

@Norick17  ha scritto:

@thols wrote:

Take a look at Proper way to communicate over serial 

 

"Do not use Bytes at port!!!!" is  the first thing he says.

 


ok - and leave the number of bytes open?

read.png


No, wire a large number, greater than any expected message size. And leave the property node outside the loop. Once it's enough.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 9 of 26
(2,922 Views)

@LLindenbauer wrote:

@Norick17 wrote:

I try to solve the problem that the lower values (every 4th) should be much higher. 

 

Yes. That is why I asked. I suspect that there is an https://en.wikipedia.org/wiki/XY_problem here. There are more problems to that approach you are on than just Bytes at Port. I strongly believe that you will be more satisfied with the feedback once you tell us why you are trying to get 10Hz readings from your serial port.


You are asking about "why" but this is absolutely irrelevant for my problem (question), because I need to know the timestamp between the "<" chars. It does not matter if it is 1, 3 or 10Hz.. The question is HOW I can improve my vi to solve the problem.

0 Kudos
Message 10 of 26
(2,914 Views)