LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read serial & do some other tasks in parallel..

Hello,

My problem is related to RS232 serial communication. The device sends numerical
data continuously to the serial port at a rate 9600 baud/s. At the same time
my program must read RF-signal from the PCI board and do some calculations.
In the code diagram this means that I have several while-loops running in
parallel, one for serial read, one for RF-read and so on (loops do not run
at the same rate). The problem is that the data received from the serial
port is not valid on every loop cycle (instead of four bytes I get six bytes)
so I have to ignore such a data. In practice this means that if I read for
example 100 samples, I have to ignore about 20 of them. I know that other
loops take their pro
cessor time and this disturbs the serial port loop but
must have those other things to be done in the program. So, I�d like to have
some advice how to read the serial port as fast as 9600 bauds/s and do some
other things at the same time without affecting to the quality of the received
data? What kind of code structure could be preferable for this kind of situation
or is there any special methods I should be using?

Thank you for your help in advance.

Jani
0 Kudos
Message 1 of 3
(2,689 Views)
Jani H wrote:
>
> Hello,
>
> My problem is related to RS232 serial communication. The device sends numerical
> data continuously to the serial port at a rate 9600 baud/s. At the same time
> my program must read RF-signal from the PCI board and do some calculations.
> In the code diagram this means that I have several while-loops running in
> parallel, one for serial read, one for RF-read and so on (loops do not run
> at the same rate). The problem is that the data received from the serial
> port is not valid on every loop cycle (instead of four bytes I get six bytes)
> so I have to ignore such a data. In practice this means that if I read for
> example 100 samples, I have to ignore about 20 of them. I know that other
> loops take their processor time and this
disturbs the serial port loop but
> must have those other things to be done in the program. So, I�d like to have
> some advice how to read the serial port as fast as 9600 bauds/s and do some
> other things at the same time without affecting to the quality of the received
> data? What kind of code structure could be preferable for this kind of situation
> or is there any special methods I should be using?
>
> Thank you for your help in advance.
>
> Jani

Jani,

Your solution is vi-server. Two independent vi's gathering data from COM
and PCI. The third vi will make calculations and gathering data from
both vi's. Take a look at the LV examples.
You can use vi reference to gather data from acquisition vi's, or
DataSocket server.

Good luck,
--
Sergey Krasnishov
____________________________________
Automated Control Systems
National Instruments Alliance Member
Moscow, Russia
sergey_acs@levsha.ru
http://acs.levsha.ru
0 Kudos
Message 2 of 3
(2,689 Views)
I had some success with a project where I was trying to read six serial links
that were running asynchronously. To keep the program from waiting too long
for any one link, missing data, or not reading a serial buffer often enough,
I used the LabVIEW occurrences. Essentially the program had two while loops
that ran at the same time. A 'generate occurrence' object was wired into
both. In the first while loop, the serial link was polled for the number
of bytes available, and if it was the right number a 'set occurence' object
referenced to the 'generate occurrence' object was executed. The first loop
needs a short time dealy, too, so that it doesn't try to run as fast as possible.
In the second while loop, a 'wait on occurrence' object that was referenced
to the same 'generate occurrence' object outside its loop was wired to the
FALSE case of a case statement object. Inside the FALSE case, you put the
code you want to execute when the right number of bytes are available at
the port, like reading them and doing something with them. When the occurence
does not 'occur' in the second while loop, the processor is free to do other
things outside the case statement object. I found this reduced the load
on the processor dramatically. This might take some trial and error to get
going right, but LabVIEW has some occurrence examples.

"Jani H" wrote:
>>Hello,>>My problem is related to RS232 serial communication. The device
sends numerical>data continuously to the serial port at a rate 9600 baud/s.
At the same time>my program must read RF-signal from the PCI board and do
some calculations.>In the code diagram this means that I have several while-loops
running in>parallel, one for serial read, one for RF-read and so on (loops
do not run>at the same rate). The problem is that the data received from
the serial>port is not valid on every loop cycle (instead of four bytes I
get six bytes)>so I have to ignore such a data. In practice this means that
if I read for>example 100 samples, I have to ignore about 20 of them. I know
that other>loops take their processor time and this disturbs the serial port
loop but>must have those other things to be done in the program. So, I�d
like to have>some advice how to read the serial port as fast as 9600 bauds/s
and do some>other things at the same time without affecting to the quality
of the received>data? What kind of code structure could be preferable for
this kind of situation>or is there any special methods I should be using?>>Thank
you for your help in advance.>>Jani>
0 Kudos
Message 3 of 3
(2,689 Views)