LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple com port read delayed (parallel/ continous)

Hi guys,

 

I have a problem with the Serial read of multiple COM prots....

My aim is to read continously data from 4-5 Microcontroller in parallel with a sample rate of 1 kHz.

Which works almost fine, but if I run all "com ports"  simultaneous my signals get delayed, which makes the data evaluation in the end impossible. 

 

My question is .... Why is my Signal delayed ? Is there any loop which waits for another before it can be carried out ? Or is the data rate to high?

Should i trigger  he loop which collects all the bytes ?

 

Hope somebody could help me

thanks in advance

 

 

0 Kudos
Message 1 of 10
(4,599 Views)

Why are you using 4-5 microcontrollers to get different signals? Smiley Surprised

Is it possible for you to use a single microcontroller to get 5 different types of signals? How many analog I/Os does you controller possess?

 

Another technique you can employ is by Multi-Core Programming which uses different cores of your PC's processor (provided if your host machine has multicore processor) to process tasks in parallel (each thread running in it's own processor). 

 

 

Regards. 


0 Kudos
Message 2 of 10
(4,563 Views)

Hi!

 

Why are you using 4-5 microcontrollers to get different signals? Smiley Surprised

 

-I divided the µC to their tasks... so i have 2 µC which collect a external clock signal. 1 is used for pressure sensoring and 1 for displaying, measuring und controlling temperature.

 

  Is it possible for you to use a single microcontroller to get 5 different types of signals? How many analog I/Os does you controller possess?

Iam using external clock pins... so iam limited to 4 pins/ µC

 

Another technique you can employ is by Multi-Core Programming which uses different cores of your PC's processor (provided if your host machine has multicore processor) to process tasks in parallel (each thread running in it's own processor).

 

Sounds super promissing but also super complex ... I will give it a chance 😛 

but did you check my program ... is that the way i should work ?

 

best regards

0 Kudos
Message 3 of 10
(4,554 Views)

In your code, you have used a while loop with no 'delay'. Since you're using your PC, this loop is oftenly called 'greedy loop' which takes all the CPU resources. Now your CPU is only processing what's 'insde' the loop and not taking care of nodes outside of it, where it has to initialize your COM ports.

 

Second, you don't need to reinforce to CPU to initilaize your COM ports by using flat sequence structure. I see alot of numeric processing with feedback nodes which takes up good cycles of your CPU, thereby unable to listen to other COM ports. 

 

Use seperate Timed-Loops for both COM resources with carefully selected clocks and timings. I would suggest you to first acquire data from both Arduino resources using seperate While loops with same delay. Observe if data you're interested in is being fetched in a nice synchronized way. 

 

Here is a webcast discussing techniques for Data Acquisition. 

 

 

Regards.


0 Kudos
Message 4 of 10
(4,535 Views)

Ok, we have some issues here.

 

1. You loops for reading the serial ports are not needed at all.  You can just let the termination character stop the VISA Reads instead of trying to find it yourself.  You already have the termination character settings correct based on the default values of the Configure Serial Port.  So just tell the VISA Read to read more than the longest message you would expect.  I like to use 50.

 

2. The sequence structure is not needed at all.  You have data flow to determine the order of execution.

 

3. Everything inside of a loop must complete before the loop can iterate.  This means that all of your measurements must be found before the read can be done for the next sample.  As long as data is coming in on all of the ports, this should not be an issue.

 

4. You can likely clean up a lot of your code by using a Chart instead of a Graph.  A chart keeps a history on its own while a graph does not.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 10
(4,481 Views)

@NapDynamite wrote:

In your code, you have used a while loop with no 'delay'. Since you're using your PC, this loop is oftenly called 'greedy loop' which takes all the CPU resources. Now your CPU is only processing what's 'insde' the loop and not taking care of nodes outside of it, where it has to initialize your COM ports.


With proper serial communications, this is not an issue since the VISA Read will sleep waiting for the data to come from the driver.  However, the reading 1 byte at a time is just asking for trouble.  Let the termination character settings built into VISA do all of the work for you.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 10
(4,479 Views)
Nor would I recommend a timed loop unless you are using LabVIEW real-time.
0 Kudos
Message 7 of 10
(4,451 Views)
Great. 🙂

0 Kudos
Message 8 of 10
(4,446 Views)

1. You loops for reading the serial ports are not needed at all.  You can just let the termination character stop the VISA Reads instead of trying to find it yourself.  You already have the termination character settings correct based on the default values of the Configure Serial Port.  So just tell the VISA Read to read more than the longest message you would expect.  I like to use 50.

 

I tried but the signals started to mix ... maybe i forgot to mention that the incoming signal on the first com port consist of 4 different signals...

 

3. Everything inside of a loop must complete before the loop can iterate.  This means that all of your measurements must be found before the read can be done for the next sample.  As long as data is coming in on all of the ports, this should not be an issue.

 

Iam not sure if i get your point right .... the amount of data should be the same at each port ? 

 

.........................................

 

Moreover I thought about using Sub VI?... So I would like to use a SubVI for reading data and a main VI for mean value calculation and visualisation ?

Is this also a possibility to increase the program speed ? Acutally this sound weird to me as the pc has to run 2 progs at the same time!?

0 Kudos
Message 9 of 10
(4,383 Views)

@kohlmeise wrote:

1. You loops for reading the serial ports are not needed at all.  You can just let the termination character stop the VISA Reads instead of trying to find it yourself.  You already have the termination character settings correct based on the default values of the Configure Serial Port.  So just tell the VISA Read to read more than the longest message you would expect.  I like to use 50.

 

I tried but the signals started to mix ... maybe i forgot to mention that the incoming signal on the first com port consist of 4 different signals...


Sounds like you have a bad format for your data coming out of the microcontroller then.  Since you have 4 signals, send them in a single message seperated by commas (,).  Then you just do one read and you get all 4 with no worries about mixing them up.

 

 


kohlmeise wrote:

3. Everything inside of a loop must complete before the loop can iterate.  This means that all of your measurements must be found before the read can be done for the next sample.  As long as data is coming in on all of the ports, this should not be an issue.

 

Iam not sure if i get your point right .... the amount of data should be the same at each port ?


No, you just need to be getting messages from all of your ports at about the same rate.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 10
(4,352 Views)