LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading from two serial ports simaltaneously with different baud rates

Hi,

Here is a simplified version of the VI. Its giving me the same error , the instrument with Baud rate 9600 does not respond along with the other instrument. But they both work individually when one of them is made false.
0 Kudos
Message 11 of 18
(1,665 Views)
Look at the functions palette >> Instrument I/O >> Serial >> VISA Bytes at Port.

Search on the forum and look at the Examples for "State Machine." In its simplest implementation a state machine consists of a whle loop containing a case structure. The Case selector represents the next state and can be an enum or a string. A common variation uses queues to pass the next state. This would allow you to eliminate all the sequence structures while having a more easily maintained and modified architecture. Often there are states for initialization, acquisition, data manipulation, and termination (VISA Close), as well as states for error handling.

Lynn
0 Kudos
Message 12 of 18
(1,662 Views)
Instead of having both serial port code in one loop, separate the code into two loops. In other words, put the code for each serial port in separate loops. The two loops should not have any wires going from one loop to the other. This way, the loops will operate independently of each other. The timing of one will not affect the timing of the other. Put wait timers in each loop (100 milliseconds or so) to ensure that each loop will get a slice of CPU time.
- tbob

Inventor of the WORM Global
Message 13 of 18
(1,654 Views)
tbob beat me to it. I have modified your example to show two loops.

Lynn
Message 14 of 18
(1,646 Views)
🙂

You guys are great. Thanks that worked, i was just wondering how Labview during runtime does not get stuck in a single while loop ? When it enters into a while loop how does it execute another while loop in parallel and if it does, does it means that the iteration number on the while loops will be completely different ?

Thanks
Gagan
Message 15 of 18
(1,644 Views)
Good question!

LabVIEW's internal scheduler lets parallel nodes execute when all of their data inputs are available. This is called dataflow. Any loop which has a delay function inside will "play nicely" with other loops. That is why I put a Wait (ms) function inside each loop. I set the delays to slightly less than the time it will take a serial port to receive the 16 bytes your program was looking for.

Try a simple program with two or more loops. Put indicators on the iteration terminals and controls on the Wait functions. Try different values and see what happens. Even 0 ms will allow the loops to share CPU access. A loop with no waits, however, can tie up the CPU.

Lynn
Message 16 of 18
(1,644 Views)
So let me see if i get this correct, when i put both the serial requests in a single while loop, since the one with baud rate 9600 recieved its byte faster than 2400 baud rate instrument it basically had to wait in the while loop till the complete transfer for the lower baud rate instrument was over. Due to which its subsequent byte arrived which cause an overlap of data in its read buffer ? So the iteration of the while loop ended when the complete byte from the lower baud rate instrument was read resulting in a false read from the higher baud rate meter, and putting them seperate you are basically multiplexing between the two instruments rather that parallising them ?

Gagan
Message 17 of 18
(1,640 Views)
In the same manner that Lynn described, an iteration of a loop will be complete when everything inside it has been completed, so if you have 2 serial reads, the 9600 one finishes first (assuming the bytes for the 2400 one aren't already in the serial buffer) and waits until the rest of the code in the current iteration finishes before running again. If the data is really coming in at those rates, the waiting should be enough to cause an overflow.
I'm not sure how LV would handle a buffer overflow and where in the buffer subsequent iteration would start reading from.

___________________
Try to take over the world!
Message 18 of 18
(1,627 Views)