LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

RS232 communication using VISA serial

Hi guys! I would like your opinion as to which method of RS232 communication is better from the two examples I have attached. The block diagram shows what I am trying to do.

 

Thanks!

I may not be perfect, but I'm all I got!
0 Kudos
Message 1 of 9
(5,063 Views)

Also, on another note. Are global variables better than references? Or is this comparison like apples and oranges.

 

I understand the EVIL of globals, but in my case variables are written only at one place and read from one place.

I may not be perfect, but I'm all I got!
0 Kudos
Message 2 of 9
(5,060 Views)

Globals are not EVIL. Much like duct tape they can be very useful at times. Variables don't cause race conditions - programmers cause race conditions.

 

If you have a single writer and a single reader you should be fine. You just have to worry about missing or stale data if that is a concern.

 

But I find that I never need to use global variables or local variables at all.

=====================
LabVIEW 2012


Message 3 of 9
(5,052 Views)

As Steve said, global variables can cause race conditions if not used properly.  If used properly, there is no reason why one setup is better than the other (at least nothing noticeable from what you sent).  Generally speaking, however, we try to warn customers of the possible errors that can occur when using them.

 

Thanks,

 

Sean

Applications Engineering Specialist - Semiconductor Test
National Instruments
0 Kudos
Message 4 of 9
(5,016 Views)

While there can be times when a global variable is useful I would recommend against using them. They can cause problems when used and are a lazy way of designing an application. By using other preferred methods (queues, notifiers, action engines) you have more control over their use and can provide more protections. In addition, these methods help to decouple the code. Global variables couple modules together and make reuse much more difficult.

 

I like to take that approach that anything I write will live for longer than I expect and there are good chances I will need to come back to it in the future to modify it or add functionality. By always using best practices my job is easier because I have less rework when I do touch the code again. Plan for maintainability, modularity and reuse and you will never go wrong.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 9
(5,009 Views)

any comments on the two programs itself?? Which way is better in terms of reading from serial port and writing back on same port.

I may not be perfect, but I'm all I got!
0 Kudos
Message 6 of 9
(4,970 Views)

VeeJay-

 

Again, I would recommend staying away from global variables when possible.

 

Thanks,

 

Sean

Applications Engineering Specialist - Semiconductor Test
National Instruments
0 Kudos
Message 7 of 9
(4,948 Views)

Thanks Sean! I got the part about using Global variables.

 

My question was with regards to reading from COM port and writing back. Is the queue method efficient or does the constant polling for commands better?

 

what about using references? Please refer vi. Thanks!

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 8 of 9
(4,932 Views)

VeeJay-

 

I couldn't really say which one is better or more efficient.  In the constant polling method, it would seem that if there is no data, than the process is wasted, or doing nothing, where as in the queue (producer/consumer) method, the consumer loop is inactive until there is data in the queue.  However, the producer loop is still constantly polling.  Overall, the producer/consumer loops seem overly complex to accomplish the same thing.

 

Thanks,

 

Sean

Applications Engineering Specialist - Semiconductor Test
National Instruments
0 Kudos
Message 9 of 9
(4,918 Views)